Why was the default argument removed with the new standard? Often I constructed a vector variable like this: std::vector<my_pod_struct> buf(100). I guess I would get an compiler error with a C++11 compiler.
explicit vector( size_type count,
const T& value = T(), /* until C++11 */
const Allocator& alloc = Allocator());
vector( size_type count,
const T& value, /* since C++11 */
const Allocator& alloc = Allocator());
Before, when you wrote
std::vector<T> buf(100);you would get oneTdefault constructed, and then that instance would be copied over to one hundred slots in the vector.Now, when you write
std::vector<T> buf(100);, it will use another constructor:explicit vector( size_type count );. This will default-construct one hundredTs. It’s a slight difference, but an important one.The new single-argument constructor doesn’t require the type
Tto be copyable. This is important because now types can be movable and not copyable.