It seems I do not think and cannot find an excuse for the following code:
std::vector<int> a{1,2}
std::vector<int> a(1,2)
vector( std::initializer_list<T> init,
const Allocator& alloc = Allocator() );
explicit vector( size_type count,
const T& value = T(),
const Allocator& alloc = Allocator());
The various functions are named based on which building method you use ( {}vs ()), and that seems extremely perverse to me. Why do std::initializer_listthey prefer other functions that otherwise would ideally fit these parameters? I know that the constructor 2above was deprecated in C ++ 11, presumably due to this change, but I still cannot explain why this is so. . The only advantage I see in this behavior is that you can initialize a container with specific values and require only one pair of curly braces; std::vector<int> a{1,2}vsstd::vector<int> a{{1,2}}. But, at least, at least, of course, this does not eliminate the ambiguity and changes in the overload resolution that it imposed. According to Scott Meyers in Effective Modern C ++, std::make_uniqueand std::make_sharedit is necessary to explicitly indicate which form is used to build as part of their interface (due to overload resolution). It seems funny to me.
I admit that I'm missing something, but I'm just not sure what it is. Please note that I just used std::vectoras an example, and I ask about this function in general.
source
share