forked from boostorg/fusion
Add test for #9418, abstract types for key of map.
https://svn.boost.org/trac/boost/ticket/9418
This commit is contained in:
@ -38,6 +38,11 @@ struct copy_all
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct abstract
|
||||||
|
{
|
||||||
|
virtual void foo() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
@ -54,7 +59,8 @@ main()
|
|||||||
{
|
{
|
||||||
typedef map<
|
typedef map<
|
||||||
pair<int, char>
|
pair<int, char>
|
||||||
, pair<double, std::string> >
|
, pair<double, std::string>
|
||||||
|
, pair<abstract, int> >
|
||||||
map_type;
|
map_type;
|
||||||
|
|
||||||
BOOST_MPL_ASSERT((traits::is_associative<map_type>));
|
BOOST_MPL_ASSERT((traits::is_associative<map_type>));
|
||||||
@ -62,23 +68,29 @@ main()
|
|||||||
|
|
||||||
map_type m(
|
map_type m(
|
||||||
make_pair<int>('X')
|
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<int>(m) << std::endl;
|
||||||
std::cout << at_key<double>(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<int>(m) == 'X');
|
||||||
BOOST_TEST(at_key<double>(m) == "Men");
|
BOOST_TEST(at_key<double>(m) == "Men");
|
||||||
|
BOOST_TEST(at_key<abstract>(m) == 2);
|
||||||
|
|
||||||
BOOST_STATIC_ASSERT((
|
BOOST_STATIC_ASSERT((
|
||||||
boost::is_same<boost::fusion::result_of::value_at_key<map_type, int>::type, char>::value));
|
boost::is_same<boost::fusion::result_of::value_at_key<map_type, int>::type, char>::value));
|
||||||
BOOST_STATIC_ASSERT((
|
BOOST_STATIC_ASSERT((
|
||||||
boost::is_same<boost::fusion::result_of::value_at_key<map_type, double>::type, std::string>::value));
|
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;
|
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, 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, 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));
|
BOOST_STATIC_ASSERT((!boost::fusion::result_of::has_key<map_type, std::string>::value));
|
||||||
|
|
||||||
std::cout << deref_data(begin(m)) << std::endl;
|
std::cout << deref_data(begin(m)) << std::endl;
|
||||||
@ -86,15 +98,19 @@ main()
|
|||||||
|
|
||||||
BOOST_TEST(deref_data(begin(m)) == 'X');
|
BOOST_TEST(deref_data(begin(m)) == 'X');
|
||||||
BOOST_TEST(deref_data(fusion::next(begin(m))) == "Men");
|
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::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::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::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::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.
|
// Test random access interface.
|
||||||
pair<int, char> a = at_c<0>(m); (void) a;
|
pair<int, char> a = at_c<0>(m); (void) a;
|
||||||
pair<double, std::string> b = at_c<1>(m);
|
pair<double, std::string> b = at_c<1>(m);
|
||||||
|
pair<abstract, int> c = at_c<2>(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
// iterators & random access interface.
|
// iterators & random access interface.
|
||||||
|
Reference in New Issue
Block a user