c++11,move,temporary-objects,list-initialization
In general, braced-init-lists like {} are not expressions and do not have a type. If you have a function template template<typename T> void f(T); and call f( {} ), no type will be deduced for T, and type deduction will fail. On the other hand, ABC{} is a prvalue expression...
c++,templates,c++11,list-initialization
That's because you're trying to perform aggregate initialization on Boo. See §8.5.4/3: List-initialization of an object or reference of type T is defined as follows: — If T is an aggregate, aggregate initialization is performed (8.5.1). You're intending to copy-construct your Boo... but really you're doing aggregate initialization, which leads...
c++,c++11,inheritance,initializer-list,list-initialization
Your original case relied upon aggregate initialization [dcl.init.list]: List-initialization of an object or reference of type T is defined as follows: ... — Otherwise, if T is an aggregate, aggregate initialization is performed Where an aggregate and aggregate initialiazation are, from [dcl.init.aggr], emphasis mine: An aggregate is an array or...
c++,c++11,gcc,c++14,list-initialization
In C++11 having in-class member initializers makes the struct/class not an aggregate — this was changed in C++14, however. This is something I found surprising when I first ran into it, the rationale for this restriction is that in-class initializers are pretty similar to a user defined constructor but the...
c++,c++14,value-initialization,list-initialization,aggregate-initialization
[dcl.init.aggr]: 7 - If there are fewer initializer-clauses in the list than there are members in the aggregate, then each member not explicitly initialized shall be initialized [C++14: from its brace-or-equal-initializer or, if there is no brace-or-equal-initializer,] from an empty initializer list (8.5.4). So g++ is being overzealous with its...
c++,c++11,overload-resolution,list-initialization
The behavior makes sense. Scott Meyers has an example almost exactly like this in Effective Modern C++ (emphasis in original): If, however, one or more constructors declare a parameter of type std::initializer_list, calls using the braced initialization syntax strongly prefer the overloads taking std;:initializer_lists. Strongly. If there's any way for...
c++,c++11,vector,initialization,list-initialization
Because the initializer_list overload is strongly preferred to all the other ones. From [over.match.list]: When objects of non-aggregate class type T are list-initialized (8.5.4), overload resolution selects the constructor in two phases: (1.1) — Initially, the candidate functions are the initializer-list constructors (8.5.4) of the class T and the argument...
c++,c++11,reference,c++14,list-initialization
It works on C++14 and also works on C++11. You're very likely using an out-of-date compiler. There's a fixed bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50025) for your exact issue (cfr. DR 1288) C++0x initialization syntax doesn't work for class members of reference type Quoting from Jonathan Wakely The original C++11 rules required a temporary...
c++,c++11,unique-ptr,initializer-list,list-initialization
This make_vector is a function that takes any number of arguments, and perfect-forwards them into a vector. // get the first type in a pack, if it exists: template<class...Ts> struct first {}; template<class T, class...Ts> struct first<T,Ts...>{ using type=T; }; template<class...Ts> using first_t=typename first<Ts...>::type; // build the return type: template<class...
c++,c++11,language-lawyer,overload-resolution,list-initialization
I believe that the problem in your analysis is the fact that the statement int t = 1.0; is indeed well-formed - an implicit conversion from double to int obviously exists. [over.ics.list]/4 also describes it: Otherwise, if the parameter type is std::initializer_list<X> and all the elements of the initializer list...
c++,polymorphism,list-initialization
You'll have to add a constructor for struct Shape and call it from your sub-class. Like so: struct Shape { public: const Rect boundingRect; // the rect in which the shape is contained Shape( Rect rect ) : boundingRecT( rect ) {} }; struct Stain : Shape { public: Stain(Rect...