template<typename T, typename U> constexpr bool is_same_v = false;
template<typename T> constexpr bool is_same_v<T, T> = true;
template<typename... T>
struct type_list;
namespace unconstrained {
decltype(auto) f1(auto x) { return x; }
static_assert(is_same_v<decltype(f1(1)), int>);
static_assert(is_same_v<decltype(f1('c')), char>);
decltype(auto) f2(auto &x) { return x; }
static_assert(is_same_v<decltype(f2(1)), int &>); static_assert(is_same_v<decltype(f2('c')), char &>);
decltype(auto) f3(const auto &x) { return x; }
static_assert(is_same_v<decltype(f3(1)), const int &>);
static_assert(is_same_v<decltype(f3('c')), const char &>);
decltype(auto) f4(auto (*x)(auto y)) { return x; }
decltype(auto) f5(void (*x)(decltype(auto) y)) { return x; }
int return_int(); void return_void(); int foo(int);
decltype(auto) f6(auto (*x)()) { return x; }
static_assert(is_same_v<decltype(f6(return_int)), int (*)()>);
static_assert(is_same_v<decltype(f6(return_void)), void (*)()>);
using f6c1 = decltype(f6(foo));
decltype(auto) f7(auto (*x)() -> int) { return x; }
static_assert(is_same_v<decltype(f7(return_int)), int (*)()>);
using f7c1 = decltype(f7(return_void)); using f7c2 = decltype(f7(foo)); static_assert(is_same_v<decltype(&f7), int (*(*)(int (*x)()))()>);
decltype(auto) f8(auto... x) { return (x + ...); }
static_assert(is_same_v<decltype(f8(1, 2, 3)), int>);
static_assert(is_same_v<decltype(f8('c', 'd')), int>);
static_assert(is_same_v<decltype(f8('c', 1)), int>);
decltype(auto) f9(auto &... x) { return (x, ...); }
using f9c1 = decltype(f9(return_int, 1));
decltype(auto) f11(decltype(auto) x) { return x; }
template<typename T>
auto f12(auto x, T y) -> type_list<T, decltype(x)>;
static_assert(is_same_v<decltype(f12(1, 'c')), type_list<char, int>>);
static_assert(is_same_v<decltype(f12<char>(1, 'c')), type_list<char, int>>);
template<typename T>
auto f13(T x, auto y) -> type_list<T, decltype(y)>;
static_assert(is_same_v<decltype(f13(1, 'c')), type_list<int, char>>);
static_assert(is_same_v<decltype(f13<char>(1, 'c')), type_list<char, char>>);
template<typename T>
auto f14(auto y) -> type_list<T, decltype(y)>;
static_assert(is_same_v<decltype(f14<int>('c')), type_list<int, char>>);
static_assert(is_same_v<decltype(f14<int, char>('c')), type_list<int, char>>);
template<typename T, typename U>
auto f15(auto y, U u) -> type_list<T, U, decltype(y)>;
static_assert(is_same_v<decltype(f15<int>('c', nullptr)), type_list<int, decltype(nullptr), char>>);
static_assert(is_same_v<decltype(f15<int, decltype(nullptr)>('c', nullptr)), type_list<int, decltype(nullptr), char>>);
auto f16(auto x, auto y) -> type_list<decltype(x), decltype(y)>;
static_assert(is_same_v<decltype(f16('c', 1)), type_list<char, int>>);
static_assert(is_same_v<decltype(f16<int>('c', 1)), type_list<int, int>>);
static_assert(is_same_v<decltype(f16<int, char>('c', 1)), type_list<int, char>>);
void f17(auto x, auto y) requires (sizeof(x) > 1);
static_assert(is_same_v<decltype(f17('c', 1)), void>);
static_assert(is_same_v<decltype(f17<int>('c', 1)), void>);
static_assert(is_same_v<decltype(f17<int, char>('c', 1)), void>);
void f18(auto... x) requires (sizeof...(x) == 2);
static_assert(is_same_v<decltype(f18('c')), void>);
static_assert(is_same_v<decltype(f18('c', 1)), void>);
static_assert(is_same_v<decltype(f18('c', 1, 2)), void>);
template<typename T>
struct S {
constexpr auto f1(auto x, T t) -> decltype(x + t);
template<typename U>
constexpr auto f2(U u, auto x, T t) -> decltype(x + u + t);
};
template<typename T>
constexpr auto S<T>::f1(auto x, T t) -> decltype(x + t) { return x + t; }
template<typename T>
template<typename U>
constexpr auto S<T>::f2(auto x, U u, T t) -> decltype(x + u + t) { return x + u + t; }
template<typename T>
template<typename U>
constexpr auto S<T>::f2(U u, auto x, T t) -> decltype(x + u + t) { return x + u + t; }
template<>
template<>
constexpr auto S<int>::f2<double>(double u, char x, int t) -> double { return 42; }
static_assert(S<char>{}.f1(1, 2) == 3);
static_assert(S<char>{}.f2(1, 2, '\x00') == 3);
static_assert(S<char>{}.f2<double>(1, 2, '\x00') == 3.);
static_assert(S<int>{}.f2<double>(1, '2', '\x00') == 42);
}
namespace constrained {
template<typename T>
concept C = is_same_v<T, int>;
template<typename T, typename U>
concept C2 = is_same_v<T, U>;
int i;
const int ci = 1;
char c;
const char cc = 'a';
int g(int);
char h(int);
void f1(C auto x);
static_assert(is_same_v<decltype(f1(1)), void>);
static_assert(is_same_v<decltype(f1('a')), void>);
void f2(C auto &x);
static_assert(is_same_v<decltype(f2(i)), void>);
static_assert(is_same_v<decltype(f2(ci)), void>);
static_assert(is_same_v<decltype(f2(c)), void>);
void f3(const C auto &x);
static_assert(is_same_v<decltype(f3(i)), void>);
static_assert(is_same_v<decltype(f3(ci)), void>);
static_assert(is_same_v<decltype(f3(c)), void>);
void f4(C auto (*x)(C auto y)); void f5(C auto (*x)(int y));
static_assert(is_same_v<decltype(f5(g)), void>);
static_assert(is_same_v<decltype(f5(h)), void>);
void f6(C auto (*x)() -> int); void f7(C auto... x);
static_assert(is_same_v<decltype(f7(1, 2)), void>);
static_assert(is_same_v<decltype(f7(1, 'a')), void>);
static_assert(is_same_v<decltype(f7('a', 2)), void>);
void f8(C auto &... x);
static_assert(is_same_v<decltype(f8(i, i)), void>);
static_assert(is_same_v<decltype(f8(i, c)), void>);
static_assert(is_same_v<decltype(f8(i, i, ci)), void>);
void f9(const C auto &... x);
static_assert(is_same_v<decltype(f9(i, i)), void>);
static_assert(is_same_v<decltype(f9(i, c)), void>);
static_assert(is_same_v<decltype(f9(i, i, ci)), void>);
void f10(C decltype(auto) x); auto f11 = [] (C auto x) { };
static_assert(is_same_v<decltype(f11(1)), void>);
static_assert(is_same_v<decltype(f11('a')), void>);
void f12(C2<char> auto x);
static_assert(is_same_v<decltype(f12(1)), void>);
static_assert(is_same_v<decltype(f12('a')), void>);
void f13(C2<char> auto &x);
static_assert(is_same_v<decltype(f13(i)), void>);
static_assert(is_same_v<decltype(f13(cc)), void>);
static_assert(is_same_v<decltype(f13(c)), void>);
void f14(const C2<char> auto &x);
static_assert(is_same_v<decltype(f14(i)), void>);
static_assert(is_same_v<decltype(f14(cc)), void>);
static_assert(is_same_v<decltype(f14(c)), void>);
void f15(C2<char> auto (*x)(C2<int> auto y)); void f16(C2<char> auto (*x)(int y));
static_assert(is_same_v<decltype(f16(g)), void>);
static_assert(is_same_v<decltype(f16(h)), void>);
void f17(C2<char> auto (*x)() -> int); void f18(C2<char> auto... x);
static_assert(is_same_v<decltype(f18('a', 'b')), void>);
static_assert(is_same_v<decltype(f18('a', 1)), void>);
static_assert(is_same_v<decltype(f18(2, 'a')), void>);
void f19(C2<char> auto &... x);
static_assert(is_same_v<decltype(f19(c, c)), void>);
static_assert(is_same_v<decltype(f19(i, c)), void>);
static_assert(is_same_v<decltype(f19(c, c, cc)), void>);
void f20(const C2<char> auto &... x);
static_assert(is_same_v<decltype(f20(c, c)), void>);
static_assert(is_same_v<decltype(f20(i, c)), void>);
static_assert(is_same_v<decltype(f20(c, c, cc)), void>);
void f21(C2<char> decltype(auto) x); auto f22 = [] (C2<char> auto x) { };
static_assert(is_same_v<decltype(f22(1)), void>);
static_assert(is_same_v<decltype(f22('a')), void>);
struct S1 { S1(C auto); };
static_assert(is_same_v<decltype(S1(1)), S1>);
static_assert(is_same_v<decltype(S1('a')), S1>);
struct S2 { S2(C2<char> auto); };
static_assert(is_same_v<decltype(S2(1)), S2>);
static_assert(is_same_v<decltype(S2('a')), S2>);
}