mirror of
https://github.com/boostorg/fusion.git
synced 2025-07-29 20:17:32 +02:00
associative iterators & views
[SVN r57156]
This commit is contained in:
@ -66,8 +66,8 @@ main()
|
||||
std::cout << tuple_close(']');
|
||||
std::cout << tuple_delimiter(", ");
|
||||
|
||||
test_set(as_set(erase_key<char>(make_set(1, 'x', 1.5, std::string("hello")))));
|
||||
test_map(as_map(erase_key<_2>(make_map<_1, _2, _3, _4>(1, 'x', 1.5, "hello"))));
|
||||
test_set(erase_key<char>(make_set(1, 'x', 1.5, std::string("hello"))));
|
||||
test_map(erase_key<_2>(make_map<_1, _2, _3, _4>(1, 'x', 1.5, "hello")));
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ main()
|
||||
std::cout << as_set(make_list(1, 1.23, "harru")) << std::endl;
|
||||
std::cout << as_set(push_back(empty, 999)) << std::endl;
|
||||
|
||||
BOOST_TEST(as_list(as_set(make_list(1, 1.23, "harru")))
|
||||
BOOST_TEST(as_list(as_set(make_list(1, 1.23, "harru")))
|
||||
== make_list(1, 1.23, std::string("harru")));
|
||||
BOOST_TEST(as_list(as_set(push_back(empty, 999)))
|
||||
== push_back(empty, 999));
|
||||
|
@ -13,6 +13,12 @@
|
||||
#include <boost/fusion/view/filter_view/filter_view.hpp>
|
||||
#include <boost/fusion/container/generation/make_vector.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/size.hpp>
|
||||
#include <boost/fusion/container/map.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/has_key.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/begin.hpp>
|
||||
#include <boost/fusion/iterator/key_of.hpp>
|
||||
#include <boost/fusion/iterator/value_of_data.hpp>
|
||||
#include <boost/fusion/iterator/deref_data.hpp>
|
||||
#include <boost/type_traits/is_class.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/mpl/arg.hpp>
|
||||
@ -62,22 +68,6 @@ main()
|
||||
std::cout << tuple_close(']');
|
||||
std::cout << tuple_delimiter(", ");
|
||||
|
||||
{ // Testing the static find_if (internal function)
|
||||
|
||||
typedef vector<int, char, long, X> vector_type;
|
||||
|
||||
vector_type v(1, 'x', 987654, X());
|
||||
typedef vector_iterator<vector_type, 0> begin;
|
||||
typedef vector_iterator<vector_type, 4> end;
|
||||
typedef detail::static_find_if<begin, end, is_same<_, long> > filter;
|
||||
typedef filter::type type;
|
||||
|
||||
BOOST_TEST(*type(v) == 987654);
|
||||
std::cout << *type(v) << std::endl;
|
||||
std::cout << *filter::call(begin(v)) << std::endl;
|
||||
BOOST_TEST(*type(v) == *filter::call(begin(v)));
|
||||
}
|
||||
|
||||
{
|
||||
typedef vector<Y, char, long, X, bool, double> vector_type;
|
||||
|
||||
@ -115,6 +105,23 @@ main()
|
||||
BOOST_MPL_ASSERT((result_of::equal_to<result_of::begin<filter_view_type>::type, result_of::end<filter_view_type>::type>));
|
||||
}
|
||||
|
||||
{
|
||||
typedef map<pair<void, int>, pair<double, std::string> > map_type;
|
||||
map_type m(make_pair<void>(0), make_pair<double>("Bond"));
|
||||
|
||||
typedef filter_view<map_type const, is_same<_, pair<double, std::string> > > filter_view_type;
|
||||
filter_view_type f(m);
|
||||
|
||||
BOOST_MPL_ASSERT((result_of::has_key<filter_view_type, double>::type));
|
||||
BOOST_MPL_ASSERT_NOT((result_of::has_key<filter_view_type, void>::type));
|
||||
|
||||
BOOST_MPL_ASSERT((is_same<result_of::key_of<result_of::begin<filter_view_type>::type>::type, double>));
|
||||
BOOST_MPL_ASSERT((is_same<result_of::value_of_data<result_of::begin<filter_view_type>::type>::type, std::string>));
|
||||
|
||||
std::cout << deref_data(begin(f)) << std::endl;
|
||||
BOOST_TEST((deref_data(begin(f)) == "Bond"));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
|
@ -5,15 +5,23 @@
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
==============================================================================*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/map.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/container/generation/make_vector.hpp>
|
||||
#include <boost/fusion/view/iterator_range/iterator_range.hpp>
|
||||
#include <boost/fusion/sequence/comparison/equal_to.hpp>
|
||||
#include <boost/fusion/sequence/io/out.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/size.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/begin.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/has_key.hpp>
|
||||
#include <boost/fusion/iterator/advance.hpp>
|
||||
#include <boost/fusion/iterator/key_of.hpp>
|
||||
#include <boost/fusion/iterator/value_of_data.hpp>
|
||||
#include <boost/fusion/iterator/deref_data.hpp>
|
||||
#include <boost/mpl/vector_c.hpp>
|
||||
#include <boost/mpl/begin.hpp>
|
||||
#include <boost/mpl/next.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
int
|
||||
@ -76,6 +84,31 @@ main()
|
||||
BOOST_STATIC_ASSERT(result_of::size<slice_t>::value == 2);
|
||||
}
|
||||
|
||||
{
|
||||
typedef map<pair<void,std::string>, pair<double,char>,pair<void*, int> > map_type;
|
||||
map_type m(make_pair<void>("foo"), make_pair<double>('x'), make_pair<void*>(2));
|
||||
|
||||
typedef iterator_range<
|
||||
result_of::begin<map_type>::type
|
||||
, result_of::advance_c<result_of::begin<map_type>::type,2>::type
|
||||
> range_type;
|
||||
range_type r(begin(m), advance_c<2>(begin(m)));
|
||||
|
||||
BOOST_MPL_ASSERT((result_of::has_key<range_type, void>::type));
|
||||
BOOST_MPL_ASSERT((result_of::has_key<range_type, double>::type));
|
||||
|
||||
BOOST_MPL_ASSERT((boost::is_same<result_of::key_of<result_of::begin<range_type>::type>::type, void>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<result_of::key_of<result_of::next<result_of::begin<range_type>::type>::type>::type, double>));
|
||||
|
||||
BOOST_MPL_ASSERT((boost::is_same<result_of::value_of_data<result_of::begin<range_type>::type>::type, std::string>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<result_of::value_of_data<result_of::next<result_of::begin<range_type>::type>::type>::type, char>));
|
||||
|
||||
std::cout << deref_data(begin(r)) << std::endl;
|
||||
std::cout << deref_data(next(begin(r))) << std::endl;
|
||||
BOOST_TEST((deref_data(begin(r)) == "foo"));
|
||||
BOOST_TEST((deref_data(next(begin(r))) == 'x'));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
|
@ -5,13 +5,22 @@
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
==============================================================================*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/map.hpp>
|
||||
#include <boost/fusion/container/set.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/view/joint_view/joint_view.hpp>
|
||||
#include <boost/fusion/sequence/io/out.hpp>
|
||||
#include <boost/fusion/sequence/comparison/equal_to.hpp>
|
||||
#include <boost/fusion/container/generation/make_vector.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/at.hpp>
|
||||
#include <boost/mpl/vector_c.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/has_key.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/begin.hpp>
|
||||
#include <boost/fusion/iterator/next.hpp>
|
||||
#include <boost/fusion/iterator/key_of.hpp>
|
||||
#include <boost/fusion/iterator/value_of.hpp>
|
||||
#include <boost/fusion/iterator/deref_data.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <string>
|
||||
|
||||
struct X
|
||||
{
|
||||
@ -139,6 +148,40 @@ main()
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
typedef map<pair<void,int> > map_type;
|
||||
map_type m(make_pair<void>(0));
|
||||
|
||||
typedef set<std::string, float> set_type;
|
||||
set_type s("foo", 1.3f);
|
||||
|
||||
typedef joint_view<map_type, set_type> joint_view_type;
|
||||
joint_view_type j(m,s);
|
||||
|
||||
BOOST_MPL_ASSERT((result_of::has_key<joint_view_type, void>::type));
|
||||
BOOST_MPL_ASSERT((result_of::has_key<joint_view_type, std::string>::type));
|
||||
BOOST_MPL_ASSERT((result_of::has_key<joint_view_type, float>::type));
|
||||
|
||||
BOOST_MPL_ASSERT((boost::is_same<result_of::key_of<result_of::begin<joint_view_type>::type>::type, void>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<result_of::key_of<result_of::next<result_of::begin<joint_view_type>::type>::type>::type, std::string>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<
|
||||
result_of::key_of<result_of::next<result_of::next<result_of::begin<joint_view_type>::type>::type>::type>::type
|
||||
, float>));
|
||||
|
||||
BOOST_MPL_ASSERT((boost::is_same<result_of::value_of_data<result_of::begin<joint_view_type>::type>::type, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<result_of::value_of_data<result_of::next<result_of::begin<joint_view_type>::type>::type>::type, std::string>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<
|
||||
result_of::value_of_data<result_of::next<result_of::next<result_of::begin<joint_view_type>::type>::type>::type>::type
|
||||
, float>));
|
||||
|
||||
std::cout << deref_data(begin(j)) << std::endl;
|
||||
std::cout << deref_data(boost::fusion::next(begin(j))) << std::endl;
|
||||
std::cout << deref_data(next(boost::fusion::next(begin(j)))) << std::endl;
|
||||
BOOST_TEST((deref_data(begin(j)) == 0));
|
||||
BOOST_TEST((deref_data(boost::fusion::next(begin(j))) == "foo"));
|
||||
BOOST_TEST((deref_data(next(boost::fusion::next(begin(j)))) == 1.3f));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,12 @@
|
||||
#include <boost/fusion/sequence/intrinsic/at_key.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/value_at_key.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/has_key.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/begin.hpp>
|
||||
#include <boost/fusion/sequence/io/out.hpp>
|
||||
#include <boost/fusion/iterator/key_of.hpp>
|
||||
#include <boost/fusion/iterator/deref_data.hpp>
|
||||
#include <boost/fusion/iterator/value_of_data.hpp>
|
||||
#include <boost/fusion/iterator/next.hpp>
|
||||
#include <boost/fusion/support/pair.hpp>
|
||||
#include <boost/fusion/support/category_of.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
@ -59,6 +64,17 @@ main()
|
||||
BOOST_STATIC_ASSERT((result_of::has_key<map_type, int>::value));
|
||||
BOOST_STATIC_ASSERT((result_of::has_key<map_type, double>::value));
|
||||
BOOST_STATIC_ASSERT((!result_of::has_key<map_type, std::string>::value));
|
||||
|
||||
std::cout << deref_data(begin(m)) << std::endl;
|
||||
std::cout << deref_data(next(begin(m))) << std::endl;
|
||||
|
||||
BOOST_TEST(deref_data(begin(m)) == 'X');
|
||||
BOOST_TEST(deref_data(next(begin(m))) == "Men");
|
||||
|
||||
BOOST_STATIC_ASSERT((is_same<result_of::key_of<result_of::begin<map_type>::type>::type, int>::value));
|
||||
BOOST_STATIC_ASSERT((is_same<result_of::key_of<result_of::next<result_of::begin<map_type>::type>::type>::type, double>::value));
|
||||
BOOST_STATIC_ASSERT((is_same<result_of::value_of_data<result_of::begin<map_type>::type>::type, char>::value));
|
||||
BOOST_STATIC_ASSERT((is_same<result_of::value_of_data<result_of::next<result_of::begin<map_type>::type>::type>::type, std::string>::value));
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -10,7 +10,12 @@
|
||||
#include <boost/fusion/sequence/intrinsic/at_key.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/value_at_key.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/has_key.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/begin.hpp>
|
||||
#include <boost/fusion/sequence/io/out.hpp>
|
||||
#include <boost/fusion/iterator/key_of.hpp>
|
||||
#include <boost/fusion/iterator/deref_data.hpp>
|
||||
#include <boost/fusion/iterator/value_of_data.hpp>
|
||||
#include <boost/fusion/iterator/next.hpp>
|
||||
#include <boost/fusion/support/pair.hpp>
|
||||
#include <boost/fusion/support/category_of.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
@ -48,12 +53,23 @@ main()
|
||||
boost::is_same<result_of::value_at_key<set_type, int>::type, int>::value));
|
||||
BOOST_STATIC_ASSERT((
|
||||
boost::is_same<result_of::value_at_key<set_type, std::string>::type, std::string>::value));
|
||||
|
||||
|
||||
std::cout << m << std::endl;
|
||||
|
||||
BOOST_STATIC_ASSERT((result_of::has_key<set_type, int>::value));
|
||||
BOOST_STATIC_ASSERT((result_of::has_key<set_type, std::string>::value));
|
||||
BOOST_STATIC_ASSERT((!result_of::has_key<set_type, double>::value));
|
||||
|
||||
std::cout << deref_data(begin(m)) << std::endl;
|
||||
std::cout << deref_data(next(begin(m))) << std::endl;
|
||||
|
||||
BOOST_TEST(deref_data(begin(m)) == 123);
|
||||
BOOST_TEST(deref_data(next(begin(m))) == "Hola");
|
||||
|
||||
BOOST_STATIC_ASSERT((is_same<result_of::key_of<result_of::begin<set_type>::type>::type, int>::value));
|
||||
BOOST_STATIC_ASSERT((is_same<result_of::key_of<result_of::next<result_of::begin<set_type>::type>::type>::type, std::string>::value));
|
||||
BOOST_STATIC_ASSERT((is_same<result_of::value_of_data<result_of::begin<set_type>::type>::type, int>::value));
|
||||
BOOST_STATIC_ASSERT((is_same<result_of::value_of_data<result_of::next<result_of::begin<set_type>::type>::type>::type, std::string>::value));
|
||||
}
|
||||
|
||||
{
|
||||
|
Reference in New Issue
Block a user