| 1 |
// PR c++/67148 |
| 2 |
// { dg-do compile { target c++20 } } |
| 3 |
// { dg-additional-options "-fconcepts" } |
| 4 |
|
| 5 |
namespace std |
| 6 |
{ |
| 7 |
template<typename T> |
| 8 |
T declval(); |
| 9 |
|
| 10 |
typedef unsigned int size_t; |
| 11 |
typedef int ptrdiff_t; |
| 12 |
typedef decltype(nullptr) nullptr_t; |
| 13 |
template<typename _Tp, _Tp... _Idx> |
| 14 |
struct integer_sequence |
| 15 |
{ |
| 16 |
typedef _Tp value_type; |
| 17 |
static constexpr size_t size() { return sizeof...(_Idx); } |
| 18 |
}; |
| 19 |
|
| 20 |
template <class T, T Value> |
| 21 |
struct integral_constant { |
| 22 |
using type = integral_constant; |
| 23 |
using value_type = T; |
| 24 |
constexpr operator T() const { return Value; } |
| 25 |
constexpr T operator()() const { return Value; } |
| 26 |
static constexpr T value {Value}; |
| 27 |
}; |
| 28 |
template <class T, T Value> |
| 29 |
constexpr T integral_constant<T, Value>::value; |
| 30 |
using true_type = integral_constant<bool, true>; |
| 31 |
using false_type = integral_constant<bool, false>; |
| 32 |
|
| 33 |
template <class T, class U> |
| 34 |
struct is_same : false_type {}; |
| 35 |
template <class T> |
| 36 |
struct is_same<T,T> : true_type {}; |
| 37 |
} |
| 38 |
|
| 39 |
namespace meta |
| 40 |
{ |
| 41 |
inline namespace v1 |
| 42 |
{ |
| 43 |
template <typename T> |
| 44 |
using _t = typename T::type; |
| 45 |
template <bool... Bools> |
| 46 |
using and_c = std::is_same<std::integer_sequence<bool, Bools...>, |
| 47 |
std::integer_sequence<bool, (Bools || true)...>>; |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
namespace stl2 { inline namespace v1 { |
| 52 |
using std::declval; |
| 53 |
namespace detail { |
| 54 |
template <class...> |
| 55 |
struct all_same : std::true_type {}; |
| 56 |
template <class T, class...Rest> |
| 57 |
struct all_same<T, Rest...> : |
| 58 |
meta::and_c<__is_same_as(T, Rest)...> {}; |
| 59 |
} |
| 60 |
template <class...Ts> |
| 61 |
concept Same = |
| 62 |
detail::all_same<Ts...>::value; |
| 63 |
|
| 64 |
template <class F, class...Args> |
| 65 |
using ResultType = decltype(declval<F>()(declval<Args>()...)); |
| 66 |
template <class> |
| 67 |
struct value_type {}; |
| 68 |
template <class T> |
| 69 |
struct value_type<T*> { |
| 70 |
using type = T; |
| 71 |
}; |
| 72 |
template <class T> |
| 73 |
using ValueType = |
| 74 |
typename value_type<T>::type; |
| 75 |
|
| 76 |
template <class F, class...Args> |
| 77 |
concept Function = |
| 78 |
requires (F& f, Args&&...args) { |
| 79 |
f((Args&&)args...); |
| 80 |
requires Same<decltype(f((Args&&)args...)), ResultType<F, Args...> >; |
| 81 |
}; |
| 82 |
|
| 83 |
|
| 84 |
template <class, class...> struct __function : std::false_type {}; |
| 85 |
template<typename F, typename... Args> |
| 86 |
requires Function<F, Args...> |
| 87 |
struct __function<F, Args...> : std::true_type {}; |
| 88 |
|
| 89 |
template <class F, class I1, class I2> |
| 90 |
concept IndirectCallable = |
| 91 |
Function<F, ValueType<I1>, ValueType<I2>>; |
| 92 |
|
| 93 |
|
| 94 |
template <class F, class I1, class I2> |
| 95 |
concept IndirectCallable2 = |
| 96 |
__function<F, ValueType<I1>, ValueType<I2>>::value; |
| 97 |
|
| 98 |
|
| 99 |
namespace ext { namespace models { |
| 100 |
template <class, class, class> |
| 101 |
constexpr bool indirect_callable() { return false; } |
| 102 |
template<typename F, typename I1, typename I2> |
| 103 |
requires IndirectCallable<F, I1, I2> |
| 104 |
constexpr bool indirect_callable() { return true; } |
| 105 |
|
| 106 |
template <class, class, class> |
| 107 |
constexpr bool indirect_callable2() { return false; } |
| 108 |
template<typename F, typename I1, typename I2> |
| 109 |
requires IndirectCallable<F, I1, I2> |
| 110 |
constexpr bool indirect_callable2() { return true; } |
| 111 |
}} |
| 112 |
}} |
| 113 |
|
| 114 |
namespace models = stl2::ext::models; |
| 115 |
|
| 116 |
template <class T = void> |
| 117 |
struct plus { |
| 118 |
T operator()(T, T) const; |
| 119 |
}; |
| 120 |
|
| 121 |
static_assert((models::indirect_callable<::plus<int>, int*, int*>())); |
| 122 |
static_assert((models::indirect_callable2<::plus<int>, int*, int*>())); |
| 123 |
|
| 124 |
static_assert((models::indirect_callable<::plus<int>, int**, int*>())); // { dg-error "static assertion failed" } |
| 125 |
static_assert((models::indirect_callable2<::plus<int>, int**, int*>())); // { dg-error "static assertion failed" } |