// Boost.TypeErasure library // // Copyright 2011 Steven Watanabe // // Distributed under the Boost Software License Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // $Id$ #include #include #include #include #include #include #include #include #include #define BOOST_TEST_MAIN #include using namespace boost::type_erasure; BOOST_AUTO_TEST_CASE(test_basic) { typedef boost::mpl::vector< forward_iterator<>, same_type::value_type, int> > test_concept; std::vector vec(10); any x(vec.begin()); any y(vec.end()); for(int i = 0; x != y; ++x, ++i) { *x = i; } int expected[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), &expected[0], &expected[0] + 10); BOOST_MPL_ASSERT((boost::is_same::value_type, int>)); BOOST_MPL_ASSERT((boost::is_same::reference, int&>)); BOOST_MPL_ASSERT((boost::is_same::pointer, int*>)); BOOST_MPL_ASSERT((boost::is_same::difference_type, std::ptrdiff_t>)); BOOST_MPL_ASSERT((boost::is_same::iterator_category, std::forward_iterator_tag>)); } BOOST_AUTO_TEST_CASE(test_any_value_type) { typedef boost::mpl::vector< forward_iterator<>, same_type::value_type, _a>, copy_constructible<_a>, assignable<_a>, incrementable<_a> > test_concept; std::vector vec(10); any x(vec.begin()); any y(vec.end()); for(any i = *x; x != y; ++x, ++i) { *x = i; } int expected[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), &expected[0], &expected[0] + 10); BOOST_MPL_ASSERT((boost::is_same::value_type, any >)); BOOST_MPL_ASSERT((boost::is_same::reference, any >)); BOOST_MPL_ASSERT((boost::is_same::pointer, any*>)); BOOST_MPL_ASSERT((boost::is_same::difference_type, std::ptrdiff_t>)); BOOST_MPL_ASSERT((boost::is_same::iterator_category, std::forward_iterator_tag>)); } BOOST_AUTO_TEST_CASE(test_relaxed) { typedef boost::mpl::vector< forward_iterator<>, same_type::value_type, int>, relaxed > test_concept; std::vector vec(10); any x(vec.begin()); any y(vec.end()); for(int i = 0; x != y; ++x, ++i) { *x = i; } int expected[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), &expected[0], &expected[0] + 10); BOOST_MPL_ASSERT((boost::is_same::value_type, int>)); BOOST_MPL_ASSERT((boost::is_same::reference, int&>)); BOOST_MPL_ASSERT((boost::is_same::pointer, int*>)); BOOST_MPL_ASSERT((boost::is_same::difference_type, std::ptrdiff_t>)); BOOST_MPL_ASSERT((boost::is_same::iterator_category, std::forward_iterator_tag>)); BOOST_CONCEPT_ASSERT((boost::ForwardIterator >)); }