1 //
2 // cpp03/can_prefer_free_require.cpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
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)
9 //
10
11 #include <boost/asio/prefer.hpp>
12 #include <cassert>
13
14 template <int>
15 struct prop
16 {
17 static const bool is_preferable = true;
18 };
19
20 template <int>
21 struct object
22 {
23 template <int N>
require(const object &,prop<N>)24 friend object<N> require(const object&, prop<N>)
25 {
26 return object<N>();
27 }
28 };
29
30 namespace boost {
31 namespace asio {
32
33 template<int N, int M>
34 struct is_applicable_property<object<N>, prop<M> >
35 {
36 static const bool value = true;
37 };
38
39 namespace traits {
40
41 template<int N, int M>
42 struct require_free<object<N>, prop<M> >
43 {
44 static const bool is_valid = true;
45 static const bool is_noexcept = true;
46 typedef object<M> result_type;
47 };
48
49 } // namespace traits
50 } // namespace asio
51 } // namespace boost
52
main()53 int main()
54 {
55 assert((boost::asio::can_prefer<object<1>, prop<2> >::value));
56 assert((boost::asio::can_prefer<object<1>, prop<2>, prop<3> >::value));
57 assert((boost::asio::can_prefer<object<1>, prop<2>, prop<3>, prop<4> >::value));
58 assert((boost::asio::can_prefer<const object<1>, prop<2> >::value));
59 assert((boost::asio::can_prefer<const object<1>, prop<2>, prop<3> >::value));
60 assert((boost::asio::can_prefer<const object<1>, prop<2>, prop<3>, prop<4> >::value));
61 }
62