diff options
Diffstat (limited to 'libs/fusion/test/sequence/map.cpp')
-rw-r--r-- | libs/fusion/test/sequence/map.cpp | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/libs/fusion/test/sequence/map.cpp b/libs/fusion/test/sequence/map.cpp index 58497b44d..8dada1675 100644 --- a/libs/fusion/test/sequence/map.cpp +++ b/libs/fusion/test/sequence/map.cpp @@ -25,6 +25,24 @@ #include <iostream> #include <string> + +struct copy_all +{ + copy_all() {} + copy_all(copy_all const&) {} + + template <typename T> + copy_all(T const& x) + { + foo(x); // should fail! + } +}; + +struct abstract +{ + virtual void foo() = 0; +}; + int main() { @@ -41,7 +59,8 @@ main() { typedef map< pair<int, char> - , pair<double, std::string> > + , pair<double, std::string> + , pair<abstract, int> > map_type; BOOST_MPL_ASSERT((traits::is_associative<map_type>)); @@ -49,23 +68,29 @@ main() map_type m( make_pair<int>('X') - , make_pair<double>("Men")); + , make_pair<double>("Men") + , make_pair<abstract>(2)); std::cout << at_key<int>(m) << std::endl; std::cout << at_key<double>(m) << std::endl; + std::cout << at_key<abstract>(m) << std::endl; BOOST_TEST(at_key<int>(m) == 'X'); BOOST_TEST(at_key<double>(m) == "Men"); + BOOST_TEST(at_key<abstract>(m) == 2); BOOST_STATIC_ASSERT(( boost::is_same<boost::fusion::result_of::value_at_key<map_type, int>::type, char>::value)); BOOST_STATIC_ASSERT(( boost::is_same<boost::fusion::result_of::value_at_key<map_type, double>::type, std::string>::value)); + BOOST_STATIC_ASSERT(( + boost::is_same<boost::fusion::result_of::value_at_key<map_type, abstract>::type, int>::value)); std::cout << m << std::endl; BOOST_STATIC_ASSERT((boost::fusion::result_of::has_key<map_type, int>::value)); BOOST_STATIC_ASSERT((boost::fusion::result_of::has_key<map_type, double>::value)); + BOOST_STATIC_ASSERT((boost::fusion::result_of::has_key<map_type, abstract>::value)); BOOST_STATIC_ASSERT((!boost::fusion::result_of::has_key<map_type, std::string>::value)); std::cout << deref_data(begin(m)) << std::endl; @@ -73,15 +98,19 @@ main() BOOST_TEST(deref_data(begin(m)) == 'X'); BOOST_TEST(deref_data(fusion::next(begin(m))) == "Men"); + BOOST_TEST(deref_data(fusion::next(next(begin(m)))) == 2); BOOST_STATIC_ASSERT((boost::is_same<boost::fusion::result_of::key_of<boost::fusion::result_of::begin<map_type>::type>::type, int>::value)); BOOST_STATIC_ASSERT((boost::is_same<boost::fusion::result_of::key_of<boost::fusion::result_of::next<boost::fusion::result_of::begin<map_type>::type>::type>::type, double>::value)); + BOOST_STATIC_ASSERT((boost::is_same<boost::fusion::result_of::key_of<boost::fusion::result_of::next<boost::fusion::result_of::next<boost::fusion::result_of::begin<map_type>::type>::type>::type>::type, abstract>::value)); BOOST_STATIC_ASSERT((boost::is_same<boost::fusion::result_of::value_of_data<boost::fusion::result_of::begin<map_type>::type>::type, char>::value)); BOOST_STATIC_ASSERT((boost::is_same<boost::fusion::result_of::value_of_data<boost::fusion::result_of::next<boost::fusion::result_of::begin<map_type>::type>::type>::type, std::string>::value)); + BOOST_STATIC_ASSERT((boost::is_same<boost::fusion::result_of::value_of_data<boost::fusion::result_of::next<boost::fusion::result_of::next<boost::fusion::result_of::begin<map_type>::type>::type>::type>::type, int>::value)); // Test random access interface. pair<int, char> a = at_c<0>(m); (void) a; pair<double, std::string> b = at_c<1>(m); + pair<abstract, int> c = at_c<2>(m); } // iterators & random access interface. @@ -119,6 +148,31 @@ main() BOOST_TEST(at_key<char>(make_map<char, int>('X', 123)) == 'X'); BOOST_TEST(at_key<int>(make_map<char, int>('X', 123)) == 123); } + + { + // test for copy construction of fusion pairs + // make sure that the correct constructor is called + pair<int, copy_all> p1; + pair<int, copy_all> p2 = p1; + } + + { + // compile test only + // make sure result_of::deref_data returns a reference + typedef map<pair<float, int> > map_type; + typedef boost::fusion::result_of::begin<map_type>::type i_type; + typedef boost::fusion::result_of::deref_data<i_type>::type r_type; + BOOST_STATIC_ASSERT((boost::is_same<r_type, int&>::value)); + } + + { + // compile test only + // make sure result_of::deref_data is const correct + typedef map<pair<float, int> > const map_type; + typedef boost::fusion::result_of::begin<map_type>::type i_type; + typedef boost::fusion::result_of::deref_data<i_type>::type r_type; + BOOST_STATIC_ASSERT((boost::is_same<r_type, int const&>::value)); + } return boost::report_errors(); } |