| 1 |
// P2280R4 - Using unknown pointers and references in constant expressions |
| 2 |
// PR c++/106650 |
| 3 |
// { dg-do compile { target c++17 } } |
| 4 |
|
| 5 |
#include <type_traits> |
| 6 |
|
| 7 |
template <typename T, typename U> |
| 8 |
constexpr bool is_type(U &&) |
| 9 |
{ |
| 10 |
return std::is_same_v<T, std::decay_t<U>>; |
| 11 |
} |
| 12 |
|
| 13 |
auto visitor = [](auto&& v) { |
| 14 |
if constexpr(is_type<int>(v)) { |
| 15 |
// ... |
| 16 |
} else if constexpr(is_type<char>(v)) { |
| 17 |
// ... |
| 18 |
} |
| 19 |
}; |
| 20 |
|
| 21 |
void |
| 22 |
g (int i) |
| 23 |
{ |
| 24 |
visitor (i); |
| 25 |
constexpr bool b = is_type<int>(i); |
| 26 |
} |