| 1 |
// PR c++/56782 |
| 2 |
// { dg-do compile { target c++11 } } |
| 3 |
|
| 4 |
template<class T> |
| 5 |
T&& declval(); |
| 6 |
|
| 7 |
struct is_convertible_impl { |
| 8 |
template<class T> |
| 9 |
static void sink(T); |
| 10 |
|
| 11 |
template<class T, class U, class = decltype(sink<U>(declval<T>()))> |
| 12 |
static auto test(int) -> char; |
| 13 |
|
| 14 |
template<class, class> |
| 15 |
static auto test(...) -> char(&)[2]; |
| 16 |
}; |
| 17 |
|
| 18 |
template<class T, class U> |
| 19 |
struct is_convertible : is_convertible_impl |
| 20 |
{ |
| 21 |
static const bool value = sizeof(test<T, U>(0)) == 1; |
| 22 |
}; |
| 23 |
|
| 24 |
template<bool, class> |
| 25 |
struct enable_if {}; |
| 26 |
|
| 27 |
template<class T> |
| 28 |
struct enable_if<true, T> { typedef T type; }; |
| 29 |
|
| 30 |
template<bool, class If, class Else> |
| 31 |
struct conditional { typedef If type; }; |
| 32 |
|
| 33 |
template<class If, class Else> |
| 34 |
struct conditional<false, If, Else> { typedef Else type; }; |
| 35 |
|
| 36 |
template<class...> |
| 37 |
struct and_; |
| 38 |
|
| 39 |
template<> |
| 40 |
struct and_<> |
| 41 |
{ |
| 42 |
static const bool value = true; |
| 43 |
}; |
| 44 |
|
| 45 |
template<class P> |
| 46 |
struct and_<P> : P |
| 47 |
{ |
| 48 |
}; |
| 49 |
|
| 50 |
template<class P1, class P2> |
| 51 |
struct and_<P1, P2> : conditional<P1::value, P2, P1>::type |
| 52 |
{ |
| 53 |
}; |
| 54 |
|
| 55 |
template<class... T> |
| 56 |
struct Tuple { |
| 57 |
template<class... U, |
| 58 |
class = typename enable_if<and_<is_convertible<U, T>... >::value, int>::type |
| 59 |
> |
| 60 |
Tuple(U&&...){} |
| 61 |
}; |
| 62 |
|
| 63 |
static_assert(is_convertible<Tuple<>, Tuple<>>::value, "Ouch"); //#1 |