A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://timsong-cpp.github.io/cppwp/n4140/over.ics.list below:

[over.ics.list]

13.3.3.1.5 List-initialization sequence [over.ics.list]

When an argument is an initializer list ([dcl.init.list]), it is not an expression and special rules apply for converting it to a parameter type.

If the parameter type is std::initializer_list<X> and all the elements of the initializer list can be implicitly converted to X, the implicit conversion sequence is the worst conversion necessary to convert an element of the list to X, or if the initializer list has no elements, the identity conversion. This conversion can be a user-defined conversion even in the context of a call to an initializer-list constructor. [ Example:

void f(std::initializer_list<int>);
f( {} );                    f( {1,2,3} );               f( {'a','b'} );             f( {1.0} );                 
struct A {
  A(std::initializer_list<double>);             A(std::initializer_list<complex<double>>);    A(std::initializer_list<std::string>);      };
A a{ 1.0,2.0 };             
void g(A);
g({ "foo", "bar" });        
typedef int IA[3];
void h(const IA&);
h({ 1, 2, 3 });             

 — end example ]

Otherwise, if the parameter type is “array of N X135, if the initializer list has exactly N elements or if it has fewer than N elements and X is default-constructible, and if all the elements of the initializer list can be implicitly converted to X, the implicit conversion sequence is the worst conversion necessary to convert an element of the list to X.

Otherwise, if the parameter is a non-aggregate class X and overload resolution per [over.match.list] chooses a single best constructor of X to perform the initialization of an object of type X from the argument initializer list, the implicit conversion sequence is a user-defined conversion sequence with the second standard conversion sequence an identity conversion. If multiple constructors are viable but none is better than the others, the implicit conversion sequence is the ambiguous conversion sequence. User-defined conversions are allowed for conversion of the initializer list elements to the constructor parameter types except as noted in [over.best.ics]. [ Example:

struct A {
  A(std::initializer_list<int>);
};
void f(A);
f( {'a', 'b'} );            
struct B {
  B(int, double);
};
void g(B);
g( {'a', 'b'} );            g( {1.0, 1.0} );            
void f(B);
f( {'a', 'b'} );            
struct C {
  C(std::string);
};
void h(C);
h({"foo"});                 
struct D {
  D(A, C);
};
void i(D);
i({ {1,2}, {"bar"} });      

 — end example ]

Otherwise, if the parameter has an aggregate type which can be initialized from the initializer list according to the rules for aggregate initialization ([dcl.init.aggr]), the implicit conversion sequence is a user-defined conversion sequence with the second standard conversion sequence an identity conversion. [ Example:

struct A {
  int m1;
  double m2;
};

void f(A);
f( {'a', 'b'} );            f( {1.0} );                 

 — end example ]

Otherwise, if the parameter is a reference, see [over.ics.ref]. [ Note: The rules in this section will apply for initializing the underlying temporary for the reference.  — end note ] [ Example:

struct A {
  int m1;
  double m2;
};

void f(const A&);
f( {'a', 'b'} );            f( {1.0} );                 
void g(const double &);
g({1});                     

 — end example ]

Otherwise, if the parameter type is not a class:

In all cases other than those enumerated above, no conversion is possible.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4