namespace std {
typedef decltype(sizeof(int)) size_t;
template <class _E>
class initializer_list
{
const _E* __begin_;
size_t __size_;
initializer_list(const _E* __b, size_t __s)
: __begin_(__b),
__size_(__s)
{}
public:
typedef _E value_type;
typedef const _E& reference;
typedef const _E& const_reference;
typedef size_t size_type;
typedef const _E* iterator;
typedef const _E* const_iterator;
initializer_list() : __begin_(nullptr), __size_(0) {}
size_t size() const {return __size_;}
const _E* begin() const {return __begin_;}
const _E* end() const {return __begin_ + __size_;}
};
}
template < bool condition, typename T = void >
struct enable_if { typedef T type; };
template< typename T >
struct enable_if< false, T > {};
namespace Casts {
template< unsigned O >
void implicit(typename enable_if< O <= 4 >::type* = 0) {
}
template< unsigned O >
void cstyle(typename enable_if< O <= (unsigned)4 >::type* = 0) {
}
template< unsigned O >
void functional(typename enable_if< O <= unsigned(4) >::type* = 0) {
}
template< unsigned O >
void static_(typename enable_if< O <= static_cast<unsigned>(4) >::type* = 0) {
}
template <unsigned O, typename T>
void reinterpret_(typename enable_if<O <= sizeof(reinterpret_cast<T *>(0))>::type * = 0) {
}
template <typename T, T *p>
void const_(typename enable_if<0 <= sizeof(const_cast<T *>(p))>::type * = 0) {
}
template <typename T, T *p>
void dynamic_(typename enable_if<0 <= sizeof(dynamic_cast<T *>(p))>::type * = 0) {
}
template< typename T >
void auto_(decltype(new auto(T()))) {
}
template< typename T >
void scalar_(decltype(T(), int())) {
}
template <unsigned N> struct T {};
template <int N> T<N> f() { return T<N>(); }
extern int i;
extern struct S {} s;
template void implicit<4>(void*);
template void cstyle<4>(void*);
template void functional<4>(void*);
template void static_<4>(void*);
template void reinterpret_<4, int>(void*);
template void const_<int, &i>(void*);
template void dynamic_<struct S, &s>(void*);
template T<6> f<6>();
template void auto_<int>(int*);
template void scalar_<int>(int);
}
namespace test1 {
short foo(short);
int foo(int);
template <class T> auto a(T t) -> decltype(foo(T())) { return foo(t); }
template <class T> auto b(T t) -> decltype((foo)(T())) { return (foo)(t); }
void test(short s) {
a(s);
b(s);
}
}
namespace test2 {
template <class T> void a(T x, decltype(x()) y) {}
template <class T> auto b(T x) -> decltype(x()) { return x(); }
template <class T> void c(T x, void (*p)(decltype(x()))) {}
template <class T> void d(T x, auto (*p)() -> decltype(x())) {}
template <class T> void e(auto (*p)(T y) -> decltype(y())) {}
template <class T> void f(void (*p)(T x, decltype(x()) y)) {}
template <class T> void g(T x, decltype(x()) y) {
static decltype(x()) variable;
variable = 0;
}
template <class T> void h(T x, decltype((decltype(x())(*)()) 0) y) {}
template <class T> void i(decltype((auto (*)(T x) -> decltype(x())) 0) y) {}
float foo();
void bar(float);
float baz(float(*)());
void fred(float(*)(), float);
void instantiate() {
a(foo, 0.0f);
(void) b(foo);
c(foo, bar);
d(foo, foo);
e(baz);
f(fred);
g(foo, 0.0f);
h(foo, foo);
i<float(*)()>(baz);
}
}
namespace test3 {
template <class T, class U> void a(T x, U y, decltype(x.*y) z) {}
struct X {
int *member;
};
void instantiate() {
X x;
int *ip;
a(x, &X::member, ip);
}
}
namespace test4 {
struct X {
X(int);
};
template <typename T>
void tf1(decltype(new T(1)) p)
{}
template <typename T>
void tf2(decltype(new T({1})) p)
{}
template <typename T>
void tf3(decltype(new T{1}) p)
{}
template void tf1<X>(X*);
template void tf2<X>(X*);
template void tf3<X>(X*);
}
namespace test5 {
template <typename T> void a(decltype(noexcept(T()))) {}
template void a<int>(decltype(noexcept(int())));
}
namespace test6 {
struct X {
int i;
};
struct Y {
union {
int i;
};
};
struct Z {
union {
X ua;
Y ub;
};
struct {
X s;
};
union {
union {
struct {
struct {
X uuss;
};
};
};
};
};
Z z, *zp;
template<typename T>
void f1(decltype(T(z.ua.i))) {}
template void f1<int>(int);
template<typename T>
void f2(decltype(T(z.ub.i))) {}
template void f2<int>(int);
template<typename T>
void f3(decltype(T(z.s.i))) {}
template void f3<int>(int);
template<typename T>
void f4(decltype(T(z.uuss.i))) {}
template void f4<int>(int);
template<typename T>
void f5(decltype(T(zp->ua.i))) {}
template void f5<int>(int);
template<typename T>
void f6(decltype(T(zp->ub.i))) {}
template void f6<int>(int);
template<typename T>
void f7(decltype(T(zp->s.i))) {}
template void f7<int>(int);
template<typename T>
void f8(decltype(T(zp->uuss.i))) {}
template void f8<int>(int);
}
namespace test7 {
struct A { int x[3]; };
struct B { B(int, int); } extern b;
struct C { C(B); };
struct D { D(C); };
struct E { E(std::initializer_list<int>); };
struct F { F(E); };
template<class T> decltype(A{1,2},T()) fA1(T t) {}
template<class T> decltype(A({1,2}),T()) fA2(T t) {}
template<class T> decltype(B{1,2},T()) fB1(T t) {}
template<class T> decltype(B({1,2}),T()) fB2(T t) {}
template<class T> decltype(C{{1,2}},T()) fC1(T t) {}
template<class T> decltype(C({1,2}),T()) fC2(T t) {}
template<class T> decltype(D{b},T()) fD1(T t) {}
template<class T> decltype(D(b),T()) fD2(T t) {}
template<class T> decltype(E{1,2},T()) fE1(T t) {}
template<class T> decltype(E({1,2}),T()) fE2(T t) {}
template<class T> decltype(F{{1,2}},T()) fF1(T t) {}
template<class T> decltype(F({1,2}),T()) fF2(T t) {}
template<class T> decltype(T{}) fT1(T t) {}
template<class T> decltype(T()) fT2(T t) {}
template<class T> decltype(T{1}) fT3(T t) {}
template<class T> decltype(T(1)) fT4(T t) {}
template<class T> decltype(T{1,2}) fT5(T t) {}
template<class T> decltype(T(1,2)) fT6(T t) {}
template<class T> decltype(T{{}}) fT7(T t) {}
template<class T> decltype(T({})) fT8(T t) {}
template<class T> decltype(T{{1}}) fT9(T t) {}
template<class T> decltype(T({1})) fTA(T t) {}
template<class T> decltype(T{{1,2}}) fTB(T t) {}
template<class T> decltype(T({1,2})) fTC(T t) {}
int main() {
fA1(1); fA2(1); fB1(1); fB2(1); fC1(1); fC2(1); fD1(1); fD2(1); fE1(1); fE2(1); fF1(1); fF2(1); fT1(1); fT2(1); fT3(1); fT4(1); fT5(b); fT6(b); fT7(A{}); fT8(A{}); fT9(A{}); fTA(A{}); fTB<C>(b); fTC<C>(b); }
}
namespace test8 {
template <class>
struct X {
template<typename T> T foo() const { return 0; }
template <class T> auto bar() const -> decltype(foo<T>()) { return 0; }
};
template int X<int>::bar<int>() const;
}
namespace designated_init {
struct A { struct B { int b[5][5]; } a; };
template<typename T> void f(decltype(T{.a.b[3][1 ... 4] = 9}) x) {}
void use_f(A a) { f<A>(a); }
}
namespace null {
template <decltype(nullptr) P>
void cpp_nullptr(typename enable_if<P == nullptr>::type* = 0) {
}
template <void *P>
void gnu_null(typename enable_if<P == __null>::type* = 0) {
}
template void cpp_nullptr<nullptr>(void *);
template void gnu_null<nullptr>(void *);
}