Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Isn't `void f(A<0>, tuple<T *...>)` more specialized than `void f(A<I>, tuple<T *...>)`?

#include <tuple>

template<int I>
struct A {};

template<int I, typename... T>
void f(A<I>, std::tuple<T *...>) {}

template<typename... T>
void f(A<0>, std::tuple<T *...>) {}

int main()
{
    f(A<0>{}, std::tuple<char*, int*, float*>{});
}

Isn't the second overload of f more specialized? g++ 4.9.2 says that the call is ambiguous, clang 3.6.0 accepts it. Which compiler is right?

It's interesting that if you change std::tuple<T *...> to std::tuple<T...>, g++ is fine with it, which I don't understand.

like image 685
cubuspl42 Avatar asked Aug 15 '15 13:08

cubuspl42


People also ask

What is a tuple Mcq?

Explanation: Tuples can be used for keys into dictionary. The tuples can have mixed length and the order of the items in the tuple is considered when comparing the equality of the keys.

Which of the following is a Python tuple Mcq?

The correct answer to the question “Which of the following is a Python Tuple” is option (B). (1, 2, 3). Because in Python, Tuple is represented in round brackets.

Which of the following is correct about tuples in Python?

Q 22 - Which of the following is correct about tuples in python? A - A tuple is another sequence data type that is similar to the list.

Which is incorrect way of creating tuple?

Incorrect! To create a tuple with a single item, there must be a comma after the first item.


1 Answers

By the current rules, the second overload is more specialized. Some specialization A<@> with a synthesized value @ cannot be matched against A<0>, but A<0> can be matched against A<I> (with I=0). This first pair's asymmetry is decisive. Whether you use T or T* as the pattern in the second parameter is irrelevant, as deduction succeeds both ways for that pair.

The bug still persists in trunk and was reported by @Barry as 67228.

like image 121
Columbo Avatar answered Oct 20 '22 20:10

Columbo