File: concepts-ts6.C

package info (click to toggle)
gcc-arm-none-eabi 15%3A14.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,099,328 kB
  • sloc: cpp: 3,627,108; ansic: 2,571,498; ada: 834,230; f90: 235,082; makefile: 79,231; asm: 74,984; xml: 51,692; exp: 39,736; sh: 33,298; objc: 15,629; python: 15,069; fortran: 14,429; pascal: 7,003; awk: 5,070; perl: 3,106; ml: 285; lisp: 253; lex: 204; haskell: 135
file content (74 lines) | stat: -rw-r--r-- 1,929 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// { dg-do compile { target c++20 } }
// { dg-additional-options "-fconcepts-ts" }

template<typename T, int N, typename... Xs> concept bool C1 = true;

template<template<typename> class X> concept bool C2 = true;

template<typename... Ts> concept bool C3 = true;

C1{A, B, ...C} struct S1 { };

C2{T} void f();

C2{...Ts} void g(); // { dg-error "cannot be introduced" }

C3{...Ts} struct S2 { };
C3{T, U, V} struct S3 { };
C3{...Ts, U} struct S4 { }; // { dg-error "cannot deduce template parameters" }

template<typename> struct X { };

void driver1() {
  S1<int, 0, char, bool, float> s1a;
  S1<0, 0, char, bool, float> s1b; // { dg-error "type/value mismatch" }

  f<X>();
  f<int>(); // { dg-error "no matching function for call" }
  // { dg-error "type/value mismatch at argument 1" "" { target *-*-* } .-1 }
  // { dg-message "expected a class template, got .int." "" { target *-*-* } .-2 }

  S2<int> s2a;
  S2<char, signed char, unsigned char> s2b;
  S2<0> s2c; // { dg-error "type/value mismatch" }

  S3<int, int, int> s3a;
  S3<int, int> s3b; // { dg-error "wrong number of template arguments" }
}

template<typename... Args>
struct all_same;

template<typename T, typename U, typename... Args>
struct all_same<T, U, Args...>
{
  static constexpr bool value = __is_same_as(T, U) && all_same<U, Args...>::value;
};

template<typename T>
struct all_same<T>
{
  static constexpr bool value = true;
};

template<>
struct all_same<>
{
  static constexpr bool value = true;
};

template<typename... Ts>
concept AllSame = all_same<Ts...>::value;

AllSame{...Ts} struct S5 { };
AllSame{T, U} struct S6 { };

void driver2()
{
  S5<int, int> s5a;
  S5<int, int, int, int> s5b;
  S5<int, int, int, char> s5c; // { dg-error "template constraint failure" }
  S6<void, void> s6a;
  S6<void, int> s6c; // { dg-error "template constraint failure" }
  S6<void, void, void> s6b; // { dg-error "wrong number of template arguments" }
}