How does a converting constructor with more than a single non-optional parameter look like and why does it make sense?

c++, c++11, constructor, language-lawyer, type-conversion

Solution

The language was modified as part of the addition of initializer lists. See n2672: init-list wording.

An example:

struct S {
    S(int x, double y) { }
};

void f(S) { }

int main() {
    f({ 42, 42.0 });
}

Problem

As far as I have used "converting constructors" they look like this: ``` struct X { X(A); // conversion from A -> X X(B,C = someC); // conversion from B -> X, with some default C }; X x1 = A(); // calls X::X(A()) X x2 = B(); // calls X::X(B(),someC) ``` This makes perfect sense, and as far as I know works as long as you don't have a constructor: ``` struct Y { Y(A,B); // no implicit conversion }; ``` However, this is where it gets interesting, the C++11 standard reads literally: 12.3.1 Conversion by constructor - A constructor declared without the function-specifier `explicit` that can be called with a single parameter specifies a conversion from the type of its first parameter types of its parameters to the type of its class. Such a constructor is called a converting constructor. (italics were originally underlined, but markdown doesn't accept `<u>`) This seems to suggest that it was changed that a converting constructor doesn't have to be callable "with a single parameter" and the change from "type of its first parameter" to "types of its parameters" (note the plural!) further supports this. While I would expect that "type of its first parameter" would be changed to "type of its single non-optional parameter" (1) or even "type of its parameter that received an explicit argument" (2) in order to allow these: ``` struct Z { Z(A = a, B, C = c); // (1) Z(D = d, E = e, F = f); // (2) }; Z = D(); // (2) Z = E(); // (2) ``` I don't see how the formulation with the plural form makes sense: Does it really indicate you can perform conversion with several arguments? What does this mean?

Original source