test_structured_pair.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. // std
  20. #include <utility>
  21. #include <cstddef>
  22. // Boost.Static_assert
  23. #include <boost/static_assert.hpp>
  24. // Boost.Bimap
  25. #include <boost/bimap/detail/test/check_metadata.hpp>
  26. #include <boost/bimap/relation/structured_pair.hpp>
  27. BOOST_BIMAP_TEST_STATIC_FUNCTION( static_metadata_test )
  28. {
  29. using namespace boost::bimaps::relation;
  30. struct data_a { char data; };
  31. struct data_b { double data; };
  32. typedef structured_pair
  33. <
  34. data_a,
  35. data_b,
  36. normal_layout
  37. > sp_ab;
  38. typedef structured_pair
  39. <
  40. data_b,
  41. data_a,
  42. mirror_layout
  43. > sp_ba;
  44. BOOST_BIMAP_CHECK_METADATA(sp_ab, first_type , data_a);
  45. BOOST_BIMAP_CHECK_METADATA(sp_ab, second_type, data_b);
  46. BOOST_BIMAP_CHECK_METADATA(sp_ba, first_type , data_b);
  47. BOOST_BIMAP_CHECK_METADATA(sp_ba, second_type, data_a);
  48. }
  49. void test_basic()
  50. {
  51. using namespace boost::bimaps::relation;
  52. // Instanciate two pairs and test the storage alignmentDataData
  53. typedef structured_pair< short, double, normal_layout > pair_type;
  54. typedef structured_pair< double, short, mirror_layout > mirror_type;
  55. pair_type pa( 2, 3.1416 );
  56. mirror_type pb( 3.1416, 2 );
  57. BOOST_CHECK( pa.first == pb.second );
  58. BOOST_CHECK( pa.second == pb.first );
  59. }
  60. int test_main( int, char* [] )
  61. {
  62. BOOST_BIMAP_CALL_TEST_STATIC_FUNCTION( static_are_storage_compatible_test );
  63. BOOST_BIMAP_CALL_TEST_STATIC_FUNCTION( static_metadata_test );
  64. test_basic();
  65. return 0;
  66. }