Debian Codegraph @

gcc/testsuite/g++.dg/cpp2a/concepts-template-parm6.C

raw
1 // { dg-do compile { target c++20 } }
2
3 template<typename... Ts> struct are_same;
4
5 template<>
6 struct are_same<> {
7 static constexpr bool value = true;
8 };
9
10 template<typename T>
11 struct are_same<T> {
12 static constexpr bool value = true;
13 };
14
15 template<typename T, typename U, typename... Ts>
16 struct are_same<T, U, Ts...> {
17 static constexpr bool value =
18 __is_same_as(T, U) && are_same<U, Ts...>::value;
19 };
20
21 template<typename... Ts>
22 concept Same = are_same<Ts...>::value;
23
24 template<typename T>
25 concept Int = __is_same_as(T, int);
26
27 // NOTE: The use of Same is misleading; it constraints each T, not
28 // the pack of Ts.
29 template<Same... Ts> struct S1 { }; // requires (C<Ts> && ...)
30 S1<int, int, int> s1;
31 S1<int, int, bool> s2;
32
33 // // NOTE: The use of Same is misleading; it constraints each deduced
34 // // type, not the pack of Ts.
35 template<Same auto... Xs> struct S2 { }; // requires (C<X> && ...) with each X deduced
36 S2<true, true, true> s3;
37 S2<true, true, 'a'> s4; // OK
38
39 template<Int... Ts> struct S3 { }; // requires (C<Ts> && ...)
40 S3<int, int, char> x0; // { dg-error "template constraint failure" }
41
42 template<Int auto... Xs> struct S4 { }; // requires (C<X> && ...) with each X deduced
43 S4<0, 1, 2, 'a'> x1; // { dg-error "placeholder constraints not satisfied" }
44