What is the programming language of the future?
beneficii wrote:
For this:
You'll want to change it to:
Code:
std::string str = "a string";
container.emplace_back( str );
container.emplace_back( str );
You'll want to change it to:
Code:
std::string str = "a string";
container.emplace_back( std::move(str) ) /* note the use of std::move, which tells the compiler to do move assignment/construction instead of copy assignment/construction; you can also use push_back here. str will be left in "an undefined but valid state" (most likely, it would be empty). emplace and emplace_back/front allow for construction of the object in place within the container without first constructing it at all outside of the container by accepting any number of arguments that work as long as they match up to one set of parameters of the object's constructor. The arguments are forwarded to the constructor using move semantics.*/
container.emplace_back( std::move(str) ) /* note the use of std::move, which tells the compiler to do move assignment/construction instead of copy assignment/construction; you can also use push_back here. str will be left in "an undefined but valid state" (most likely, it would be empty). emplace and emplace_back/front allow for construction of the object in place within the container without first constructing it at all outside of the container by accepting any number of arguments that work as long as they match up to one set of parameters of the object's constructor. The arguments are forwarded to the constructor using move semantics.*/
So emplace_back() is only intended to work for inplace construction, not passing existing objects? And std::move() means it will call the move ctr.
I think I tested this out, but it didn't call the move ctr. I might remember it wrongly though...
Also, can I ask about your background? From reading your post about the container you made, you seem to be knowing a whole lot about C++. I assume you work with C++? STL implementer?
morslilleole wrote:
beneficii wrote:
For this:
You'll want to change it to:
Code:
std::string str = "a string";
container.emplace_back( str );
container.emplace_back( str );
You'll want to change it to:
Code:
std::string str = "a string";
container.emplace_back( std::move(str) ) /* note the use of std::move, which tells the compiler to do move assignment/construction instead of copy assignment/construction; you can also use push_back here. str will be left in "an undefined but valid state" (most likely, it would be empty). emplace and emplace_back/front allow for construction of the object in place within the container without first constructing it at all outside of the container by accepting any number of arguments that work as long as they match up to one set of parameters of the object's constructor. The arguments are forwarded to the constructor using move semantics.*/
container.emplace_back( std::move(str) ) /* note the use of std::move, which tells the compiler to do move assignment/construction instead of copy assignment/construction; you can also use push_back here. str will be left in "an undefined but valid state" (most likely, it would be empty). emplace and emplace_back/front allow for construction of the object in place within the container without first constructing it at all outside of the container by accepting any number of arguments that work as long as they match up to one set of parameters of the object's constructor. The arguments are forwarded to the constructor using move semantics.*/
So emplace_back() is only intended to work for inplace construction, not passing existing objects? And std::move() means it will call the move ctr.
I think I tested this out, but it didn't call the move ctr. I might remember it wrongly though...
Also, can I ask about your background? From reading your post about the container you made, you seem to be knowing a whole lot about C++. I assume you work with C++? STL implementer?
I am an "advanced" amateur in C++. (My dad says he talked to a coworker about my range_map project and the co-worker said that my ability to tackle that kind of project was the sign of an "advanced" programmer.)
Anyway, std::string should have a move constructor in C++11.
_________________
"You have a responsibility to consider all sides of a problem and a responsibility to make a judgment and a responsibility to care for all involved." --Ian Danskin
mrrhq wrote:
Lambda calculus, what is that?
Later in the same post, you refer to "good-old simple lisp", but lisp is really quite similar to the lambda calculus. They're really nearly the same thing, if you don't count some of the imperative features of lisp that aren't part of (and wouldn't make sense in) the mathematical theory of lambda calculus.
Quote:
In that case, I guess Haskell might be the, er, "language of the future" but I seriously doubt it. Maybe someone can please, please tell me why, even from a marketing standpoint.
I think Haskell is the language of the future in the same way Smalltalk was the language of the future in the 80's. Smalltalk had a huge influence on OOP, but never became popular itself.
Languages are already importing some of the nice features Haskell has (like C++ with lambdas). F# is Microsoft's .Net version of OCaml, which is in many ways closely related to Haskell. Lisp dialects already had a bunch of these features, but not necessarily the focus on immutability/referential transparency. Clojure is a new lisp dialect that's become somewhat popular, and it does have the focus on immutability. Scala is a somewhat popular new language that also takes a lot from functional programming.
Quote:
Like really, do NOT bother with Haskell unless you know what you are doing.
Haskell is not anywhere near as hard as it's made out to be. The problem people have with it is that it's so different from what they're used to, they have to learn a lot more new stuff. The stuff they learn isn't harder than what they're used to, they just aren't used to it (yet).
_________________
"A dead thing can go with the stream, but only a living thing can go against it." --G. K. Chesterton
Project COSA
Everything in this article is highly speculative at his point. However, it will give you an idea of where the computer world MIGHT be headed at some point in the future.
Similar Topics | |
---|---|
Grace Hopper - Pioneer of Computer Programming |
24 Oct 2024, 10:47 pm |
Facing my past to have a future |
26 Sep 2024, 1:32 pm |