Date
2013-09-21.00:00:00
Message id
6692

Content

Consider the following code:

void meow(tuple<long, long>) { puts("Two"); }

void meow(tuple<long, long, long>) { puts("Three"); }

tuple<int, int, int> t(0, 0, 0);

meow(t);

This should compile and print "Three" because tuple<long, long>'s constructor from const tuple<int, int, int>& should remove itself from overload resolution. Implementations sensibly do this, but the Standard doesn't actually say it!

In this case, Types is "long, long" and UTypes is "int, int, int". [tuple.cnstr]/3 says "let i be in the range [0,sizeof...(Types)) in order", which is [0, 2). Then /17 says "Remark: This constructor shall not participate in overload resolution unless const Ui& is implicitly convertible to Ti for all i." Interpreted literally, this is true! /15 says "Requires: sizeof...(Types) == sizeof...(UTypes)." but requiring the sizes to be identical doesn't help. Only the special phrase "shall not participate in overload resolution unless" mandates SFINAE/enable_if machinery.

The wording that we need is almost available in the Requires paragraphs, except that the Requires paragraphs say "is_constructible" while the Remark paragraphs say "is implicitly convertible", which is the correct thing for the SFINAE constraints to check. My proposed resolution is to unify the Requires and Remark paragraphs, after which there will be no need for Requires (when a constructor participates in overload resolution if and only if X is true, then there's no need for it to Require that X is true).

Note: [meta.unary.prop]/6 specifies is_constructible<To, From> and [meta.rel]/4 specifies is_convertible<From, To>. Both are specified in terms of "template <class T> typename add_rvalue_reference<T>::type create();". Therefore, passing From and From&& is equivalent, regardless of whether From is an object type, an lvalue reference, or an rvalue reference.

Also note that [tuple.cnstr]/3 defines T0 and T1 so we don't need to repeat their definitions.