Why does ‘std::vector b{2};’ create a 1-element vector, and not a 2-element one?

Yes, this behaviour is intended, according to §13.3.1.7 Initialization by list-initialization

When objects of non-aggregate class type T are list-initialized
(8.5.4), overload resolution selects the constructor in two phases:

— Initially, the candidate functions are the initializer-list
constructors (8.5.4) of the class T and the argument list consists of
the initializer list as a single argument.

— If no viable
initializer-list constructor is found, overload resolution is
performed again, where the candidate functions are all the
constructors of the class T and the argument list consists of the
elements of the initializer list.

As to “the whole purpose of uniform intialization”… “Uniform initialization” is a marketing term, and not a very good description. The standard has all the usual forms of initialization plus list-initialization, but no “uniform initialization”. List initialization is not meant to be the ultimate form of initialization, it’s just another tool in the utility belt.

Leave a Comment