0
Not all functions return values. If you take a function which is of type void, you get a function which is does not return anything. The only functions which should return values are those which are used as a right side of expressions (so called rvalues).
1 answer
The newest striking issues with regards C++ can always be found be looking at the latest standard and those to come. The current standard is C++11, while the next two are currently known as C++14 and C++17. By examining the changes from the previous version to the next version one can determine what is new. The predecessor to C++11 was C++03. The naming convention follows the tradition of using the year of publication. Thus C++03 was published in 2003.
One of the main changes between C++03 and C++11 was the introduction of the move constructor. This is useful when assigning a temporary object (an rvalue) to another object (an lvalue). Typically, resources are deep copied from the rvalue to the lvalue, which is expensive in terms of memory consumption and performance. However, since the rvalue is temporary, there is no need to copy the resources -- they can simply be moved.
For instance, a std::vector<T> object is really nothing more than a wrapper for a C-style dynamic array with size. The size member is a simple primitive (an unsigned integer) that can easily be copied directly without any cost. However, the internal array is more complex in that it is a void pointer to memory that was dynamically allocated. With copy construction, the entire array must be copied to new memory which is then assigned to the lvalue's internal pointer. But with move construction, the lvalue's pointer simply copies the value of the rvalue's pointer before setting the rvalue's pointer to NULL. In other words, the lvalue takes ownership of the existing memory. When the rvalue falls from scope (which it must do since it is temporary), the memory is safe because its internal pointer is NULL.
To achieve this, C++11 introduced an rvalue reference. In C++03, rvalues were typically considered const T& types. But an rvalue reference is a non-const T& type, identified by T&&. This semantic permits class designers to include both a copy and move constructor, as well as copy and move assignment operator overloads.
Other major changes included the introduction of the constexpr keyword, which allowed functions and object constructors to be used within constant expressions. There were also changes to the plain old data semantic (POD) such that a class, struct or union can only be considered a POD if it is trivial, standard-layout, and all its non-static data members and base classes are PODs. By separating the trivial and standard-layout concepts, it is now possible to lose one without compromising the other, and thus be able to produce more complex PODs that are still memcpy-able and therefore compatible with C.
1 answer