test_increment.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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/mpl/vector.hpp>
  16. #define BOOST_TEST_MAIN
  17. #include <boost/test/unit_test.hpp>
  18. using namespace boost::type_erasure;
  19. template<class T = _self>
  20. struct common : ::boost::mpl::vector<
  21. destructible<T>,
  22. copy_constructible<T>,
  23. typeid_<T>
  24. > {};
  25. BOOST_AUTO_TEST_CASE(test_value)
  26. {
  27. typedef ::boost::mpl::vector<common<>, incrementable<> > test_concept;
  28. any<test_concept> x(1);
  29. ++x;
  30. BOOST_CHECK_EQUAL(any_cast<int>(x), 2);
  31. any<test_concept> y(x++);
  32. BOOST_CHECK_EQUAL(any_cast<int>(x), 3);
  33. BOOST_CHECK_EQUAL(any_cast<int>(y), 2);
  34. }
  35. BOOST_AUTO_TEST_CASE(test_reference)
  36. {
  37. typedef ::boost::mpl::vector<common<>, incrementable<> > test_concept;
  38. int i = 1;
  39. any<test_concept, _self&> x(i);
  40. ++x;
  41. BOOST_CHECK_EQUAL(i, 2);
  42. any<test_concept> y(x++);
  43. BOOST_CHECK_EQUAL(i, 3);
  44. BOOST_CHECK_EQUAL(any_cast<int>(y), 2);
  45. }