| 1 |
// { dg-do compile { target c++11 } } |
| 2 |
|
| 3 |
template<typename T, typename U> |
| 4 |
struct is_same |
| 5 |
{ |
| 6 |
static const bool value = false; |
| 7 |
}; |
| 8 |
|
| 9 |
template<typename T> |
| 10 |
struct is_same<T, T> |
| 11 |
{ |
| 12 |
static const bool value = true; |
| 13 |
}; |
| 14 |
|
| 15 |
#define CHECK_DECLTYPE(DECLTYPE,RESULT) \ |
| 16 |
static_assert(is_same< DECLTYPE , RESULT >::value, #RESULT) |
| 17 |
|
| 18 |
template<typename F> F create_a(); |
| 19 |
|
| 20 |
template<typename F, typename T1> |
| 21 |
decltype(create_a<F&>()(create_a<const T1&>())) forward(F f, const T1& a1) |
| 22 |
{ |
| 23 |
return f(a1); |
| 24 |
} |
| 25 |
|
| 26 |
struct identity { |
| 27 |
template<typename T> |
| 28 |
const T& operator()(const T& x) { return x; } |
| 29 |
}; |
| 30 |
|
| 31 |
|
| 32 |
identity id; |
| 33 |
int i; |
| 34 |
float f; |
| 35 |
|
| 36 |
CHECK_DECLTYPE(decltype(forward(id, i)), const int&); |
| 37 |
CHECK_DECLTYPE(decltype(forward(id, f)), const float&); |