compress_variant.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  5. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  6. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  7. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  8. // Use, modification and distribution is subject to the Boost Software License,
  9. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. #include <boost/test/included/test_exec_monitor.hpp>
  12. #include <boost/geometry/util/compress_variant.hpp>
  13. #include <boost/mpl/assert.hpp>
  14. #include <boost/mpl/equal.hpp>
  15. #include <boost/mpl/vector.hpp>
  16. #include <boost/type_traits/is_same.hpp>
  17. #include <boost/variant/variant.hpp>
  18. template <typename ExpectedTypes, BOOST_VARIANT_ENUM_PARAMS(typename T)>
  19. void check_variant_types(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>)
  20. {
  21. BOOST_MPL_ASSERT((
  22. boost::mpl::equal<
  23. typename boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types,
  24. ExpectedTypes
  25. >
  26. ));
  27. }
  28. template <typename Variant, typename ExpectedTypes>
  29. void test_variant_result()
  30. {
  31. check_variant_types<ExpectedTypes>(typename boost::geometry::compress_variant<Variant>::type());
  32. }
  33. template <typename Variant, typename ExpectedType>
  34. void test_single_type_result()
  35. {
  36. BOOST_MPL_ASSERT((
  37. boost::is_same<
  38. typename boost::geometry::compress_variant<Variant>::type,
  39. ExpectedType
  40. >
  41. ));
  42. }
  43. int test_main(int, char* [])
  44. {
  45. test_variant_result<
  46. boost::variant<int, float, double>,
  47. boost::mpl::vector<int, float, double>
  48. >();
  49. test_variant_result<
  50. boost::variant<int, float, double, int, int, float, double, double, float>,
  51. boost::mpl::vector<int, double, float>
  52. >();
  53. test_single_type_result<
  54. boost::variant<int>,
  55. int
  56. >();
  57. test_single_type_result<
  58. boost::variant<double, double, double, double, double>,
  59. double
  60. >();
  61. return 0;
  62. }