Stroika Library 3.0d23
 
Loading...
Searching...
No Matches
Concepts.inl
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2026. All rights reserved
3 */
4
6
7 /////////////////////////////////////////////////////////////
8 ////////////////////// DEPREACTED BELOW /////////////////////
9 /////////////////////////////////////////////////////////////
10
11 DISABLE_COMPILER_MSC_WARNING_START (4996);
12 DISABLE_COMPILER_GCC_WARNING_START ("GCC diagnostic ignored \"-Wdeprecated-declarations\"");
13 DISABLE_COMPILER_CLANG_WARNING_START ("clang diagnostic ignored \"-Wdeprecated-declarations\"");
14 template <typename T>
15 [[deprecated ("Since Stroika v3.0d1, use IEqualToOptimizable concept")]] constexpr bool HasUsableEqualToOptimization ()
16 {
17 return IEqualToOptimizable<T>;
18 }
19
20 template <typename T>
21 [[deprecated ("Since Stroika v3.0d1, use require expression")]] constexpr inline bool has_plus_v = requires (T t) {
22 { t + t };
23 };
24 namespace Private_ {
25 template <typename From, typename To>
26 struct is_explicitly_convertible {
27 template <typename T>
28 static void f (T);
29
30 template <typename F, typename T>
31 static constexpr auto test (int) -> decltype (f (static_cast<T> (declval<F> ())), true)
32 {
33 return true;
34 }
35
36 template <typename F, typename T>
37 static constexpr auto test (...) -> bool
38 {
39 return false;
40 }
41
42 static bool const value = test<From, To> (0);
43 };
44 }
45 template <typename From, typename To>
46 [[deprecated ("Since Stroika v3.0d1 - not sure any point - probalyuse convertible or constructible concepts")]] constexpr inline bool is_explicitly_convertible_v =
47 Private_::is_explicitly_convertible<From, To>::value;
48
49 template <typename T>
50 [[deprecated ("Since Stroika v3.0d1, use IHasSizeMethod")]] constexpr inline bool has_size_v = IHasSizeMethod<T>;
51
52 namespace Private_ {
53 template <typename T>
54 using has_beginend_t = decltype (static_cast<bool> (begin (declval<T&> ()) != end (declval<T&> ())));
55 }
56 template <typename T>
57 [[deprecated ("Since Stroika v3.0d1, use std::ranges::range (probably - roughly same)")]] constexpr inline bool has_beginend_v =
58 is_detected_v<Private_::has_beginend_t, T>;
59
60 namespace Private_ {
61 template <typename T>
62 using has_minus_t = decltype (std::declval<T> () - std::declval<T> ());
63 }
64 template <typename T>
65 [[deprecated ("Since Stroika v3.0d1, use something else, either requires statment, or random_access_iterator for "
66 "example")]] constexpr inline bool has_minus_v = is_detected_v<Private_::has_minus_t, T>;
67 template <typename T, typename U>
68 [[deprecated ("Since Stroika v3.0d1, use something else, either requires statment, or random_access_iterator for "
69 "example")]] constexpr inline bool has_minus_v<std::pair<T, U>> = has_minus_v<T> and has_minus_v<U>;
70 template <typename... Ts>
71 [[deprecated ("Since Stroika v3.0d1, use something else, either requires statment, or random_access_iterator for "
72 "example")]] constexpr inline bool has_minus_v<std::tuple<Ts...>> = (has_minus_v<Ts> and ...);
73 namespace Private_ {
74 template <typename T>
75 using has_neq_t = decltype (static_cast<bool> (std::declval<T> () != std::declval<T> ()));
76 }
77 template <typename T>
78 [[deprecated ("Since Stroika v3.0d1, use equality_comparable (cuz in C++20 basically same) concept")]] constexpr inline bool has_neq_v =
79 is_detected_v<Private_::has_neq_t, T>;
80 template <typename T, typename U>
81 [[deprecated ("Since Stroika v3.0d1, use equality_comparable (cuz in C++20 basically same) concept")]] constexpr inline bool has_neq_v<std::pair<T, U>> =
82 has_neq_v<T> and has_neq_v<U>;
83 template <typename... Ts>
84 [[deprecated ("Since Stroika v3.0d1, use equality_comparable (cuz in C++20 basically same) concept")]] constexpr inline bool has_neq_v<std::tuple<Ts...>> =
85 (has_neq_v<Ts> and ...);
86
87 template <typename T>
88 [[deprecated ("Since Stroika v3.0d1, use equality_comparable concept")]] constexpr inline bool has_eq_v = equality_comparable<T>;
89
90 template <typename T>
91 [[deprecated ("Since Stroika v3.0d1, use totally_ordered concept")]] constexpr inline bool has_lt_v = totally_ordered<T>;
92
93 template <typename T>
94 [[deprecated ("Since Stroika v3.0d1, use IHasValueType concept")]] constexpr inline bool has_value_type_v = IHasValueType<T>;
95 template <typename T>
96 [[deprecated ("Since Stroika v3.0d1, use https://en.cppreference.com/w/cpp/concepts/equality_comparable")]] constexpr bool EqualityComparable ()
97 {
98 return equality_comparable<T>;
99 }
100
101 template <typename T>
102 [[deprecated ("Since Stroika v3.0d1, use https://en.cppreference.com/w/cpp/concepts/totally_ordered - NOT SAME THING AT ALL, BUT "
103 "CLOSEST IN STANDARD")]] constexpr bool
104 LessThanComparable ()
105 {
106 return has_lt_v<T>;
107 }
108
109 namespace Private_ {
110 // From https://stackoverflow.com/questions/15393938/find-out-if-a-c-object-is-callable
111 template <typename T>
112 struct is_callable_impl_ {
113 private:
114 typedef char (&yes)[1];
115 typedef char (&no)[2];
116
117 struct Fallback {
118 void operator() ();
119 };
120 struct Derived : T, Fallback {};
121
122 template <typename U, U>
123 struct Check;
124
125 template <typename>
126 static yes test (...);
127
128 template <typename C>
129 static no test (Check<void (Fallback::*) (), &C::operator()>*);
130
131 public:
132 static const bool value = sizeof (test<Derived> (0)) == sizeof (yes);
133 };
134 template <typename T>
135 using is_callable = conditional_t<is_class_v<T>, is_callable_impl_<T>, false_type>;
136 }
137 template <typename T>
138 [[deprecated ("Since Stroika v3.0d1, use https://en.cppreference.com/w/cpp/concepts/invocable")]] constexpr bool is_callable_v =
139 Private_::is_callable<T>::value;
140 template <typename ITERABLE>
141 [[deprecated ("Since Stroika v3.0d1, use ranges::range")]] constexpr bool IsIterable_v =
142 has_beginend_v<ITERABLE> and not same_as<ExtractValueType_t<ITERABLE>, void>;
143
144 namespace Private_ {
145
146 // Would be nice to simplify, but my current version of is_detected_v only takes one template parameter, and the std::experimental version not included in VS2k19
147 template <typename ITERABLE_OF_T, typename T>
148 struct IsIterableOfT_Impl2_ {
149 template <typename X, typename USE_ITERABLE = ITERABLE_OF_T,
150 bool ITER_RESULT_CONVERTIBLE_TO_T = is_convertible_v<decltype (*begin (declval<USE_ITERABLE&> ())), T>>
151 static auto check (const X& x)
152 -> conditional_t<is_detected_v<has_beginend_t, ITERABLE_OF_T> and ITER_RESULT_CONVERTIBLE_TO_T, substitution_succeeded<T>, substitution_failure>;
153 static substitution_failure check (...);
154 using type = decltype (check (declval<T> ()));
155 };
156 template <typename ITERABLE_OF_T, typename T>
157 using IsIterableOfT_t = integral_constant<bool, not same_as<typename IsIterableOfT_Impl2_<ITERABLE_OF_T, T>::type, substitution_failure>>;
158 }
159 template <typename ITERABLE_OF_T, typename T>
160 [[deprecated ("Since Stroika v3.0d1 use Traversal::IIterableOfTo concept")]] constexpr bool IsIterableOfT_v =
161 Private_::IsIterableOfT_t<ITERABLE_OF_T, T>::value;
162
163 namespace Private_ {
164 template <typename T, typename = void>
165 struct is_iterator {
166 static constexpr bool value = false;
167 };
168 template <typename T>
169 struct is_iterator<T, enable_if_t<!same_as<typename iterator_traits<T>::value_type, void>>> {
170 static constexpr bool value = true;
171 };
172 }
173 template <typename T>
174 [[deprecated ("Since Stroika v3.0d1, use input_iterator, forward_iterator, or some other sort of std iterator concept")]] constexpr bool IsIterator_v =
175 Private_::is_iterator<remove_cvref_t<T>>::value;
176
177 template <typename FUNCTOR_ARG, typename FUNCTOR>
178 [[deprecated ("Since Stroika v3.0d1, use std::predicate<F,ARG,ARG>")]] constexpr bool IsTPredicate ()
179 {
180 using T = remove_cvref_t<FUNCTOR_ARG>;
181 if constexpr (is_invocable_v<FUNCTOR, T>) {
182 return std::is_convertible_v<std::invoke_result_t<FUNCTOR, T>, bool>;
183 }
184 return false;
185 }
186 template <typename T>
187 [[deprecated ("Since Stroika v3.0d1, use three_way_comparable")]] constexpr inline bool has_spaceship_v = three_way_comparable<T>;
188 DISABLE_COMPILER_MSC_WARNING_END (4996);
189 DISABLE_COMPILER_GCC_WARNING_END ("GCC diagnostic ignored \"-Wdeprecated-declarations\"");
190 DISABLE_COMPILER_CLANG_WARNING_END ("clang diagnostic ignored \"-Wdeprecated-declarations\"");
191
192}