2) Are there any technical reasons that you might think about to eliminate the possibility of “ideal forwarding constructors” as an adequate alternative?
I showed one problem with this perfect transition: Forwarding all the constructors in C ++ 0x .
In addition, the ideal redirection method cannot “force” the clarity of the constructors of the base class: either it is always the constructor of the transformation, or never, and the base class will always have direct initialization (always using all the constructors, even explicit ones).
Another problem is list-initializer-constructors, because you cannot output Args to initializer_list<U> . Instead, you will need to forward the database using B{args...} (note the curly braces) and initialize the D objects with (a, b, c) or {1, 2, 3} or = {1, 2, 3} . In this case, Args will be the type of the elements of the initializer list and redirects them to the base class. After that, the constructor-initializer can get them. This seems to cause unnecessary code bloat because the template argument package potentially contains many type sequences for each different combination of types and lengths, and since you need to choose the initialization syntax, this means:
struct MyList { // initializes by initializer list MyList(std::initializer_list<Data> list); // initializes with size copies of def MyList(std::size_t size, Data def = Data()); }; MyList m{3, 1}; // data: [3, 1] MyList m(3, 1); // data: [1, 1, 1] // either you use { args ... } and support initializer lists or // you use (args...) and won't struct MyDerivedList : MyList { template<class ... Args> MyDerivedList(Args&& ... args) : MyList{ args... } { } }; MyDerivedList m{3, 1}; // data: [3, 1] MyDerivedList m(3, 1); // data: [3, 1] (!!)
Johannes Schaub - litb Nov 08 '10 at 23:19 2010-11-08 23:19
source share