Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/g++.dg/cpp2a/concepts-pr67860.C @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
131:84e7813d76e9 | 145:1830386684a0 |
---|---|
1 // { dg-do compile { target c++2a } } | |
2 // { dg-additional-options "-fconcepts-ts" } | |
3 | |
4 #include <type_traits> | |
5 | |
6 inline constexpr bool and_impl() { return true; } | |
7 | |
8 template <class OperandFirst, class... OperandsRest> | |
9 constexpr bool and_impl(OperandFirst operand_first, | |
10 OperandsRest... operands_rest) { | |
11 return operand_first && and_impl(operands_rest...); | |
12 } | |
13 | |
14 template <class... Operands> constexpr bool and_(Operands... operands) { | |
15 return and_impl(operands...); | |
16 } | |
17 | |
18 template <class X> concept bool C() { return true; } | |
19 | |
20 // v1 | |
21 template<int, class... Xs> | |
22 requires and_(C<Xs>()...) | |
23 constexpr int f(const Xs&... xs) { | |
24 return 0; | |
25 } | |
26 | |
27 // v2 | |
28 template<int, class... Xs> | |
29 constexpr int f(const Xs&... xs) { | |
30 return 1; | |
31 } | |
32 | |
33 int main() { | |
34 static_assert(f<10>(3.0, 2.0f) == 0); | |
35 return 0; | |
36 } | |
37 | |
38 // 2nd example | |
39 | |
40 template <typename T, typename... Us> | |
41 concept bool AreType() { | |
42 return (std::is_same<T,Us>::value && ...); | |
43 // return true; gives the same overloaded error | |
44 } | |
45 | |
46 // Function with constraint | |
47 template<typename T, AreType<T>... Us> | |
48 constexpr bool isValid(Us... us) { | |
49 return true; | |
50 } | |
51 | |
52 // Function with no constraint | |
53 template<typename T, typename... U> | |
54 constexpr bool isValid(U... u) { | |
55 return false; | |
56 } | |
57 | |
58 int main2() { | |
59 static_assert(isValid<int>(1)); // also isValid<int>(1, 2, 3); etc | |
60 return 0; | |
61 } |