test_typeid_of.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #include <boost/type_erasure/any.hpp>
  11. #include <boost/type_erasure/tuple.hpp>
  12. #include <boost/type_erasure/builtin.hpp>
  13. #include <boost/type_erasure/operators.hpp>
  14. #include <boost/type_erasure/any_cast.hpp>
  15. #include <boost/type_erasure/typeid_of.hpp>
  16. #include <boost/mpl/vector.hpp>
  17. #define BOOST_TEST_MAIN
  18. #include <boost/test/unit_test.hpp>
  19. using namespace boost::type_erasure;
  20. template<class T = _self>
  21. struct common : ::boost::mpl::vector<
  22. copy_constructible<T>,
  23. typeid_<T>
  24. > {};
  25. BOOST_AUTO_TEST_CASE(test_val)
  26. {
  27. typedef common<> test_concept;
  28. any<test_concept> x(2);
  29. BOOST_CHECK(typeid_of(x) == typeid(int));
  30. const any<test_concept> y(2);
  31. BOOST_CHECK(typeid_of(y) == typeid(int));
  32. }
  33. BOOST_AUTO_TEST_CASE(test_ref)
  34. {
  35. typedef common<> test_concept;
  36. int i;
  37. any<test_concept, _self&> x(i);
  38. BOOST_CHECK(typeid_of(x) == typeid(int));
  39. const any<test_concept, _self&> y(i);
  40. BOOST_CHECK(typeid_of(y) == typeid(int));
  41. }
  42. BOOST_AUTO_TEST_CASE(test_cref)
  43. {
  44. typedef common<> test_concept;
  45. int i;
  46. any<test_concept, const _self&> x(i);
  47. BOOST_CHECK(typeid_of(x) == typeid(int));
  48. const any<test_concept, const _self&> y(i);
  49. BOOST_CHECK(typeid_of(y) == typeid(int));
  50. }
  51. BOOST_AUTO_TEST_CASE(test_binding)
  52. {
  53. typedef boost::mpl::vector<common<_a>, common<_b> > test_concept;
  54. binding<test_concept> b =
  55. make_binding<
  56. boost::mpl::map<
  57. boost::mpl::pair<_a, int>,
  58. boost::mpl::pair<_b, double>
  59. >
  60. >();
  61. BOOST_CHECK(typeid_of<_a>(b) == typeid(int));
  62. BOOST_CHECK(typeid_of<_b>(b) == typeid(double));
  63. }