5 // Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_ASIO_REQUIRE_CONCEPT_HPP
12 #define BOOST_ASIO_REQUIRE_CONCEPT_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
19 #include <boost/asio/detail/type_traits.hpp>
20 #include <boost/asio/is_applicable_property.hpp>
21 #include <boost/asio/traits/require_concept_member.hpp>
22 #include <boost/asio/traits/require_concept_free.hpp>
23 #include <boost/asio/traits/static_require_concept.hpp>
25 #include <boost/asio/detail/push_options.hpp>
27 #if defined(GENERATING_DOCUMENTATION)
32 /// A customisation point that applies a concept-enforcing property to an
35 * The name <tt>require_concept</tt> denotes a customization point object. The
36 * expression <tt>boost::asio::require_concept(E, P)</tt> for some
37 * subexpressions <tt>E</tt> and <tt>P</tt> (with types <tt>T =
38 * decay_t<decltype(E)></tt> and <tt>Prop = decay_t<decltype(P)></tt>) is
39 * expression-equivalent to:
41 * @li If <tt>is_applicable_property_v<T, Prop> &&
42 * Prop::is_requirable_concept</tt> is not a well-formed constant expression
43 * with value <tt>true</tt>, <tt>boost::asio::require_concept(E, P)</tt> is
46 * @li Otherwise, <tt>E</tt> if the expression <tt>Prop::template
47 * static_query_v<T> == Prop::value()</tt> is a well-formed constant
48 * expression with value <tt>true</tt>.
50 * @li Otherwise, <tt>(E).require_concept(P)</tt> if the expression
51 * <tt>(E).require_concept(P)</tt> is well-formed.
53 * @li Otherwise, <tt>require_concept(E, P)</tt> if the expression
54 * <tt>require_concept(E, P)</tt> is a valid expression with overload
55 * resolution performed in a context that does not include the declaration
56 * of the <tt>require_concept</tt> customization point object.
58 * @li Otherwise, <tt>boost::asio::require_concept(E, P)</tt> is ill-formed.
60 inline constexpr unspecified require_concept = unspecified;
62 /// A type trait that determines whether a @c require_concept expression is
65 * Class template @c can_require_concept is a trait that is derived from
66 * @c true_type if the expression
67 * <tt>boost::asio::require_concept(std::declval<T>(),
68 * std::declval<Property>())</tt> is well formed; otherwise @c false_type.
70 template <typename T, typename Property>
71 struct can_require_concept :
72 integral_constant<bool, automatically_determined>
76 /// A type trait that determines whether a @c require_concept expression will
79 * Class template @c is_nothrow_require_concept is a trait that is derived from
80 * @c true_type if the expression
81 * <tt>boost::asio::require_concept(std::declval<T>(),
82 * std::declval<Property>())</tt> is @c noexcept; otherwise @c false_type.
84 template <typename T, typename Property>
85 struct is_nothrow_require_concept :
86 integral_constant<bool, automatically_determined>
90 /// A type trait that determines the result type of a @c require_concept
93 * Class template @c require_concept_result is a trait that determines the
94 * result type of the expression
95 * <tt>boost::asio::require_concept(std::declval<T>(),
96 * std::declval<Property>())</tt>.
98 template <typename T, typename Property>
99 struct require_concept_result
101 /// The result of the @c require_concept expression.
102 typedef automatically_determined type;
108 #else // defined(GENERATING_DOCUMENTATION)
110 namespace asio_require_concept_fn {
112 using boost::asio::decay;
113 using boost::asio::declval;
114 using boost::asio::enable_if;
115 using boost::asio::is_applicable_property;
116 using boost::asio::traits::require_concept_free;
117 using boost::asio::traits::require_concept_member;
118 using boost::asio::traits::static_require_concept;
120 void require_concept();
130 template <typename T, typename Properties, typename = void>
133 BOOST_ASIO_STATIC_CONSTEXPR(overload_type, overload = ill_formed);
134 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = false);
135 typedef void result_type;
138 template <typename T, typename Property>
139 struct call_traits<T, void(Property),
142 is_applicable_property<
143 typename decay<T>::type,
144 typename decay<Property>::type
147 decay<Property>::type::is_requirable_concept
149 static_require_concept<T, Property>::is_valid
153 BOOST_ASIO_STATIC_CONSTEXPR(overload_type, overload = identity);
154 BOOST_ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);
155 typedef BOOST_ASIO_MOVE_ARG(T) result_type;
158 template <typename T, typename Property>
159 struct call_traits<T, void(Property),
162 is_applicable_property<
163 typename decay<T>::type,
164 typename decay<Property>::type
167 decay<Property>::type::is_requirable_concept
169 !static_require_concept<T, Property>::is_valid
171 require_concept_member<T, Property>::is_valid
174 require_concept_member<T, Property>
176 BOOST_ASIO_STATIC_CONSTEXPR(overload_type, overload = call_member);
179 template <typename T, typename Property>
180 struct call_traits<T, void(Property),
183 is_applicable_property<
184 typename decay<T>::type,
185 typename decay<Property>::type
188 decay<Property>::type::is_requirable_concept
190 !static_require_concept<T, Property>::is_valid
192 !require_concept_member<T, Property>::is_valid
194 require_concept_free<T, Property>::is_valid
197 require_concept_free<T, Property>
199 BOOST_ASIO_STATIC_CONSTEXPR(overload_type, overload = call_free);
204 template <typename T, typename Property>
205 BOOST_ASIO_NODISCARD BOOST_ASIO_CONSTEXPR typename enable_if<
206 call_traits<T, void(Property)>::overload == identity,
207 typename call_traits<T, void(Property)>::result_type
210 BOOST_ASIO_MOVE_ARG(T) t,
211 BOOST_ASIO_MOVE_ARG(Property)) const
212 BOOST_ASIO_NOEXCEPT_IF((
213 call_traits<T, void(Property)>::is_noexcept))
215 return BOOST_ASIO_MOVE_CAST(T)(t);
218 template <typename T, typename Property>
219 BOOST_ASIO_NODISCARD BOOST_ASIO_CONSTEXPR typename enable_if<
220 call_traits<T, void(Property)>::overload == call_member,
221 typename call_traits<T, void(Property)>::result_type
224 BOOST_ASIO_MOVE_ARG(T) t,
225 BOOST_ASIO_MOVE_ARG(Property) p) const
226 BOOST_ASIO_NOEXCEPT_IF((
227 call_traits<T, void(Property)>::is_noexcept))
229 return BOOST_ASIO_MOVE_CAST(T)(t).require_concept(
230 BOOST_ASIO_MOVE_CAST(Property)(p));
233 template <typename T, typename Property>
234 BOOST_ASIO_NODISCARD BOOST_ASIO_CONSTEXPR typename enable_if<
235 call_traits<T, void(Property)>::overload == call_free,
236 typename call_traits<T, void(Property)>::result_type
239 BOOST_ASIO_MOVE_ARG(T) t,
240 BOOST_ASIO_MOVE_ARG(Property) p) const
241 BOOST_ASIO_NOEXCEPT_IF((
242 call_traits<T, void(Property)>::is_noexcept))
244 return require_concept(
245 BOOST_ASIO_MOVE_CAST(T)(t),
246 BOOST_ASIO_MOVE_CAST(Property)(p));
250 template <typename T = impl>
251 struct static_instance
253 static const T instance;
256 template <typename T>
257 const T static_instance<T>::instance = {};
259 } // namespace asio_require_concept_fn
264 static BOOST_ASIO_CONSTEXPR const asio_require_concept_fn::impl&
265 require_concept = asio_require_concept_fn::static_instance<>::instance;
269 template <typename T, typename Property>
270 struct can_require_concept :
271 integral_constant<bool,
272 asio_require_concept_fn::call_traits<T, void(Property)>::overload !=
273 asio_require_concept_fn::ill_formed>
277 #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
279 template <typename T, typename Property>
280 constexpr bool can_require_concept_v
281 = can_require_concept<T, Property>::value;
283 #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
285 template <typename T, typename Property>
286 struct is_nothrow_require_concept :
287 integral_constant<bool,
288 asio_require_concept_fn::call_traits<T, void(Property)>::is_noexcept>
292 #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
294 template <typename T, typename Property>
295 constexpr bool is_nothrow_require_concept_v
296 = is_nothrow_require_concept<T, Property>::value;
298 #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
300 template <typename T, typename Property>
301 struct require_concept_result
303 typedef typename asio_require_concept_fn::call_traits<
304 T, void(Property)>::result_type type;
310 #endif // defined(GENERATING_DOCUMENTATION)
312 #include <boost/asio/detail/pop_options.hpp>
314 #endif // BOOST_ASIO_REQUIRE_CONCEPT_HPP