test_tagged.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Boost.Bimap
  2. //
  3. // Copyright (c) 2006-2007 Matias Capeletto
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. // VC++ 8.0 warns on usage of certain Standard Library and API functions that
  9. // can be cause buffer overruns or other possible security issues if misused.
  10. // See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx
  11. // But the wording of the warning is misleading and unsettling, there are no
  12. // portable alternative functions, and VC++ 8.0's own libraries use the
  13. // functions in question. So turn off the warnings.
  14. #define _CRT_SECURE_NO_DEPRECATE
  15. #define _SCL_SECURE_NO_DEPRECATE
  16. #include <boost/config.hpp>
  17. // Boost.Test
  18. #include <boost/test/minimal.hpp>
  19. #include <boost/static_assert.hpp>
  20. // Boost.MPL
  21. #include <boost/type_traits/is_same.hpp>
  22. #include <boost/mpl/placeholders.hpp>
  23. #include <boost/mpl/assert.hpp>
  24. #include <boost/type_traits/add_const.hpp>
  25. // Boost.Bimap
  26. #include <boost/bimap/detail/test/check_metadata.hpp>
  27. // Boost.Bimap.Tags
  28. #include <boost/bimap/tags/tagged.hpp>
  29. #include <boost/bimap/tags/support/default_tagged.hpp>
  30. #include <boost/bimap/tags/support/is_tagged.hpp>
  31. #include <boost/bimap/tags/support/overwrite_tagged.hpp>
  32. #include <boost/bimap/tags/support/tag_of.hpp>
  33. #include <boost/bimap/tags/support/value_type_of.hpp>
  34. #include <boost/bimap/tags/support/apply_to_value_type.hpp>
  35. BOOST_BIMAP_TEST_STATIC_FUNCTION( test_metafunctions )
  36. {
  37. using namespace boost::bimaps::tags::support;
  38. using namespace boost::bimaps::tags;
  39. using namespace boost::mpl::placeholders;
  40. using namespace boost;
  41. struct tag {};
  42. struct value {};
  43. // Test apply_to_value_type metafunction
  44. // tagged<value,tag> ----(add_const<_>)----> tagged<value const,tag>
  45. typedef tagged< value, tag > ttype;
  46. typedef apply_to_value_type< add_const<_>,ttype>::type result;
  47. typedef is_same<tagged<value const,tag>,result> compare;
  48. BOOST_MPL_ASSERT_MSG(compare::value,tag,(result));
  49. }
  50. struct tag_a {};
  51. struct tag_b {};
  52. struct data {};
  53. void test_function()
  54. {
  55. using namespace boost::bimaps::tags::support;
  56. using namespace boost::bimaps::tags;
  57. using boost::is_same;
  58. typedef tagged< data, tag_a > data_a;
  59. typedef tagged< data, tag_b > data_b;
  60. BOOST_CHECK(( is_same< data_a::value_type , data >::value ));
  61. BOOST_CHECK(( is_same< data_a::tag , tag_a >::value ));
  62. BOOST_CHECK((
  63. is_same< overwrite_tagged < data_a, tag_b >::type, data_b >::value
  64. ));
  65. BOOST_CHECK((
  66. is_same< default_tagged < data_a, tag_b >::type, data_a >::value
  67. ));
  68. BOOST_CHECK((
  69. is_same< default_tagged < data , tag_b >::type, data_b >::value
  70. ));
  71. BOOST_CHECK(( is_tagged< data >::value == false ));
  72. BOOST_CHECK(( is_tagged< data_a >::value == true ));
  73. BOOST_CHECK(( is_same< value_type_of<data_a>::type, data >::value ));
  74. BOOST_CHECK(( is_same< tag_of <data_a>::type, tag_a >::value ));
  75. }
  76. int test_main( int, char* [] )
  77. {
  78. test_function();
  79. // Test metanfunctions
  80. BOOST_BIMAP_CALL_TEST_STATIC_FUNCTION( test_metafunctions );
  81. return 0;
  82. }