| 1 | // Boost.TypeErasure library |
| 2 | // |
| 3 | // Copyright 2011 Steven Watanabe |
| 4 | // |
| 5 | // Distributed under the Boost Software License Version 1.0. (See |
| 6 | // accompanying file LICENSE_1_0.txt or copy at |
| 7 | // http://www.boost.org/LICENSE_1_0.txt) |
| 8 | // |
| 9 | // $Id$ |
| 10 | |
| 11 | #include <boost/type_erasure/any.hpp> |
| 12 | #include <boost/type_erasure/tuple.hpp> |
| 13 | #include <boost/type_erasure/builtin.hpp> |
| 14 | #include <boost/type_erasure/operators.hpp> |
| 15 | #include <boost/type_erasure/any_cast.hpp> |
| 16 | #include <boost/type_erasure/binding_of.hpp> |
| 17 | #include <boost/mpl/vector.hpp> |
| 18 | #include <boost/tuple/tuple.hpp> |
| 19 | #include <vector> |
| 20 | |
| 21 | #define BOOST_TEST_MAIN |
| 22 | #include <boost/test/unit_test.hpp> |
| 23 | |
| 24 | using namespace boost::type_erasure; |
| 25 | |
| 26 | template<class T = _self> |
| 27 | struct common : ::boost::mpl::vector< |
| 28 | copy_constructible<T>, |
| 29 | typeid_<T> |
| 30 | > {}; |
| 31 | |
| 32 | BOOST_AUTO_TEST_CASE(test_implicit) { |
| 33 | any<common<> > x = 1; |
| 34 | BOOST_CHECK_EQUAL(any_cast<int>(x), 1); |
| 35 | } |
| 36 | |
| 37 | void func() {} |
| 38 | |
| 39 | BOOST_AUTO_TEST_CASE(test_decay) { |
| 40 | char array[] = "Hello World!" ; |
| 41 | const char carray[] = "Hello World!" ; |
| 42 | |
| 43 | any<common<> > x1(array); |
| 44 | any<common<> > y1(func); |
| 45 | any<common<> > z1(carray); |
| 46 | BOOST_CHECK_EQUAL(any_cast<char *>(x1), &array[0]); |
| 47 | BOOST_CHECK(any_cast<void(*)()>(y1) == &func); |
| 48 | BOOST_CHECK_EQUAL(any_cast<const char *>(z1), &carray[0]); |
| 49 | |
| 50 | any<common<> > x2(array, make_binding<boost::mpl::map<boost::mpl::pair<_self, char *> > >()); |
| 51 | any<common<> > y2(func, make_binding<boost::mpl::map<boost::mpl::pair<_self, void(*)()> > >()); |
| 52 | any<common<> > z2(carray, make_binding<boost::mpl::map<boost::mpl::pair<_self, const char *> > >()); |
| 53 | BOOST_CHECK_EQUAL(any_cast<char *>(x2), &array[0]); |
| 54 | BOOST_CHECK(any_cast<void(*)()>(y2) == &func); |
| 55 | BOOST_CHECK_EQUAL(any_cast<const char *>(z2), &carray[0]); |
| 56 | |
| 57 | static_binding<boost::mpl::map<boost::mpl::pair<_self, char *> > > bx3; |
| 58 | static_binding<boost::mpl::map<boost::mpl::pair<_self, void (*)()> > > by3; |
| 59 | static_binding<boost::mpl::map<boost::mpl::pair<_self, const char *> > > bz3; |
| 60 | any<common<> > x3(array, bx3); |
| 61 | any<common<> > y3(func, by3); |
| 62 | any<common<> > z3(carray, bz3); |
| 63 | BOOST_CHECK_EQUAL(any_cast<char *>(x3), &array[0]); |
| 64 | BOOST_CHECK(any_cast<void(*)()>(y3) == &func); |
| 65 | BOOST_CHECK_EQUAL(any_cast<const char *>(z3), &carray[0]); |
| 66 | } |
| 67 | |
| 68 | enum { |
| 69 | lvalue, |
| 70 | const_lvalue, |
| 71 | rvalue |
| 72 | #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES |
| 73 | = lvalue |
| 74 | #endif |
| 75 | }; |
| 76 | |
| 77 | template<class T> |
| 78 | int make_arg_type(); |
| 79 | |
| 80 | template<> |
| 81 | int make_arg_type<int>() { return rvalue; } |
| 82 | template<> |
| 83 | int make_arg_type<int&>() { return lvalue; } |
| 84 | template<> |
| 85 | int make_arg_type<const int&>() { return const_lvalue; } |
| 86 | |
| 87 | enum { id_int = 4, id_copy = 8 }; |
| 88 | |
| 89 | std::vector<int> make_vector() { return std::vector<int>(); } |
| 90 | |
| 91 | template<class T> |
| 92 | std::vector<T> make_vector(T t0) { |
| 93 | std::vector<T> result; |
| 94 | result.push_back(t0); |
| 95 | return result; |
| 96 | } |
| 97 | template<class T> |
| 98 | std::vector<T> make_vector(T t0, T t1) { |
| 99 | std::vector<T> result; |
| 100 | result.push_back(t0); |
| 101 | result.push_back(t1); |
| 102 | return result; |
| 103 | } |
| 104 | |
| 105 | #ifdef BOOST_MSVC |
| 106 | #pragma warning(disable:4521) // multiple copy constructors specified |
| 107 | #endif |
| 108 | |
| 109 | struct test_class |
| 110 | { |
| 111 | |
| 112 | test_class() {} |
| 113 | |
| 114 | test_class(const test_class &) |
| 115 | : args(make_vector(t0: const_lvalue | id_copy)) |
| 116 | {} |
| 117 | |
| 118 | test_class(test_class &) |
| 119 | : args(make_vector(t0: lvalue | id_copy)) |
| 120 | {} |
| 121 | |
| 122 | #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES |
| 123 | |
| 124 | test_class(test_class &&) |
| 125 | : args(make_vector(t0: rvalue | id_copy)) |
| 126 | {} |
| 127 | |
| 128 | template<class T0> |
| 129 | test_class(T0&& t0) |
| 130 | : args(make_vector(t0 | make_arg_type<T0>())) |
| 131 | {} |
| 132 | |
| 133 | template<class T0, class T1> |
| 134 | test_class(T0&& t0, T1&& t1) |
| 135 | : args(make_vector(t0 | make_arg_type<T0>(), t1 | make_arg_type<T1>())) |
| 136 | {} |
| 137 | |
| 138 | #else |
| 139 | |
| 140 | test_class(int& i0) |
| 141 | : args(make_vector(i0 | lvalue)) |
| 142 | {} |
| 143 | test_class(const int& i0) |
| 144 | : args(make_vector(i0 | const_lvalue)) |
| 145 | {} |
| 146 | test_class(int& i0, int& i1) |
| 147 | : args(make_vector(i0 | lvalue, i1 | lvalue)) |
| 148 | {} |
| 149 | test_class(int& i0, const int& i1) |
| 150 | : args(make_vector(i0 | lvalue, i1 | const_lvalue)) |
| 151 | {} |
| 152 | test_class(const int& i0, int& i1) |
| 153 | : args(make_vector(i0 | const_lvalue, i1 | lvalue)) |
| 154 | {} |
| 155 | test_class(const int& i0, const int& i1) |
| 156 | : args(make_vector(i0 | const_lvalue, i1 | const_lvalue)) |
| 157 | {} |
| 158 | |
| 159 | #endif |
| 160 | std::vector<int> args; |
| 161 | }; |
| 162 | |
| 163 | template<class T> |
| 164 | struct make_arg_impl; |
| 165 | |
| 166 | template<> |
| 167 | struct make_arg_impl<int> |
| 168 | { |
| 169 | static int apply() |
| 170 | { |
| 171 | return id_int; |
| 172 | } |
| 173 | }; |
| 174 | |
| 175 | template<class Concept> |
| 176 | struct make_arg_impl<binding<Concept> > |
| 177 | { |
| 178 | static binding<Concept> apply() |
| 179 | { |
| 180 | return make_binding< ::boost::mpl::map< |
| 181 | ::boost::mpl::pair<_a, test_class>, |
| 182 | ::boost::mpl::pair<_b, int> |
| 183 | > >(); |
| 184 | } |
| 185 | }; |
| 186 | |
| 187 | template<class Concept> |
| 188 | struct make_arg_impl<any<Concept, _a>&> |
| 189 | { |
| 190 | static any<Concept, _a>& apply() |
| 191 | { |
| 192 | static any<Concept, _a> result( |
| 193 | test_class(), |
| 194 | make_binding< ::boost::mpl::map< |
| 195 | ::boost::mpl::pair<_a, test_class>, |
| 196 | ::boost::mpl::pair<_b, int> |
| 197 | > >()); |
| 198 | return result; |
| 199 | } |
| 200 | }; |
| 201 | |
| 202 | template<class Concept> |
| 203 | struct make_arg_impl<any<Concept, _b>&> |
| 204 | { |
| 205 | static any<Concept, _b>& apply() |
| 206 | { |
| 207 | static any<Concept, _b> result( |
| 208 | (int)id_int, |
| 209 | make_binding< ::boost::mpl::map< |
| 210 | ::boost::mpl::pair<_a, test_class>, |
| 211 | ::boost::mpl::pair<_b, int> |
| 212 | > >()); |
| 213 | return result; |
| 214 | } |
| 215 | }; |
| 216 | |
| 217 | template<class Concept> |
| 218 | struct make_arg_impl<any<Concept, _a> > |
| 219 | { |
| 220 | static any<Concept, _a> apply() |
| 221 | { |
| 222 | return make_arg_impl<any<Concept, _a>&>::apply(); |
| 223 | } |
| 224 | }; |
| 225 | |
| 226 | template<class Concept> |
| 227 | struct make_arg_impl<any<Concept, _b> > |
| 228 | { |
| 229 | static any<Concept, _b> apply() |
| 230 | { |
| 231 | return make_arg_impl<any<Concept, _b>&>::apply(); |
| 232 | } |
| 233 | }; |
| 234 | |
| 235 | template<class Concept, class T> |
| 236 | struct make_arg_impl<any<Concept, T&> > |
| 237 | { |
| 238 | static any<Concept, T&> apply() |
| 239 | { |
| 240 | return make_arg_impl<any<Concept, T>&>::apply(); |
| 241 | } |
| 242 | }; |
| 243 | |
| 244 | template<class Concept, class T> |
| 245 | struct make_arg_impl<any<Concept, const T&> > |
| 246 | { |
| 247 | static any<Concept, const T&> apply() |
| 248 | { |
| 249 | return make_arg_impl<any<Concept, T>&>::apply(); |
| 250 | } |
| 251 | }; |
| 252 | |
| 253 | #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES |
| 254 | |
| 255 | template<class Concept, class T> |
| 256 | struct make_arg_impl<any<Concept, T&&> > |
| 257 | { |
| 258 | static any<Concept, T&&> apply() |
| 259 | { |
| 260 | return std::move(make_arg_impl<any<Concept, T>&>::apply()); |
| 261 | } |
| 262 | }; |
| 263 | |
| 264 | #endif |
| 265 | |
| 266 | template<class T> |
| 267 | struct make_arg_impl<const T> : make_arg_impl<T> {}; |
| 268 | |
| 269 | template<class T> |
| 270 | struct make_arg_impl<T&> |
| 271 | { |
| 272 | static T& apply() |
| 273 | { |
| 274 | static T result = make_arg_impl<T>::apply(); |
| 275 | return result; |
| 276 | } |
| 277 | }; |
| 278 | template<class T> |
| 279 | struct make_arg_impl<const T&> |
| 280 | { |
| 281 | static T& apply() |
| 282 | { |
| 283 | return make_arg_impl<T&>::apply(); |
| 284 | } |
| 285 | }; |
| 286 | |
| 287 | #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES |
| 288 | |
| 289 | template<class T> |
| 290 | struct make_arg_impl<T&&> |
| 291 | { |
| 292 | static T&& apply() |
| 293 | { |
| 294 | return std::move(make_arg_impl<T&>::apply()); |
| 295 | } |
| 296 | }; |
| 297 | |
| 298 | #endif |
| 299 | |
| 300 | #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES |
| 301 | |
| 302 | template<class T> |
| 303 | T make_arg() |
| 304 | { |
| 305 | return make_arg_impl<T>::apply(); |
| 306 | } |
| 307 | |
| 308 | #else |
| 309 | |
| 310 | template<class T> |
| 311 | T&& make_arg() |
| 312 | { |
| 313 | return make_arg_impl<T&&>::apply(); |
| 314 | } |
| 315 | |
| 316 | #endif |
| 317 | |
| 318 | int get_value(int i) { return i; } |
| 319 | template<class T> |
| 320 | int get_value(const T& t) { return any_cast<int>(t); } |
| 321 | |
| 322 | template<class Sig, class Args> |
| 323 | struct tester; |
| 324 | |
| 325 | template<class Concept, class T> |
| 326 | struct tester<Concept, void(T)> |
| 327 | { |
| 328 | static std::vector<int> apply() |
| 329 | { |
| 330 | any<Concept, _a> x(make_arg<T>()); |
| 331 | const test_class& result = any_cast<const test_class&>(x); |
| 332 | return result.args; |
| 333 | } |
| 334 | }; |
| 335 | |
| 336 | template<class Concept, class T0, class T1> |
| 337 | struct tester<Concept, void(T0, T1)> |
| 338 | { |
| 339 | static std::vector<int> apply() |
| 340 | { |
| 341 | any<Concept, _a> x(make_arg<T0>(), make_arg<T1>()); |
| 342 | const test_class& result = any_cast<const test_class&>(x); |
| 343 | return result.args; |
| 344 | } |
| 345 | }; |
| 346 | |
| 347 | template<class Concept, class T0, class T1, class T2> |
| 348 | struct tester<Concept, void(T0, T1, T2)> |
| 349 | { |
| 350 | static std::vector<int> apply() |
| 351 | { |
| 352 | any<Concept, _a> x(make_arg<T0>(), make_arg<T1>(), make_arg<T2>()); |
| 353 | const test_class& result = any_cast<const test_class&>(x); |
| 354 | return result.args; |
| 355 | } |
| 356 | }; |
| 357 | |
| 358 | #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES |
| 359 | // We need copy_constructible in order to get an rvalue. |
| 360 | #define CONSTRUCT_COMMON(p) common<p> |
| 361 | #else |
| 362 | // Don't include the copy constructor if we don't |
| 363 | // need it, as it can hide the non-const copy constructor. |
| 364 | #define CONSTRUCT_COMMON(p) destructible<p>, typeid_<p> |
| 365 | #endif |
| 366 | |
| 367 | #define TEST_CONSTRUCT(sig, args, expected_) \ |
| 368 | {\ |
| 369 | typedef ::boost::mpl::vector<\ |
| 370 | CONSTRUCT_COMMON(_a), \ |
| 371 | common<_b>,\ |
| 372 | constructible<sig>,\ |
| 373 | extra\ |
| 374 | > C;\ |
| 375 | std::vector<int> result = tester<C, void args>::apply();\ |
| 376 | std::vector<int> expected = make_vector expected_;\ |
| 377 | BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(), \ |
| 378 | expected.begin(), expected.end());\ |
| 379 | } |
| 380 | |
| 381 | typedef ::boost::mpl::vector< |
| 382 | ::boost::mpl::vector<>, |
| 383 | ::boost::type_erasure::relaxed |
| 384 | > maybe_relaxed; |
| 385 | |
| 386 | BOOST_AUTO_TEST_CASE_TEMPLATE(test_default, extra, maybe_relaxed) |
| 387 | { |
| 388 | TEST_CONSTRUCT(_a(), (binding<C>), ()); |
| 389 | TEST_CONSTRUCT(_a(), (binding<C>&), ()); |
| 390 | TEST_CONSTRUCT(_a(), (const binding<C>&), ()); |
| 391 | } |
| 392 | |
| 393 | // test all forms of direct construction that take 1 argument |
| 394 | BOOST_AUTO_TEST_CASE_TEMPLATE(test_construct1, extra, maybe_relaxed) |
| 395 | { |
| 396 | // construction from int |
| 397 | TEST_CONSTRUCT(_a(int&), (binding<C>, int&), (lvalue | id_int)); |
| 398 | TEST_CONSTRUCT(_a(int&), (binding<C>&, int&), (lvalue | id_int)); |
| 399 | TEST_CONSTRUCT(_a(int&), (const binding<C>&, int&), (lvalue | id_int)); |
| 400 | |
| 401 | TEST_CONSTRUCT(_a(const int&), (binding<C>, int), (const_lvalue | id_int)); |
| 402 | TEST_CONSTRUCT(_a(const int&), (binding<C>, int&), (const_lvalue | id_int)); |
| 403 | TEST_CONSTRUCT(_a(const int&), (binding<C>, const int&), (const_lvalue | id_int)); |
| 404 | TEST_CONSTRUCT(_a(const int&), (binding<C>&, int), (const_lvalue | id_int)); |
| 405 | TEST_CONSTRUCT(_a(const int&), (binding<C>&, int&), (const_lvalue | id_int)); |
| 406 | TEST_CONSTRUCT(_a(const int&), (binding<C>&, const int&), (const_lvalue | id_int)); |
| 407 | TEST_CONSTRUCT(_a(const int&), (const binding<C>&, int), (const_lvalue | id_int)); |
| 408 | TEST_CONSTRUCT(_a(const int&), (const binding<C>&, int&), (const_lvalue | id_int)); |
| 409 | TEST_CONSTRUCT(_a(const int&), (const binding<C>&, const int&), (const_lvalue | id_int)); |
| 410 | |
| 411 | TEST_CONSTRUCT(_a(int), (binding<C>, int), (rvalue | id_int)); |
| 412 | TEST_CONSTRUCT(_a(int), (binding<C>, int&), (rvalue | id_int)); |
| 413 | TEST_CONSTRUCT(_a(int), (binding<C>, const int&), (rvalue | id_int)); |
| 414 | TEST_CONSTRUCT(_a(int), (binding<C>&, int), (rvalue | id_int)); |
| 415 | TEST_CONSTRUCT(_a(int), (binding<C>&, int&), (rvalue | id_int)); |
| 416 | TEST_CONSTRUCT(_a(int), (binding<C>&, const int&), (rvalue | id_int)); |
| 417 | TEST_CONSTRUCT(_a(int), (const binding<C>&, int), (rvalue | id_int)); |
| 418 | TEST_CONSTRUCT(_a(int), (const binding<C>&, int&), (rvalue | id_int)); |
| 419 | TEST_CONSTRUCT(_a(int), (const binding<C>&, const int&), (rvalue | id_int)); |
| 420 | |
| 421 | #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES |
| 422 | TEST_CONSTRUCT(_a(int&&), (binding<C>, int), (rvalue | id_int)); |
| 423 | TEST_CONSTRUCT(_a(int&&), (binding<C>&, int), (rvalue | id_int)); |
| 424 | TEST_CONSTRUCT(_a(int&&), (const binding<C>&, int), (rvalue | id_int)); |
| 425 | #endif |
| 426 | |
| 427 | // Test same any type |
| 428 | |
| 429 | #ifndef BOOST_NO_CXX11_REF_QUALIFIERS |
| 430 | // ambiguous with the copy constructor in C++03 |
| 431 | TEST_CONSTRUCT(_a(_a&), (any<C, _a>&), (lvalue | id_copy)); |
| 432 | TEST_CONSTRUCT(_a(_a&), (binding<C>, any<C, _a>&), (lvalue | id_copy)); |
| 433 | TEST_CONSTRUCT(_a(_a&), (binding<C>&, any<C, _a>&), (lvalue | id_copy)); |
| 434 | TEST_CONSTRUCT(_a(_a&), (const binding<C>&, any<C, _a>&), (lvalue | id_copy)); |
| 435 | #endif |
| 436 | |
| 437 | TEST_CONSTRUCT(_a(const _a&), (any<C, _a>), (const_lvalue | id_copy)); |
| 438 | TEST_CONSTRUCT(_a(const _a&), (any<C, _a>&), (const_lvalue | id_copy)); |
| 439 | TEST_CONSTRUCT(_a(const _a&), (const any<C, _a>&), (const_lvalue | id_copy)); |
| 440 | TEST_CONSTRUCT(_a(const _a&), (binding<C>, any<C, _a>), (const_lvalue | id_copy)); |
| 441 | TEST_CONSTRUCT(_a(const _a&), (binding<C>, any<C, _a>&), (const_lvalue | id_copy)); |
| 442 | TEST_CONSTRUCT(_a(const _a&), (binding<C>, const any<C, _a>&), (const_lvalue | id_copy)); |
| 443 | TEST_CONSTRUCT(_a(const _a&), (binding<C>&, any<C, _a>), (const_lvalue | id_copy)); |
| 444 | TEST_CONSTRUCT(_a(const _a&), (binding<C>&, any<C, _a>&), (const_lvalue | id_copy)); |
| 445 | TEST_CONSTRUCT(_a(const _a&), (binding<C>&, const any<C, _a>&), (const_lvalue | id_copy)); |
| 446 | TEST_CONSTRUCT(_a(const _a&), (const binding<C>&, any<C, _a>), (const_lvalue | id_copy)); |
| 447 | TEST_CONSTRUCT(_a(const _a&), (const binding<C>&, any<C, _a>&), (const_lvalue | id_copy)); |
| 448 | TEST_CONSTRUCT(_a(const _a&), (const binding<C>&, const any<C, _a>&), (const_lvalue | id_copy)); |
| 449 | |
| 450 | #ifndef BOOST_NO_CXX11_REF_QUALIFIERS |
| 451 | |
| 452 | #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES |
| 453 | TEST_CONSTRUCT(_a(_a&&), (any<C, _a>), (rvalue | id_copy)); |
| 454 | TEST_CONSTRUCT(_a(_a&&), (binding<C>, any<C, _a>), (rvalue | id_copy)); |
| 455 | TEST_CONSTRUCT(_a(_a&&), (binding<C>&, any<C, _a>), (rvalue | id_copy)); |
| 456 | TEST_CONSTRUCT(_a(_a&&), (const binding<C>&, any<C, _a>), (rvalue | id_copy)); |
| 457 | #endif |
| 458 | |
| 459 | #endif |
| 460 | |
| 461 | // test other any type |
| 462 | TEST_CONSTRUCT(_a(_b&), (any<C, _b>&), (lvalue | id_int)); |
| 463 | TEST_CONSTRUCT(_a(_b&), (binding<C>, any<C, _b>&), (lvalue | id_int)); |
| 464 | TEST_CONSTRUCT(_a(_b&), (binding<C>&, any<C, _b>&), (lvalue | id_int)); |
| 465 | TEST_CONSTRUCT(_a(_b&), (const binding<C>&, any<C, _b>&), (lvalue | id_int)); |
| 466 | |
| 467 | TEST_CONSTRUCT(_a(const _b&), (any<C, _b>), (const_lvalue | id_int)); |
| 468 | TEST_CONSTRUCT(_a(const _b&), (any<C, _b>&), (const_lvalue | id_int)); |
| 469 | TEST_CONSTRUCT(_a(const _b&), (const any<C, _b>&), (const_lvalue | id_int)); |
| 470 | TEST_CONSTRUCT(_a(const _b&), (binding<C>, any<C, _b>), (const_lvalue | id_int)); |
| 471 | TEST_CONSTRUCT(_a(const _b&), (binding<C>, any<C, _b>&), (const_lvalue | id_int)); |
| 472 | TEST_CONSTRUCT(_a(const _b&), (binding<C>, const any<C, _b>&), (const_lvalue | id_int)); |
| 473 | TEST_CONSTRUCT(_a(const _b&), (binding<C>&, any<C, _b>), (const_lvalue | id_int)); |
| 474 | TEST_CONSTRUCT(_a(const _b&), (binding<C>&, any<C, _b>&), (const_lvalue | id_int)); |
| 475 | TEST_CONSTRUCT(_a(const _b&), (binding<C>&, const any<C, _b>&), (const_lvalue | id_int)); |
| 476 | TEST_CONSTRUCT(_a(const _b&), (const binding<C>&, any<C, _b>), (const_lvalue | id_int)); |
| 477 | TEST_CONSTRUCT(_a(const _b&), (const binding<C>&, any<C, _b>&), (const_lvalue | id_int)); |
| 478 | TEST_CONSTRUCT(_a(const _b&), (const binding<C>&, const any<C, _b>&), (const_lvalue | id_int)); |
| 479 | |
| 480 | TEST_CONSTRUCT(_a(_b), (any<C, _b>), (rvalue | id_int)); |
| 481 | TEST_CONSTRUCT(_a(_b), (any<C, _b>&), (rvalue | id_int)); |
| 482 | TEST_CONSTRUCT(_a(_b), (const any<C, _b>&), (rvalue | id_int)); |
| 483 | TEST_CONSTRUCT(_a(_b), (binding<C>, any<C, _b>), (rvalue | id_int)); |
| 484 | TEST_CONSTRUCT(_a(_b), (binding<C>, any<C, _b>&), (rvalue | id_int)); |
| 485 | TEST_CONSTRUCT(_a(_b), (binding<C>, const any<C, _b>&), (rvalue | id_int)); |
| 486 | TEST_CONSTRUCT(_a(_b), (binding<C>&, any<C, _b>), (rvalue | id_int)); |
| 487 | TEST_CONSTRUCT(_a(_b), (binding<C>&, any<C, _b>&), (rvalue | id_int)); |
| 488 | TEST_CONSTRUCT(_a(_b), (binding<C>&, const any<C, _b>&), (rvalue | id_int)); |
| 489 | TEST_CONSTRUCT(_a(_b), (const binding<C>&, any<C, _b>), (rvalue | id_int)); |
| 490 | TEST_CONSTRUCT(_a(_b), (const binding<C>&, any<C, _b>&), (rvalue | id_int)); |
| 491 | TEST_CONSTRUCT(_a(_b), (const binding<C>&, const any<C, _b>&), (rvalue | id_int)); |
| 492 | |
| 493 | #ifndef BOOST_NO_CXX11_REF_QUALIFIERS |
| 494 | |
| 495 | #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES |
| 496 | TEST_CONSTRUCT(_a(_b&&), (any<C, _b>), (rvalue | id_int)); |
| 497 | TEST_CONSTRUCT(_a(_b&&), (binding<C>, any<C, _b>), (rvalue | id_int)); |
| 498 | TEST_CONSTRUCT(_a(_b&&), (binding<C>&, any<C, _b>), (rvalue | id_int)); |
| 499 | TEST_CONSTRUCT(_a(_b&&), (const binding<C>&, any<C, _b>), (rvalue | id_int)); |
| 500 | #endif |
| 501 | |
| 502 | #endif |
| 503 | |
| 504 | // test any reference type |
| 505 | TEST_CONSTRUCT(_a(_b&), (any<C, _b&>), (lvalue | id_int)); |
| 506 | TEST_CONSTRUCT(_a(_b&), (any<C, _b&>&), (lvalue | id_int)); |
| 507 | TEST_CONSTRUCT(_a(_b&), (const any<C, _b&>&), (lvalue | id_int)); |
| 508 | TEST_CONSTRUCT(_a(_b&), (binding<C>, any<C, _b&>), (lvalue | id_int)); |
| 509 | TEST_CONSTRUCT(_a(_b&), (binding<C>, any<C, _b&>&), (lvalue | id_int)); |
| 510 | TEST_CONSTRUCT(_a(_b&), (binding<C>, const any<C, _b&>&), (lvalue | id_int)); |
| 511 | TEST_CONSTRUCT(_a(_b&), (binding<C>&, any<C, _b&>), (lvalue | id_int)); |
| 512 | TEST_CONSTRUCT(_a(_b&), (binding<C>&, any<C, _b&>&), (lvalue | id_int)); |
| 513 | TEST_CONSTRUCT(_a(_b&), (binding<C>&, const any<C, _b&>&), (lvalue | id_int)); |
| 514 | TEST_CONSTRUCT(_a(_b&), (const binding<C>&, any<C, _b&>), (lvalue | id_int)); |
| 515 | TEST_CONSTRUCT(_a(_b&), (const binding<C>&, any<C, _b&>&), (lvalue | id_int)); |
| 516 | TEST_CONSTRUCT(_a(_b&), (const binding<C>&, const any<C, _b&>&), (lvalue | id_int)); |
| 517 | |
| 518 | TEST_CONSTRUCT(_a(const _b&), (any<C, _b&>), (const_lvalue | id_int)); |
| 519 | TEST_CONSTRUCT(_a(const _b&), (any<C, _b&>&), (const_lvalue | id_int)); |
| 520 | TEST_CONSTRUCT(_a(const _b&), (const any<C, _b&>&), (const_lvalue | id_int)); |
| 521 | TEST_CONSTRUCT(_a(const _b&), (binding<C>, any<C, _b&>), (const_lvalue | id_int)); |
| 522 | TEST_CONSTRUCT(_a(const _b&), (binding<C>, any<C, _b&>&), (const_lvalue | id_int)); |
| 523 | TEST_CONSTRUCT(_a(const _b&), (binding<C>, const any<C, _b&>&), (const_lvalue | id_int)); |
| 524 | TEST_CONSTRUCT(_a(const _b&), (binding<C>&, any<C, _b&>), (const_lvalue | id_int)); |
| 525 | TEST_CONSTRUCT(_a(const _b&), (binding<C>&, any<C, _b&>&), (const_lvalue | id_int)); |
| 526 | TEST_CONSTRUCT(_a(const _b&), (binding<C>&, const any<C, _b&>&), (const_lvalue | id_int)); |
| 527 | TEST_CONSTRUCT(_a(const _b&), (const binding<C>&, any<C, _b&>), (const_lvalue | id_int)); |
| 528 | TEST_CONSTRUCT(_a(const _b&), (const binding<C>&, any<C, _b&>&), (const_lvalue | id_int)); |
| 529 | TEST_CONSTRUCT(_a(const _b&), (const binding<C>&, const any<C, _b&>&), (const_lvalue | id_int)); |
| 530 | |
| 531 | TEST_CONSTRUCT(_a(_b), (any<C, _b&>), (rvalue | id_int)); |
| 532 | TEST_CONSTRUCT(_a(_b), (any<C, _b&>&), (rvalue | id_int)); |
| 533 | TEST_CONSTRUCT(_a(_b), (const any<C, _b&>&), (rvalue | id_int)); |
| 534 | TEST_CONSTRUCT(_a(_b), (binding<C>, any<C, _b&>), (rvalue | id_int)); |
| 535 | TEST_CONSTRUCT(_a(_b), (binding<C>, any<C, _b&>&), (rvalue | id_int)); |
| 536 | TEST_CONSTRUCT(_a(_b), (binding<C>, const any<C, _b&>&), (rvalue | id_int)); |
| 537 | TEST_CONSTRUCT(_a(_b), (binding<C>&, any<C, _b&>), (rvalue | id_int)); |
| 538 | TEST_CONSTRUCT(_a(_b), (binding<C>&, any<C, _b&>&), (rvalue | id_int)); |
| 539 | TEST_CONSTRUCT(_a(_b), (binding<C>&, const any<C, _b&>&), (rvalue | id_int)); |
| 540 | TEST_CONSTRUCT(_a(_b), (const binding<C>&, any<C, _b&>), (rvalue | id_int)); |
| 541 | TEST_CONSTRUCT(_a(_b), (const binding<C>&, any<C, _b&>&), (rvalue | id_int)); |
| 542 | TEST_CONSTRUCT(_a(_b), (const binding<C>&, const any<C, _b&>&), (rvalue | id_int)); |
| 543 | |
| 544 | // test const any reference type |
| 545 | TEST_CONSTRUCT(_a(const _b&), (any<C, const _b&>), (const_lvalue | id_int)); |
| 546 | TEST_CONSTRUCT(_a(const _b&), (any<C, const _b&>&), (const_lvalue | id_int)); |
| 547 | TEST_CONSTRUCT(_a(const _b&), (const any<C, const _b&>&), (const_lvalue | id_int)); |
| 548 | TEST_CONSTRUCT(_a(const _b&), (binding<C>, any<C, const _b&>), (const_lvalue | id_int)); |
| 549 | TEST_CONSTRUCT(_a(const _b&), (binding<C>, any<C, const _b&>&), (const_lvalue | id_int)); |
| 550 | TEST_CONSTRUCT(_a(const _b&), (binding<C>, const any<C, const _b&>&), (const_lvalue | id_int)); |
| 551 | TEST_CONSTRUCT(_a(const _b&), (binding<C>&, any<C, const _b&>), (const_lvalue | id_int)); |
| 552 | TEST_CONSTRUCT(_a(const _b&), (binding<C>&, any<C, const _b&>&), (const_lvalue | id_int)); |
| 553 | TEST_CONSTRUCT(_a(const _b&), (binding<C>&, const any<C, const _b&>&), (const_lvalue | id_int)); |
| 554 | TEST_CONSTRUCT(_a(const _b&), (const binding<C>&, any<C, const _b&>), (const_lvalue | id_int)); |
| 555 | TEST_CONSTRUCT(_a(const _b&), (const binding<C>&, any<C, const _b&>&), (const_lvalue | id_int)); |
| 556 | TEST_CONSTRUCT(_a(const _b&), (const binding<C>&, const any<C, const _b&>&), (const_lvalue | id_int)); |
| 557 | |
| 558 | TEST_CONSTRUCT(_a(_b), (any<C, const _b&>), (rvalue | id_int)); |
| 559 | TEST_CONSTRUCT(_a(_b), (any<C, const _b&>&), (rvalue | id_int)); |
| 560 | TEST_CONSTRUCT(_a(_b), (const any<C, const _b&>&), (rvalue | id_int)); |
| 561 | TEST_CONSTRUCT(_a(_b), (binding<C>, any<C, const _b&>), (rvalue | id_int)); |
| 562 | TEST_CONSTRUCT(_a(_b), (binding<C>, any<C, const _b&>&), (rvalue | id_int)); |
| 563 | TEST_CONSTRUCT(_a(_b), (binding<C>, const any<C, const _b&>&), (rvalue | id_int)); |
| 564 | TEST_CONSTRUCT(_a(_b), (binding<C>&, any<C, const _b&>), (rvalue | id_int)); |
| 565 | TEST_CONSTRUCT(_a(_b), (binding<C>&, any<C, const _b&>&), (rvalue | id_int)); |
| 566 | TEST_CONSTRUCT(_a(_b), (binding<C>&, const any<C, const _b&>&), (rvalue | id_int)); |
| 567 | TEST_CONSTRUCT(_a(_b), (const binding<C>&, any<C, const _b&>), (rvalue | id_int)); |
| 568 | TEST_CONSTRUCT(_a(_b), (const binding<C>&, any<C, const _b&>&), (rvalue | id_int)); |
| 569 | TEST_CONSTRUCT(_a(_b), (const binding<C>&, const any<C, const _b&>&), (rvalue | id_int)); |
| 570 | |
| 571 | #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES |
| 572 | |
| 573 | // test any rvalue reference type |
| 574 | TEST_CONSTRUCT(_a(const _b&), (any<C, _b&&>), (const_lvalue | id_int)); |
| 575 | TEST_CONSTRUCT(_a(const _b&), (any<C, _b&&>&), (const_lvalue | id_int)); |
| 576 | TEST_CONSTRUCT(_a(const _b&), (const any<C, _b&&>&), (const_lvalue | id_int)); |
| 577 | TEST_CONSTRUCT(_a(const _b&), (binding<C>, any<C, _b&&>), (const_lvalue | id_int)); |
| 578 | TEST_CONSTRUCT(_a(const _b&), (binding<C>, any<C, _b&&>&), (const_lvalue | id_int)); |
| 579 | TEST_CONSTRUCT(_a(const _b&), (binding<C>, const any<C, _b&&>&), (const_lvalue | id_int)); |
| 580 | TEST_CONSTRUCT(_a(const _b&), (binding<C>&, any<C, _b&&>), (const_lvalue | id_int)); |
| 581 | TEST_CONSTRUCT(_a(const _b&), (binding<C>&, any<C, _b&&>&), (const_lvalue | id_int)); |
| 582 | TEST_CONSTRUCT(_a(const _b&), (binding<C>&, const any<C, _b&&>&), (const_lvalue | id_int)); |
| 583 | TEST_CONSTRUCT(_a(const _b&), (const binding<C>&, any<C, _b&&>), (const_lvalue | id_int)); |
| 584 | TEST_CONSTRUCT(_a(const _b&), (const binding<C>&, any<C, _b&&>&), (const_lvalue | id_int)); |
| 585 | TEST_CONSTRUCT(_a(const _b&), (const binding<C>&, const any<C, _b&&>&), (const_lvalue | id_int)); |
| 586 | |
| 587 | TEST_CONSTRUCT(_a(_b), (any<C, _b&&>), (rvalue | id_int)); |
| 588 | TEST_CONSTRUCT(_a(_b), (any<C, _b&&>&), (rvalue | id_int)); |
| 589 | TEST_CONSTRUCT(_a(_b), (const any<C, _b&&>&), (rvalue | id_int)); |
| 590 | TEST_CONSTRUCT(_a(_b), (binding<C>, any<C, _b&&>), (rvalue | id_int)); |
| 591 | TEST_CONSTRUCT(_a(_b), (binding<C>, any<C, _b&&>&), (rvalue | id_int)); |
| 592 | TEST_CONSTRUCT(_a(_b), (binding<C>, const any<C, _b&&>&), (rvalue | id_int)); |
| 593 | TEST_CONSTRUCT(_a(_b), (binding<C>&, any<C, _b&&>), (rvalue | id_int)); |
| 594 | TEST_CONSTRUCT(_a(_b), (binding<C>&, any<C, _b&&>&), (rvalue | id_int)); |
| 595 | TEST_CONSTRUCT(_a(_b), (binding<C>&, const any<C, _b&&>&), (rvalue | id_int)); |
| 596 | TEST_CONSTRUCT(_a(_b), (const binding<C>&, any<C, _b&&>), (rvalue | id_int)); |
| 597 | TEST_CONSTRUCT(_a(_b), (const binding<C>&, any<C, _b&&>&), (rvalue | id_int)); |
| 598 | TEST_CONSTRUCT(_a(_b), (const binding<C>&, const any<C, _b&&>&), (rvalue | id_int)); |
| 599 | |
| 600 | TEST_CONSTRUCT(_a(_b&&), (any<C, _b&&>), (rvalue | id_int)); |
| 601 | TEST_CONSTRUCT(_a(_b&&), (any<C, _b&&>&), (rvalue | id_int)); |
| 602 | TEST_CONSTRUCT(_a(_b&&), (const any<C, _b&&>&), (rvalue | id_int)); |
| 603 | TEST_CONSTRUCT(_a(_b&&), (binding<C>, any<C, _b&&>), (rvalue | id_int)); |
| 604 | TEST_CONSTRUCT(_a(_b&&), (binding<C>, any<C, _b&&>&), (rvalue | id_int)); |
| 605 | TEST_CONSTRUCT(_a(_b&&), (binding<C>, const any<C, _b&&>&), (rvalue | id_int)); |
| 606 | TEST_CONSTRUCT(_a(_b&&), (binding<C>&, any<C, _b&&>), (rvalue | id_int)); |
| 607 | TEST_CONSTRUCT(_a(_b&&), (binding<C>&, any<C, _b&&>&), (rvalue | id_int)); |
| 608 | TEST_CONSTRUCT(_a(_b&&), (binding<C>&, const any<C, _b&&>&), (rvalue | id_int)); |
| 609 | TEST_CONSTRUCT(_a(_b&&), (const binding<C>&, any<C, _b&&>), (rvalue | id_int)); |
| 610 | TEST_CONSTRUCT(_a(_b&&), (const binding<C>&, any<C, _b&&>&), (rvalue | id_int)); |
| 611 | TEST_CONSTRUCT(_a(_b&&), (const binding<C>&, const any<C, _b&&>&), (rvalue | id_int)); |
| 612 | |
| 613 | #endif |
| 614 | |
| 615 | } |
| 616 | |
| 617 | // test constructors with 2 parameters |
| 618 | BOOST_AUTO_TEST_CASE_TEMPLATE(test_construct2, extra, maybe_relaxed) |
| 619 | { |
| 620 | TEST_CONSTRUCT(_a(int, int), (binding<C>, int, int), (rvalue | id_int, rvalue | id_int)); |
| 621 | TEST_CONSTRUCT(_a(int, int), (binding<C>, int, int&), (rvalue | id_int, rvalue | id_int)); |
| 622 | TEST_CONSTRUCT(_a(int, int), (binding<C>, int, const int&), (rvalue | id_int, rvalue | id_int)); |
| 623 | TEST_CONSTRUCT(_a(int, int), (binding<C>, int&, int), (rvalue | id_int, rvalue | id_int)); |
| 624 | TEST_CONSTRUCT(_a(int, int), (binding<C>, int&, int&), (rvalue | id_int, rvalue | id_int)); |
| 625 | TEST_CONSTRUCT(_a(int, int), (binding<C>, int&, const int&), (rvalue | id_int, rvalue | id_int)); |
| 626 | TEST_CONSTRUCT(_a(int, int), (binding<C>, const int&, int), (rvalue | id_int, rvalue | id_int)); |
| 627 | TEST_CONSTRUCT(_a(int, int), (binding<C>, const int&, int&), (rvalue | id_int, rvalue | id_int)); |
| 628 | TEST_CONSTRUCT(_a(int, int), (binding<C>, const int&, const int&), (rvalue | id_int, rvalue | id_int)); |
| 629 | TEST_CONSTRUCT(_a(int, int), (binding<C>&, int, int), (rvalue | id_int, rvalue | id_int)); |
| 630 | TEST_CONSTRUCT(_a(int, int), (binding<C>&, int, int&), (rvalue | id_int, rvalue | id_int)); |
| 631 | TEST_CONSTRUCT(_a(int, int), (binding<C>&, int, const int&), (rvalue | id_int, rvalue | id_int)); |
| 632 | TEST_CONSTRUCT(_a(int, int), (binding<C>&, int&, int), (rvalue | id_int, rvalue | id_int)); |
| 633 | TEST_CONSTRUCT(_a(int, int), (binding<C>&, int&, int&), (rvalue | id_int, rvalue | id_int)); |
| 634 | TEST_CONSTRUCT(_a(int, int), (binding<C>&, int&, const int&), (rvalue | id_int, rvalue | id_int)); |
| 635 | TEST_CONSTRUCT(_a(int, int), (binding<C>&, const int&, int), (rvalue | id_int, rvalue | id_int)); |
| 636 | TEST_CONSTRUCT(_a(int, int), (binding<C>&, const int&, int&), (rvalue | id_int, rvalue | id_int)); |
| 637 | TEST_CONSTRUCT(_a(int, int), (binding<C>&, const int&, const int&), (rvalue | id_int, rvalue | id_int)); |
| 638 | TEST_CONSTRUCT(_a(int, int), (const binding<C>&, int, int), (rvalue | id_int, rvalue | id_int)); |
| 639 | TEST_CONSTRUCT(_a(int, int), (const binding<C>&, int, int&), (rvalue | id_int, rvalue | id_int)); |
| 640 | TEST_CONSTRUCT(_a(int, int), (const binding<C>&, int, const int&), (rvalue | id_int, rvalue | id_int)); |
| 641 | TEST_CONSTRUCT(_a(int, int), (const binding<C>&, int&, int), (rvalue | id_int, rvalue | id_int)); |
| 642 | TEST_CONSTRUCT(_a(int, int), (const binding<C>&, int&, int&), (rvalue | id_int, rvalue | id_int)); |
| 643 | TEST_CONSTRUCT(_a(int, int), (const binding<C>&, int&, const int&), (rvalue | id_int, rvalue | id_int)); |
| 644 | TEST_CONSTRUCT(_a(int, int), (const binding<C>&, const int&, int), (rvalue | id_int, rvalue | id_int)); |
| 645 | TEST_CONSTRUCT(_a(int, int), (const binding<C>&, const int&, int&), (rvalue | id_int, rvalue | id_int)); |
| 646 | TEST_CONSTRUCT(_a(int, int), (const binding<C>&, const int&, const int&), (rvalue | id_int, rvalue | id_int)); |
| 647 | } |
| 648 | |
| 649 | BOOST_AUTO_TEST_CASE(test_overload) |
| 650 | { |
| 651 | typedef ::boost::mpl::vector< |
| 652 | common<_a>, |
| 653 | common<_b>, |
| 654 | constructible<_a(_b)>, |
| 655 | constructible<_a(std::size_t)> |
| 656 | > test_concept; |
| 657 | typedef ::boost::mpl::map< |
| 658 | ::boost::mpl::pair<_a, std::vector<int> >, |
| 659 | ::boost::mpl::pair<_b, std::size_t> |
| 660 | > types; |
| 661 | binding<test_concept> table = make_binding<types>(); |
| 662 | any<test_concept, _b> x(static_cast<std::size_t>(10), make_binding<types>()); |
| 663 | any<test_concept, _a> y(x); |
| 664 | any<test_concept, _a> z(table, 17); |
| 665 | std::vector<int> vec1(any_cast<std::vector<int> >(arg&: y)); |
| 666 | BOOST_CHECK_EQUAL(vec1.size(), 10u); |
| 667 | std::vector<int> vec2(any_cast<std::vector<int> >(arg&: z)); |
| 668 | BOOST_CHECK_EQUAL(vec2.size(), 17u); |
| 669 | } |
| 670 | |
| 671 | template<class T> |
| 672 | T as_rvalue(const T& arg) { return arg; } |
| 673 | template<class T> |
| 674 | const T& as_const(const T& arg) { return arg; } |
| 675 | |
| 676 | BOOST_AUTO_TEST_CASE(test_from_int_with_binding) |
| 677 | { |
| 678 | typedef ::boost::mpl::vector<common<> > test_concept; |
| 679 | static_binding<boost::mpl::map<boost::mpl::pair<_self, int> > > binding = |
| 680 | make_binding<boost::mpl::map<boost::mpl::pair<_self, int> > >(); |
| 681 | int value = 4; |
| 682 | |
| 683 | any<test_concept> x1(value, binding); |
| 684 | BOOST_CHECK_EQUAL(any_cast<int>(x1), 4); |
| 685 | any<test_concept> x2(value, as_rvalue(arg: binding)); |
| 686 | BOOST_CHECK_EQUAL(any_cast<int>(x2), 4); |
| 687 | any<test_concept> x3(value, as_const(arg: binding)); |
| 688 | BOOST_CHECK_EQUAL(any_cast<int>(x3), 4); |
| 689 | |
| 690 | any<test_concept> y1(as_rvalue(arg: value), binding); |
| 691 | BOOST_CHECK_EQUAL(any_cast<int>(y1), 4); |
| 692 | any<test_concept> y2(as_rvalue(arg: value), as_rvalue(arg: binding)); |
| 693 | BOOST_CHECK_EQUAL(any_cast<int>(y2), 4); |
| 694 | any<test_concept> y3(as_rvalue(arg: value), as_const(arg: binding)); |
| 695 | BOOST_CHECK_EQUAL(any_cast<int>(y3), 4); |
| 696 | |
| 697 | any<test_concept> z1(as_const(arg: value), binding); |
| 698 | BOOST_CHECK_EQUAL(any_cast<int>(z1), 4); |
| 699 | any<test_concept> z2(as_const(arg: value), as_rvalue(arg: binding)); |
| 700 | BOOST_CHECK_EQUAL(any_cast<int>(z2), 4); |
| 701 | any<test_concept> z3(as_const(arg: value), as_const(arg: binding)); |
| 702 | BOOST_CHECK_EQUAL(any_cast<int>(z3), 4); |
| 703 | } |
| 704 | |
| 705 | BOOST_AUTO_TEST_CASE(test_copy) |
| 706 | { |
| 707 | typedef ::boost::mpl::vector<common<> > test_concept; |
| 708 | any<test_concept> x(4); |
| 709 | BOOST_CHECK_EQUAL(any_cast<int>(x), 4); |
| 710 | any<test_concept> y(x); |
| 711 | BOOST_CHECK_EQUAL(any_cast<int>(y), 4); |
| 712 | any<test_concept> z(as_rvalue(arg: x)); |
| 713 | BOOST_CHECK_EQUAL(any_cast<int>(z), 4); |
| 714 | any<test_concept> w(as_const(arg: x)); |
| 715 | BOOST_CHECK_EQUAL(any_cast<int>(w), 4); |
| 716 | } |
| 717 | |
| 718 | BOOST_AUTO_TEST_CASE(test_copy_implicit) |
| 719 | { |
| 720 | typedef ::boost::mpl::vector<common<>, common<_a> > test_concept; |
| 721 | any<test_concept> x(4, make_binding< ::boost::mpl::map< ::boost::mpl::pair<_self, int>, ::boost::mpl::pair<_a, int> > >()); |
| 722 | BOOST_CHECK_EQUAL(any_cast<int>(x), 4); |
| 723 | |
| 724 | any<test_concept> y = x; |
| 725 | BOOST_CHECK_EQUAL(any_cast<int>(y), 4); |
| 726 | any<test_concept> z = as_rvalue(arg: x); |
| 727 | BOOST_CHECK_EQUAL(any_cast<int>(z), 4); |
| 728 | any<test_concept> w = as_const(arg: x); |
| 729 | BOOST_CHECK_EQUAL(any_cast<int>(w), 4); |
| 730 | } |
| 731 | |
| 732 | BOOST_AUTO_TEST_CASE(test_convert) |
| 733 | { |
| 734 | typedef ::boost::mpl::vector<common<>, incrementable<> > src_concept; |
| 735 | typedef ::boost::mpl::vector<common<> > dst_concept; |
| 736 | any<src_concept> x(4); |
| 737 | BOOST_CHECK_EQUAL(any_cast<int>(x), 4); |
| 738 | any<dst_concept> y(x); |
| 739 | BOOST_CHECK_EQUAL(any_cast<int>(y), 4); |
| 740 | any<dst_concept> z = as_rvalue(arg: x); |
| 741 | BOOST_CHECK_EQUAL(any_cast<int>(z), 4); |
| 742 | any<dst_concept> w = as_const(arg: x); |
| 743 | BOOST_CHECK_EQUAL(any_cast<int>(w), 4); |
| 744 | } |
| 745 | |
| 746 | BOOST_AUTO_TEST_CASE(test_rebind) |
| 747 | { |
| 748 | typedef ::boost::mpl::vector<common<> > src_concept; |
| 749 | typedef ::boost::mpl::vector<common<_a> > dst_concept; |
| 750 | any<src_concept> x(4); |
| 751 | BOOST_CHECK_EQUAL(any_cast<int>(x), 4); |
| 752 | any<dst_concept, _a> y = x; |
| 753 | BOOST_CHECK_EQUAL(any_cast<int>(y), 4); |
| 754 | any<dst_concept, _a> z = as_rvalue(arg: x); |
| 755 | BOOST_CHECK_EQUAL(any_cast<int>(z), 4); |
| 756 | any<dst_concept, _a> w = as_const(arg: x); |
| 757 | BOOST_CHECK_EQUAL(any_cast<int>(w), 4); |
| 758 | } |
| 759 | |
| 760 | BOOST_AUTO_TEST_CASE(test_rebind_and_convert) |
| 761 | { |
| 762 | typedef ::boost::mpl::vector<common<>, incrementable<> > src_concept; |
| 763 | typedef ::boost::mpl::vector<common<_a> > dst_concept; |
| 764 | any<src_concept> x(4); |
| 765 | BOOST_CHECK_EQUAL(any_cast<int>(x), 4); |
| 766 | any<dst_concept, _a> y(x); |
| 767 | BOOST_CHECK_EQUAL(any_cast<int>(y), 4); |
| 768 | any<dst_concept, _a> z = as_rvalue(arg: x); |
| 769 | BOOST_CHECK_EQUAL(any_cast<int>(z), 4); |
| 770 | any<dst_concept, _a> w = as_const(arg: x); |
| 771 | BOOST_CHECK_EQUAL(any_cast<int>(w), 4); |
| 772 | } |
| 773 | |
| 774 | BOOST_AUTO_TEST_CASE(test_rebind_and_convert_with_binding) |
| 775 | { |
| 776 | typedef ::boost::mpl::vector<common<>, incrementable<> > src_concept; |
| 777 | typedef ::boost::mpl::vector<common<_a> > dst_concept; |
| 778 | typedef ::boost::mpl::map<boost::mpl::pair<_a, _self> > map; |
| 779 | typedef ::boost::mpl::map<boost::mpl::pair<_a, int> > types; |
| 780 | |
| 781 | static_binding<map> s_table(make_binding<map>()); |
| 782 | binding<dst_concept> table(make_binding<types>()); |
| 783 | |
| 784 | any<src_concept> x(4); |
| 785 | BOOST_CHECK_EQUAL(any_cast<int>(x), 4); |
| 786 | |
| 787 | // lvalues |
| 788 | any<dst_concept, _a> y1(x, s_table); |
| 789 | BOOST_CHECK_EQUAL(any_cast<int>(y1), 4); |
| 790 | any<dst_concept, _a> y2(x, as_rvalue(arg: s_table)); |
| 791 | BOOST_CHECK_EQUAL(any_cast<int>(y2), 4); |
| 792 | any<dst_concept, _a> y3(x, as_const(arg: s_table)); |
| 793 | BOOST_CHECK_EQUAL(any_cast<int>(y3), 4); |
| 794 | any<dst_concept, _a> z1(x, table); |
| 795 | BOOST_CHECK_EQUAL(any_cast<int>(z1), 4); |
| 796 | any<dst_concept, _a> z2(x, as_rvalue(arg: table)); |
| 797 | BOOST_CHECK_EQUAL(any_cast<int>(z2), 4); |
| 798 | any<dst_concept, _a> z3(x, as_const(arg: table)); |
| 799 | BOOST_CHECK_EQUAL(any_cast<int>(z3), 4); |
| 800 | |
| 801 | // rvalues |
| 802 | any<dst_concept, _a> ry1(as_rvalue(arg: x), s_table); |
| 803 | BOOST_CHECK_EQUAL(any_cast<int>(ry1), 4); |
| 804 | any<dst_concept, _a> ry2(as_rvalue(arg: x), as_rvalue(arg: s_table)); |
| 805 | BOOST_CHECK_EQUAL(any_cast<int>(ry2), 4); |
| 806 | any<dst_concept, _a> ry3(as_rvalue(arg: x), as_const(arg: s_table)); |
| 807 | BOOST_CHECK_EQUAL(any_cast<int>(ry3), 4); |
| 808 | any<dst_concept, _a> rz1(as_rvalue(arg: x), table); |
| 809 | BOOST_CHECK_EQUAL(any_cast<int>(rz1), 4); |
| 810 | any<dst_concept, _a> rz2(as_rvalue(arg: x), as_rvalue(arg: table)); |
| 811 | BOOST_CHECK_EQUAL(any_cast<int>(rz2), 4); |
| 812 | any<dst_concept, _a> rz3(as_rvalue(arg: x), as_rvalue(arg: table)); |
| 813 | BOOST_CHECK_EQUAL(any_cast<int>(rz3), 4); |
| 814 | |
| 815 | // const lvalues |
| 816 | any<dst_concept, _a> cy1(as_const(arg: x), s_table); |
| 817 | BOOST_CHECK_EQUAL(any_cast<int>(cy1), 4); |
| 818 | any<dst_concept, _a> cy2(as_const(arg: x), as_rvalue(arg: s_table)); |
| 819 | BOOST_CHECK_EQUAL(any_cast<int>(cy2), 4); |
| 820 | any<dst_concept, _a> cy3(as_const(arg: x), as_const(arg: s_table)); |
| 821 | BOOST_CHECK_EQUAL(any_cast<int>(cy3), 4); |
| 822 | any<dst_concept, _a> cz1(as_const(arg: x), table); |
| 823 | BOOST_CHECK_EQUAL(any_cast<int>(cz1), 4); |
| 824 | any<dst_concept, _a> cz2(as_const(arg: x), as_rvalue(arg: table)); |
| 825 | BOOST_CHECK_EQUAL(any_cast<int>(cz2), 4); |
| 826 | any<dst_concept, _a> cz3(as_const(arg: x), as_rvalue(arg: table)); |
| 827 | BOOST_CHECK_EQUAL(any_cast<int>(cz3), 4); |
| 828 | } |
| 829 | |
| 830 | BOOST_AUTO_TEST_CASE(test_copy_from_ref) |
| 831 | { |
| 832 | typedef ::boost::mpl::vector<common<> > test_concept; |
| 833 | int i = 4; |
| 834 | any<test_concept, _self&> x(i); |
| 835 | BOOST_CHECK_EQUAL(any_cast<int>(x), 4); |
| 836 | any<test_concept> y(x); |
| 837 | BOOST_CHECK_EQUAL(any_cast<int>(y), 4); |
| 838 | any<test_concept> z = as_rvalue(arg: x); |
| 839 | BOOST_CHECK_EQUAL(any_cast<int>(z), 4); |
| 840 | any<test_concept> w = as_const(arg: x); |
| 841 | BOOST_CHECK_EQUAL(any_cast<int>(w), 4); |
| 842 | } |
| 843 | |
| 844 | BOOST_AUTO_TEST_CASE(test_convert_from_ref) |
| 845 | { |
| 846 | typedef ::boost::mpl::vector<common<>, incrementable<> > src_concept; |
| 847 | typedef ::boost::mpl::vector<common<> > dst_concept; |
| 848 | int i = 4; |
| 849 | any<src_concept, _self&> x(i); |
| 850 | BOOST_CHECK_EQUAL(any_cast<int>(x), 4); |
| 851 | any<dst_concept> y(x); |
| 852 | BOOST_CHECK_EQUAL(any_cast<int>(y), 4); |
| 853 | any<dst_concept> z = as_rvalue(arg: x); |
| 854 | BOOST_CHECK_EQUAL(any_cast<int>(z), 4); |
| 855 | any<dst_concept> w = as_const(arg: x); |
| 856 | BOOST_CHECK_EQUAL(any_cast<int>(w), 4); |
| 857 | } |
| 858 | |
| 859 | BOOST_AUTO_TEST_CASE(test_rebind_from_ref) |
| 860 | { |
| 861 | typedef ::boost::mpl::vector<common<> > src_concept; |
| 862 | typedef ::boost::mpl::vector<common<_a> > dst_concept; |
| 863 | int i = 4; |
| 864 | any<src_concept, _self&> x(i); |
| 865 | BOOST_CHECK_EQUAL(any_cast<int>(x), 4); |
| 866 | any<dst_concept, _a> y(x); |
| 867 | BOOST_CHECK_EQUAL(any_cast<int>(y), 4); |
| 868 | any<dst_concept, _a> z = as_rvalue(arg: x); |
| 869 | BOOST_CHECK_EQUAL(any_cast<int>(z), 4); |
| 870 | any<dst_concept, _a> w = as_const(arg: x); |
| 871 | BOOST_CHECK_EQUAL(any_cast<int>(w), 4); |
| 872 | } |
| 873 | |
| 874 | BOOST_AUTO_TEST_CASE(test_rebind_and_convert_from_ref) |
| 875 | { |
| 876 | typedef ::boost::mpl::vector<common<>, incrementable<> > src_concept; |
| 877 | typedef ::boost::mpl::vector<common<_a> > dst_concept; |
| 878 | int i = 4; |
| 879 | any<src_concept, _self&> x(i); |
| 880 | BOOST_CHECK_EQUAL(any_cast<int>(x), 4); |
| 881 | any<dst_concept, _a> y(x); |
| 882 | BOOST_CHECK_EQUAL(any_cast<int>(y), 4); |
| 883 | any<dst_concept, _a> z = as_rvalue(arg: x); |
| 884 | BOOST_CHECK_EQUAL(any_cast<int>(z), 4); |
| 885 | any<dst_concept, _a> w = as_const(arg: x); |
| 886 | BOOST_CHECK_EQUAL(any_cast<int>(w), 4); |
| 887 | } |
| 888 | |
| 889 | BOOST_AUTO_TEST_CASE(test_rebind_and_convert_with_binding_from_ref) |
| 890 | { |
| 891 | typedef ::boost::mpl::vector<common<>, incrementable<> > src_concept; |
| 892 | typedef ::boost::mpl::vector<common<_a> > dst_concept; |
| 893 | typedef ::boost::mpl::map<boost::mpl::pair<_a, _self> > map; |
| 894 | typedef ::boost::mpl::map<boost::mpl::pair<_a, int> > types; |
| 895 | |
| 896 | static_binding<map> s_table(make_binding<map>()); |
| 897 | binding<dst_concept> table(make_binding<types>()); |
| 898 | |
| 899 | int i = 4; |
| 900 | any<src_concept, _self&> x(i); |
| 901 | BOOST_CHECK_EQUAL(any_cast<int>(x), 4); |
| 902 | |
| 903 | // lvalues |
| 904 | any<dst_concept, _a> y1(x, s_table); |
| 905 | BOOST_CHECK_EQUAL(any_cast<int>(y1), 4); |
| 906 | any<dst_concept, _a> y2(x, as_rvalue(arg: s_table)); |
| 907 | BOOST_CHECK_EQUAL(any_cast<int>(y2), 4); |
| 908 | any<dst_concept, _a> y3(x, as_const(arg: s_table)); |
| 909 | BOOST_CHECK_EQUAL(any_cast<int>(y3), 4); |
| 910 | any<dst_concept, _a> z1(x, table); |
| 911 | BOOST_CHECK_EQUAL(any_cast<int>(z1), 4); |
| 912 | any<dst_concept, _a> z2(x, as_rvalue(arg: table)); |
| 913 | BOOST_CHECK_EQUAL(any_cast<int>(z2), 4); |
| 914 | any<dst_concept, _a> z3(x, as_const(arg: table)); |
| 915 | BOOST_CHECK_EQUAL(any_cast<int>(z3), 4); |
| 916 | |
| 917 | // rvalues |
| 918 | any<dst_concept, _a> ry1(as_rvalue(arg: x), s_table); |
| 919 | BOOST_CHECK_EQUAL(any_cast<int>(ry1), 4); |
| 920 | any<dst_concept, _a> ry2(as_rvalue(arg: x), as_rvalue(arg: s_table)); |
| 921 | BOOST_CHECK_EQUAL(any_cast<int>(ry2), 4); |
| 922 | any<dst_concept, _a> ry3(as_rvalue(arg: x), as_const(arg: s_table)); |
| 923 | BOOST_CHECK_EQUAL(any_cast<int>(ry3), 4); |
| 924 | any<dst_concept, _a> rz1(as_rvalue(arg: x), table); |
| 925 | BOOST_CHECK_EQUAL(any_cast<int>(rz1), 4); |
| 926 | any<dst_concept, _a> rz2(as_rvalue(arg: x), as_rvalue(arg: table)); |
| 927 | BOOST_CHECK_EQUAL(any_cast<int>(rz2), 4); |
| 928 | any<dst_concept, _a> rz3(as_rvalue(arg: x), as_rvalue(arg: table)); |
| 929 | BOOST_CHECK_EQUAL(any_cast<int>(rz3), 4); |
| 930 | |
| 931 | // const lvalues |
| 932 | any<dst_concept, _a> cy1(as_const(arg: x), s_table); |
| 933 | BOOST_CHECK_EQUAL(any_cast<int>(cy1), 4); |
| 934 | any<dst_concept, _a> cy2(as_const(arg: x), as_rvalue(arg: s_table)); |
| 935 | BOOST_CHECK_EQUAL(any_cast<int>(cy2), 4); |
| 936 | any<dst_concept, _a> cy3(as_const(arg: x), as_const(arg: s_table)); |
| 937 | BOOST_CHECK_EQUAL(any_cast<int>(cy3), 4); |
| 938 | any<dst_concept, _a> cz1(as_const(arg: x), table); |
| 939 | BOOST_CHECK_EQUAL(any_cast<int>(cz1), 4); |
| 940 | any<dst_concept, _a> cz2(as_const(arg: x), as_rvalue(arg: table)); |
| 941 | BOOST_CHECK_EQUAL(any_cast<int>(cz2), 4); |
| 942 | any<dst_concept, _a> cz3(as_const(arg: x), as_rvalue(arg: table)); |
| 943 | BOOST_CHECK_EQUAL(any_cast<int>(cz3), 4); |
| 944 | } |
| 945 | |
| 946 | BOOST_AUTO_TEST_CASE(test_copy_from_cref) |
| 947 | { |
| 948 | typedef ::boost::mpl::vector<common<> > test_concept; |
| 949 | int i = 4; |
| 950 | any<test_concept, const _self&> x(i); |
| 951 | BOOST_CHECK_EQUAL(any_cast<int>(x), 4); |
| 952 | any<test_concept> y(x); |
| 953 | BOOST_CHECK_EQUAL(any_cast<int>(y), 4); |
| 954 | any<test_concept> z = as_rvalue(arg: x); |
| 955 | BOOST_CHECK_EQUAL(any_cast<int>(z), 4); |
| 956 | any<test_concept> w = as_const(arg: x); |
| 957 | BOOST_CHECK_EQUAL(any_cast<int>(w), 4); |
| 958 | } |
| 959 | |
| 960 | BOOST_AUTO_TEST_CASE(test_convert_from_cref) |
| 961 | { |
| 962 | typedef ::boost::mpl::vector<common<>, incrementable<> > src_concept; |
| 963 | typedef ::boost::mpl::vector<common<> > dst_concept; |
| 964 | int i = 4; |
| 965 | any<src_concept, const _self&> x(i); |
| 966 | BOOST_CHECK_EQUAL(any_cast<int>(x), 4); |
| 967 | any<dst_concept> y(x); |
| 968 | BOOST_CHECK_EQUAL(any_cast<int>(y), 4); |
| 969 | any<dst_concept> z = as_rvalue(arg: x); |
| 970 | BOOST_CHECK_EQUAL(any_cast<int>(z), 4); |
| 971 | any<dst_concept> w = as_const(arg: x); |
| 972 | BOOST_CHECK_EQUAL(any_cast<int>(w), 4); |
| 973 | } |
| 974 | |
| 975 | BOOST_AUTO_TEST_CASE(test_rebind_from_cref) |
| 976 | { |
| 977 | typedef ::boost::mpl::vector<common<> > src_concept; |
| 978 | typedef ::boost::mpl::vector<common<_a> > dst_concept; |
| 979 | int i = 4; |
| 980 | any<src_concept, const _self&> x(i); |
| 981 | BOOST_CHECK_EQUAL(any_cast<int>(x), 4); |
| 982 | any<dst_concept, _a> y(x); |
| 983 | BOOST_CHECK_EQUAL(any_cast<int>(y), 4); |
| 984 | any<dst_concept, _a> z = as_rvalue(arg: x); |
| 985 | BOOST_CHECK_EQUAL(any_cast<int>(z), 4); |
| 986 | any<dst_concept, _a> w = as_const(arg: x); |
| 987 | BOOST_CHECK_EQUAL(any_cast<int>(w), 4); |
| 988 | } |
| 989 | |
| 990 | BOOST_AUTO_TEST_CASE(test_rebind_and_convert_from_cref) |
| 991 | { |
| 992 | typedef ::boost::mpl::vector<common<>, incrementable<> > src_concept; |
| 993 | typedef ::boost::mpl::vector<common<_a> > dst_concept; |
| 994 | int i = 4; |
| 995 | any<src_concept, const _self&> x(i); |
| 996 | BOOST_CHECK_EQUAL(any_cast<int>(x), 4); |
| 997 | any<dst_concept, _a> y(x); |
| 998 | BOOST_CHECK_EQUAL(any_cast<int>(y), 4); |
| 999 | any<dst_concept, _a> z = as_rvalue(arg: x); |
| 1000 | BOOST_CHECK_EQUAL(any_cast<int>(z), 4); |
| 1001 | any<dst_concept, _a> w = as_const(arg: x); |
| 1002 | BOOST_CHECK_EQUAL(any_cast<int>(w), 4); |
| 1003 | } |
| 1004 | |
| 1005 | BOOST_AUTO_TEST_CASE(test_rebind_and_convert_with_binding_from_cref) |
| 1006 | { |
| 1007 | typedef ::boost::mpl::vector<common<>, incrementable<> > src_concept; |
| 1008 | typedef ::boost::mpl::vector<common<_a> > dst_concept; |
| 1009 | typedef ::boost::mpl::map<boost::mpl::pair<_a, _self> > map; |
| 1010 | typedef ::boost::mpl::map<boost::mpl::pair<_a, int> > types; |
| 1011 | |
| 1012 | static_binding<map> s_table(make_binding<map>()); |
| 1013 | binding<dst_concept> table(make_binding<types>()); |
| 1014 | |
| 1015 | int i = 4; |
| 1016 | any<src_concept, const _self&> x(i); |
| 1017 | BOOST_CHECK_EQUAL(any_cast<int>(x), 4); |
| 1018 | |
| 1019 | // lvalues |
| 1020 | any<dst_concept, _a> y1(x, s_table); |
| 1021 | BOOST_CHECK_EQUAL(any_cast<int>(y1), 4); |
| 1022 | any<dst_concept, _a> y2(x, as_rvalue(arg: s_table)); |
| 1023 | BOOST_CHECK_EQUAL(any_cast<int>(y2), 4); |
| 1024 | any<dst_concept, _a> y3(x, as_const(arg: s_table)); |
| 1025 | BOOST_CHECK_EQUAL(any_cast<int>(y3), 4); |
| 1026 | any<dst_concept, _a> z1(x, table); |
| 1027 | BOOST_CHECK_EQUAL(any_cast<int>(z1), 4); |
| 1028 | any<dst_concept, _a> z2(x, as_rvalue(arg: table)); |
| 1029 | BOOST_CHECK_EQUAL(any_cast<int>(z2), 4); |
| 1030 | any<dst_concept, _a> z3(x, as_const(arg: table)); |
| 1031 | BOOST_CHECK_EQUAL(any_cast<int>(z3), 4); |
| 1032 | |
| 1033 | // rvalues |
| 1034 | any<dst_concept, _a> ry1(as_rvalue(arg: x), s_table); |
| 1035 | BOOST_CHECK_EQUAL(any_cast<int>(ry1), 4); |
| 1036 | any<dst_concept, _a> ry2(as_rvalue(arg: x), as_rvalue(arg: s_table)); |
| 1037 | BOOST_CHECK_EQUAL(any_cast<int>(ry2), 4); |
| 1038 | any<dst_concept, _a> ry3(as_rvalue(arg: x), as_const(arg: s_table)); |
| 1039 | BOOST_CHECK_EQUAL(any_cast<int>(ry3), 4); |
| 1040 | any<dst_concept, _a> rz1(as_rvalue(arg: x), table); |
| 1041 | BOOST_CHECK_EQUAL(any_cast<int>(rz1), 4); |
| 1042 | any<dst_concept, _a> rz2(as_rvalue(arg: x), as_rvalue(arg: table)); |
| 1043 | BOOST_CHECK_EQUAL(any_cast<int>(rz2), 4); |
| 1044 | any<dst_concept, _a> rz3(as_rvalue(arg: x), as_rvalue(arg: table)); |
| 1045 | BOOST_CHECK_EQUAL(any_cast<int>(rz3), 4); |
| 1046 | |
| 1047 | // const lvalues |
| 1048 | any<dst_concept, _a> cy1(as_const(arg: x), s_table); |
| 1049 | BOOST_CHECK_EQUAL(any_cast<int>(cy1), 4); |
| 1050 | any<dst_concept, _a> cy2(as_const(arg: x), as_rvalue(arg: s_table)); |
| 1051 | BOOST_CHECK_EQUAL(any_cast<int>(cy2), 4); |
| 1052 | any<dst_concept, _a> cy3(as_const(arg: x), as_const(arg: s_table)); |
| 1053 | BOOST_CHECK_EQUAL(any_cast<int>(cy3), 4); |
| 1054 | any<dst_concept, _a> cz1(as_const(arg: x), table); |
| 1055 | BOOST_CHECK_EQUAL(any_cast<int>(cz1), 4); |
| 1056 | any<dst_concept, _a> cz2(as_const(arg: x), as_rvalue(arg: table)); |
| 1057 | BOOST_CHECK_EQUAL(any_cast<int>(cz2), 4); |
| 1058 | any<dst_concept, _a> cz3(as_const(arg: x), as_rvalue(arg: table)); |
| 1059 | BOOST_CHECK_EQUAL(any_cast<int>(cz3), 4); |
| 1060 | } |
| 1061 | |
| 1062 | #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES |
| 1063 | |
| 1064 | struct move_only |
| 1065 | { |
| 1066 | explicit move_only(int i) : value(i) {} |
| 1067 | move_only(move_only&& other) : value(other.value) { other.value = 0; } |
| 1068 | int value; |
| 1069 | private: |
| 1070 | move_only(const move_only&); |
| 1071 | }; |
| 1072 | |
| 1073 | BOOST_AUTO_TEST_CASE(test_move_only) |
| 1074 | { |
| 1075 | typedef ::boost::mpl::vector<destructible<>, typeid_<> > test_concept; |
| 1076 | move_only source(2); |
| 1077 | any<test_concept> x(std::move(source)); |
| 1078 | BOOST_CHECK_EQUAL(source.value, 0); |
| 1079 | BOOST_CHECK_EQUAL(any_cast<move_only&>(x).value, 2); |
| 1080 | } |
| 1081 | |
| 1082 | BOOST_AUTO_TEST_CASE(test_copy_from_rref) |
| 1083 | { |
| 1084 | typedef ::boost::mpl::vector<common<> > test_concept; |
| 1085 | int i = 4; |
| 1086 | any<test_concept, _self&&> x(std::move(i)); |
| 1087 | BOOST_CHECK_EQUAL(any_cast<int>(x), 4); |
| 1088 | any<test_concept> y(x); |
| 1089 | BOOST_CHECK_EQUAL(any_cast<int>(y), 4); |
| 1090 | any<test_concept> z = as_rvalue(arg: x); |
| 1091 | BOOST_CHECK_EQUAL(any_cast<int>(z), 4); |
| 1092 | any<test_concept> w = as_const(arg: x); |
| 1093 | BOOST_CHECK_EQUAL(any_cast<int>(w), 4); |
| 1094 | } |
| 1095 | |
| 1096 | BOOST_AUTO_TEST_CASE(test_convert_from_rref) |
| 1097 | { |
| 1098 | typedef ::boost::mpl::vector<common<>, incrementable<> > src_concept; |
| 1099 | typedef ::boost::mpl::vector<common<> > dst_concept; |
| 1100 | int i = 4; |
| 1101 | any<src_concept, _self&&> x(std::move(i)); |
| 1102 | BOOST_CHECK_EQUAL(any_cast<int>(x), 4); |
| 1103 | any<dst_concept> y(x); |
| 1104 | BOOST_CHECK_EQUAL(any_cast<int>(y), 4); |
| 1105 | any<dst_concept> z = as_rvalue(arg: x); |
| 1106 | BOOST_CHECK_EQUAL(any_cast<int>(z), 4); |
| 1107 | any<dst_concept> w = as_const(arg: x); |
| 1108 | BOOST_CHECK_EQUAL(any_cast<int>(w), 4); |
| 1109 | } |
| 1110 | |
| 1111 | BOOST_AUTO_TEST_CASE(test_rebind_from_rref) |
| 1112 | { |
| 1113 | typedef ::boost::mpl::vector<common<> > src_concept; |
| 1114 | typedef ::boost::mpl::vector<common<_a> > dst_concept; |
| 1115 | int i = 4; |
| 1116 | any<src_concept, _self&&> x(std::move(i)); |
| 1117 | BOOST_CHECK_EQUAL(any_cast<int>(x), 4); |
| 1118 | any<dst_concept, _a> y(x); |
| 1119 | BOOST_CHECK_EQUAL(any_cast<int>(y), 4); |
| 1120 | any<dst_concept, _a> z = as_rvalue(arg: x); |
| 1121 | BOOST_CHECK_EQUAL(any_cast<int>(z), 4); |
| 1122 | any<dst_concept, _a> w = as_const(arg: x); |
| 1123 | BOOST_CHECK_EQUAL(any_cast<int>(w), 4); |
| 1124 | } |
| 1125 | |
| 1126 | BOOST_AUTO_TEST_CASE(test_rebind_and_convert_from_rref) |
| 1127 | { |
| 1128 | typedef ::boost::mpl::vector<common<>, incrementable<> > src_concept; |
| 1129 | typedef ::boost::mpl::vector<common<_a> > dst_concept; |
| 1130 | int i = 4; |
| 1131 | any<src_concept, _self&&> x(std::move(i)); |
| 1132 | BOOST_CHECK_EQUAL(any_cast<int>(x), 4); |
| 1133 | any<dst_concept, _a> y(x); |
| 1134 | BOOST_CHECK_EQUAL(any_cast<int>(y), 4); |
| 1135 | any<dst_concept, _a> z = as_rvalue(arg: x); |
| 1136 | BOOST_CHECK_EQUAL(any_cast<int>(z), 4); |
| 1137 | any<dst_concept, _a> w = as_const(arg: x); |
| 1138 | BOOST_CHECK_EQUAL(any_cast<int>(w), 4); |
| 1139 | } |
| 1140 | |
| 1141 | BOOST_AUTO_TEST_CASE(test_rebind_and_convert_with_binding_from_rref) |
| 1142 | { |
| 1143 | typedef ::boost::mpl::vector<common<>, incrementable<> > src_concept; |
| 1144 | typedef ::boost::mpl::vector<common<_a> > dst_concept; |
| 1145 | typedef ::boost::mpl::map<boost::mpl::pair<_a, _self> > map; |
| 1146 | typedef ::boost::mpl::map<boost::mpl::pair<_a, int> > types; |
| 1147 | |
| 1148 | static_binding<map> s_table(make_binding<map>()); |
| 1149 | binding<dst_concept> table(make_binding<types>()); |
| 1150 | |
| 1151 | int i = 4; |
| 1152 | any<src_concept, _self&&> x(std::move(i)); |
| 1153 | BOOST_CHECK_EQUAL(any_cast<int>(x), 4); |
| 1154 | |
| 1155 | // lvalues |
| 1156 | any<dst_concept, _a> y1(x, s_table); |
| 1157 | BOOST_CHECK_EQUAL(any_cast<int>(y1), 4); |
| 1158 | any<dst_concept, _a> y2(x, as_rvalue(arg: s_table)); |
| 1159 | BOOST_CHECK_EQUAL(any_cast<int>(y2), 4); |
| 1160 | any<dst_concept, _a> y3(x, as_const(arg: s_table)); |
| 1161 | BOOST_CHECK_EQUAL(any_cast<int>(y3), 4); |
| 1162 | any<dst_concept, _a> z1(x, table); |
| 1163 | BOOST_CHECK_EQUAL(any_cast<int>(z1), 4); |
| 1164 | any<dst_concept, _a> z2(x, as_rvalue(arg: table)); |
| 1165 | BOOST_CHECK_EQUAL(any_cast<int>(z2), 4); |
| 1166 | any<dst_concept, _a> z3(x, as_const(arg: table)); |
| 1167 | BOOST_CHECK_EQUAL(any_cast<int>(z3), 4); |
| 1168 | |
| 1169 | // rvalues |
| 1170 | any<dst_concept, _a> ry1(as_rvalue(arg: x), s_table); |
| 1171 | BOOST_CHECK_EQUAL(any_cast<int>(ry1), 4); |
| 1172 | any<dst_concept, _a> ry2(as_rvalue(arg: x), as_rvalue(arg: s_table)); |
| 1173 | BOOST_CHECK_EQUAL(any_cast<int>(ry2), 4); |
| 1174 | any<dst_concept, _a> ry3(as_rvalue(arg: x), as_const(arg: s_table)); |
| 1175 | BOOST_CHECK_EQUAL(any_cast<int>(ry3), 4); |
| 1176 | any<dst_concept, _a> rz1(as_rvalue(arg: x), table); |
| 1177 | BOOST_CHECK_EQUAL(any_cast<int>(rz1), 4); |
| 1178 | any<dst_concept, _a> rz2(as_rvalue(arg: x), as_rvalue(arg: table)); |
| 1179 | BOOST_CHECK_EQUAL(any_cast<int>(rz2), 4); |
| 1180 | any<dst_concept, _a> rz3(as_rvalue(arg: x), as_rvalue(arg: table)); |
| 1181 | BOOST_CHECK_EQUAL(any_cast<int>(rz3), 4); |
| 1182 | |
| 1183 | // const lvalues |
| 1184 | any<dst_concept, _a> cy1(as_const(arg: x), s_table); |
| 1185 | BOOST_CHECK_EQUAL(any_cast<int>(cy1), 4); |
| 1186 | any<dst_concept, _a> cy2(as_const(arg: x), as_rvalue(arg: s_table)); |
| 1187 | BOOST_CHECK_EQUAL(any_cast<int>(cy2), 4); |
| 1188 | any<dst_concept, _a> cy3(as_const(arg: x), as_const(arg: s_table)); |
| 1189 | BOOST_CHECK_EQUAL(any_cast<int>(cy3), 4); |
| 1190 | any<dst_concept, _a> cz1(as_const(arg: x), table); |
| 1191 | BOOST_CHECK_EQUAL(any_cast<int>(cz1), 4); |
| 1192 | any<dst_concept, _a> cz2(as_const(arg: x), as_rvalue(arg: table)); |
| 1193 | BOOST_CHECK_EQUAL(any_cast<int>(cz2), 4); |
| 1194 | any<dst_concept, _a> cz3(as_const(arg: x), as_rvalue(arg: table)); |
| 1195 | BOOST_CHECK_EQUAL(any_cast<int>(cz3), 4); |
| 1196 | } |
| 1197 | |
| 1198 | #endif |
| 1199 | |