test_deduced.cpp 1.4 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/builtin.hpp>
  12. #include <boost/type_erasure/operators.hpp>
  13. #include <boost/type_erasure/any_cast.hpp>
  14. #include <boost/type_erasure/deduced.hpp>
  15. #include <boost/mpl/vector.hpp>
  16. #include <boost/mpl/assert.hpp>
  17. #include <boost/type_traits/remove_pointer.hpp>
  18. #include <boost/type_traits/is_same.hpp>
  19. #define BOOST_TEST_MAIN
  20. #include <boost/test/unit_test.hpp>
  21. using namespace boost::type_erasure;
  22. template<class T = _self>
  23. struct common : ::boost::mpl::vector<
  24. copy_constructible<T>,
  25. typeid_<T>
  26. > {};
  27. BOOST_AUTO_TEST_CASE(test_deduce_dereference)
  28. {
  29. typedef ::boost::mpl::vector<
  30. copy_constructible<>,
  31. typeid_<deduced<boost::remove_pointer<_self> >::type>,
  32. dereferenceable<deduced<boost::remove_pointer<_self> >&>
  33. > test_concept;
  34. int i;
  35. any<test_concept> x(&i);
  36. any<test_concept, deduced<boost::remove_pointer<_self> >&> y(*x);
  37. BOOST_CHECK_EQUAL(&any_cast<int&>(y), &i);
  38. }
  39. BOOST_MPL_ASSERT((
  40. boost::is_same<
  41. deduced<boost::remove_pointer<_self> >::type,
  42. deduced<boost::remove_pointer<_self> > >));
  43. BOOST_MPL_ASSERT((
  44. boost::is_same<deduced<boost::remove_pointer<int*> >::type, int >));