1 | /* Boost.MultiIndex test for terse key specification syntax. |
2 | * |
3 | * Copyright 2003-2019 Joaquin M Lopez Munoz. |
4 | * Distributed under the Boost Software License, Version 1.0. |
5 | * (See accompanying file LICENSE_1_0.txt or copy at |
6 | * http://www.boost.org/LICENSE_1_0.txt) |
7 | * |
8 | * See http://www.boost.org/libs/multi_index for library home page. |
9 | */ |
10 | |
11 | #include "test_key.hpp" |
12 | |
13 | #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */ |
14 | #include <boost/detail/lightweight_test.hpp> |
15 | #include "pre_multi_index.hpp" |
16 | #include <boost/multi_index/key.hpp> |
17 | |
18 | #if !defined(BOOST_MULTI_INDEX_KEY_SUPPORTED) |
19 | |
20 | #include <boost/config/pragma_message.hpp> |
21 | |
22 | BOOST_PRAGMA_MESSAGE("boost::multi_index::key not supported, skipping test" ) |
23 | |
24 | void test_key() |
25 | { |
26 | } |
27 | #else |
28 | |
29 | #include <functional> |
30 | #include <type_traits> |
31 | |
32 | using namespace boost::multi_index; |
33 | |
34 | namespace { |
35 | |
36 | struct base |
37 | { |
38 | int x; |
39 | const int cx; |
40 | int f(){return x;}; |
41 | int cf()const{return x;}; |
42 | int vf()volatile{return x;}; |
43 | int cvf()const volatile{return x;}; |
44 | int rf()&{return x;}; |
45 | int crf()const&{return x;}; |
46 | int vrf()volatile&{return x;}; |
47 | int cvrf()const volatile&{return x;}; |
48 | int nef()noexcept{return x;}; |
49 | int cnef()const noexcept{return x;}; |
50 | int vnef()volatile noexcept{return x;}; |
51 | int cvnef()const volatile noexcept{return x;}; |
52 | int rnef()& noexcept{return x;}; |
53 | int crnef()const& noexcept{return x;}; |
54 | int vrnef()volatile& noexcept{return x;}; |
55 | int cvrnef()const volatile& noexcept{return x;}; |
56 | }; |
57 | |
58 | int gf(const base& b){return b.x;} |
59 | int negf(const base& b)noexcept{return b.x;} |
60 | |
61 | struct derived:base |
62 | { |
63 | int y; |
64 | }; |
65 | |
66 | int gh(derived& d){return d.y;} |
67 | int grh(std::reference_wrapper<derived>& d){return d.get().y;} |
68 | |
69 | } /* namespace */ |
70 | |
71 | void test_key() |
72 | { |
73 | BOOST_TEST((std::is_same< |
74 | key<&base::x>,member<base,int,&base::x> |
75 | >::value)); |
76 | BOOST_TEST((std::is_same< |
77 | key<&base::cx>,member<base,const int,&base::cx> |
78 | >::value)); |
79 | BOOST_TEST((std::is_same< |
80 | key<&base::f>,mem_fun<base,int,&base::f> |
81 | >::value)); |
82 | BOOST_TEST((std::is_same< |
83 | key<&base::cf>,const_mem_fun<base,int,&base::cf> |
84 | >::value)); |
85 | BOOST_TEST((std::is_same< |
86 | key<&base::vf>,volatile_mem_fun<base,int,&base::vf> |
87 | >::value)); |
88 | BOOST_TEST((std::is_same< |
89 | key<&base::cvf>,cv_mem_fun<base,int,&base::cvf> |
90 | >::value)); |
91 | BOOST_TEST((std::is_same< |
92 | key<&base::rf>,ref_mem_fun<base,int,&base::rf> |
93 | >::value)); |
94 | BOOST_TEST((std::is_same< |
95 | key<&base::crf>,cref_mem_fun<base,int,&base::crf> |
96 | >::value)); |
97 | BOOST_TEST((std::is_same< |
98 | key<&base::vrf>,vref_mem_fun<base,int,&base::vrf> |
99 | >::value)); |
100 | BOOST_TEST((std::is_same< |
101 | key<&base::cvrf>,cvref_mem_fun<base,int,&base::cvrf> |
102 | >::value)); |
103 | BOOST_TEST((std::is_same< |
104 | key<&base::nef>,mem_fun<base,int,&base::nef> |
105 | >::value)); |
106 | BOOST_TEST((std::is_same< |
107 | key<&base::cnef>,const_mem_fun<base,int,&base::cnef> |
108 | >::value)); |
109 | BOOST_TEST((std::is_same< |
110 | key<&base::vnef>,volatile_mem_fun<base,int,&base::vnef> |
111 | >::value)); |
112 | BOOST_TEST((std::is_same< |
113 | key<&base::cvnef>,cv_mem_fun<base,int,&base::cvnef> |
114 | >::value)); |
115 | BOOST_TEST((std::is_same< |
116 | key<&base::rnef>,ref_mem_fun<base,int,&base::rnef> |
117 | >::value)); |
118 | BOOST_TEST((std::is_same< |
119 | key<&base::crnef>,cref_mem_fun<base,int,&base::crnef> |
120 | >::value)); |
121 | BOOST_TEST((std::is_same< |
122 | key<&base::vrnef>,vref_mem_fun<base,int,&base::vrnef> |
123 | >::value)); |
124 | BOOST_TEST((std::is_same< |
125 | key<&base::cvrnef>,cvref_mem_fun<base,int,&base::cvrnef> |
126 | >::value)); |
127 | BOOST_TEST((std::is_same< |
128 | key<gf>,global_fun<const base&,int,gf> |
129 | >::value)); |
130 | BOOST_TEST((std::is_same< |
131 | key<negf>,global_fun<const base&,int,negf> |
132 | >::value)); |
133 | BOOST_TEST((std::is_same< |
134 | key<&base::x,&base::cx,&base::f,&base::cf,gf>, |
135 | composite_key< |
136 | base, |
137 | member<base,int,&base::x>, |
138 | member<base,const int,&base::cx>, |
139 | mem_fun<base,int,&base::f>, |
140 | const_mem_fun<base,int,&base::cf>, |
141 | global_fun<const base&,int,gf> |
142 | > |
143 | >::value)); |
144 | BOOST_TEST((std::is_same< |
145 | key<&base::x,&derived::y>, |
146 | composite_key< |
147 | derived, |
148 | member<base,int,&base::x>, |
149 | member<derived,int,&derived::y> |
150 | > |
151 | >::value)); |
152 | BOOST_TEST((std::is_same< |
153 | key<gf,gh>, |
154 | composite_key< |
155 | derived, |
156 | global_fun<const base&,int,gf>, |
157 | global_fun<derived&,int,gh> |
158 | > |
159 | >::value)); |
160 | BOOST_TEST((std::is_same< |
161 | key<gf,gh,grh>, |
162 | composite_key< |
163 | std::reference_wrapper<derived>, |
164 | global_fun<const base&,int,gf>, |
165 | global_fun<derived&,int,gh>, |
166 | global_fun<std::reference_wrapper<derived>&,int,grh> |
167 | > |
168 | >::value)); |
169 | } |
170 | #endif |
171 | |