Direct and standard initialization in std :: allocator

This question was also submitted to Usenet, where it is more relevant, but it is a larger and more reliable forum.

std::allocator::construct is defined to redirect the parameter of the argument package to the construction of the object using parentheses, direct initialization aka

If he used curly braces, uniform aka initialization, we could initialize aggregate data types from functions such as std::make_shared and container::emplace . In addition, it would be acceptable to put the contents of the initializer list into the argument list of such a function, solving the problem of outputting the initializer_list type in accordance with the forwarding.

Has this alternative been considered and rejected? Too late to switch in a future standard? This seems to be a change, but not particularly disgusting.

+7
c ++ c ++ 11 uniform-initialization
Oct 19 '11 at 10:50
source share
1 answer

I do not know what SC was considering, but keep in mind that uniform initialization does not really work in general contexts (prohibition of cost construction *). Consider this attempt:

 template<typename T, typename... Args> T make(Args&&... args) { return T { std::forward<Args>(args)... }; } 

You get:

 assert( make<std::vector<int>>(10, 0).size() == 2 ); assert( std::vector<int>(10, 0).size() == 10 ); 

and this will not compile:

 make<std::vector<int*>>(10u, 0); 

then how it does:

 std::vector<int*>(10u, 0); 

If the specific interaction between the ideal forwarder and initializer lists that causes this was formed soon enough, I could see that SC did not want to restart from scratch.

(*): T {} excellent even in general contexts.

+9
Oct 19 '11 at 11:02
source share



All Articles