fusion: merge of associative iterators/views and the new fold interface

[SVN r58618]
This commit is contained in:
Christopher Schmidt
2010-01-01 22:00:21 +00:00
parent b605617c4f
commit cda74605fc
379 changed files with 28481 additions and 2185 deletions

View File

@@ -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();
}

View File

@@ -34,22 +34,22 @@ struct add_ints_only
template<typename T>
struct result;
template <typename T, typename State>
struct result<add_ints_only(T,State)>
template <typename State, typename T>
struct result<add_ints_only(State, T)>
{
typedef typename boost::remove_const<
typename boost::remove_reference<State>::type>::type type;
};
template <typename T, typename State>
State const&
operator()(T const& x, State const& state) const
template <typename State, typename T>
State
operator()(State const& state, T const& x) const
{
return state;
}
int
operator()(int x, int state) const
operator()(int state, int x) const
{
return x + state;
}
@@ -60,13 +60,13 @@ struct count_ints
template<typename T>
struct result;
template <typename T, typename CountT>
struct result<count_ints(T,CountT)>
template <typename CountT, typename T>
struct result<count_ints(CountT, T)>
{
typedef typename boost::remove_const<
typename boost::remove_reference<T>::type>::type elem;
typedef typename boost::remove_const<
typename boost::remove_reference<CountT>::type>::type state;
typedef typename boost::remove_const<
typename boost::remove_reference<T>::type>::type elem;
typedef typename
if_<
@@ -77,11 +77,11 @@ struct count_ints
type;
};
template <typename T, typename CountT>
typename result<count_ints(T, CountT)>::type
operator()(T const&, CountT const&) const
template <typename CountT, typename T>
typename result<count_ints(CountT, T)>::type
operator()(CountT const&, T const&) const
{
typedef typename result<count_ints(T, CountT)>::type result;
typedef typename result<count_ints(CountT, T)>::type result;
return result();
}
};
@@ -90,7 +90,7 @@ struct appender
{
typedef std::string result_type;
std::string operator()(char c, std::string const& str) const
std::string operator()(std::string const& str, char c) const
{
return str + c;
}
@@ -102,14 +102,14 @@ struct lvalue_adder
struct result;
template<typename T0, typename T1>
struct result<lvalue_adder(T0&, T1)>
struct result<lvalue_adder(T0, T1&)>
{
// Second argument still needs to support rvalues - see definition of fusion::fold
typedef T0 type;
typedef T1 type;
};
template<typename T0, typename T1>
T0 operator()(T0& lhs, T1 const& rhs) const
T1 operator()(T0 const& lhs, T1& rhs) const
{
return lhs + rhs;
}

View File

@@ -22,7 +22,7 @@ namespace
typedef int result_type;
template<int n, int batch>
int operator()(distinct<n, batch> const& d, int state) const
int operator()(int state, distinct<n, batch> const& d) const
{
return state + n;
}

View File

@@ -67,7 +67,7 @@ struct test_func
typedef long result_type;
template <typename T>
long operator()(T & elem, long value) const
long operator()(long value, T & elem) const
{
elem += sizeof(T);
return value + elem;

View File

@@ -57,7 +57,7 @@ struct test_func
typedef long result_type;
template <typename T>
long operator()(T & elem, long value) const
long operator()(long value, T & elem) const
{
elem += sizeof(T);
return value + elem;

View File

@@ -63,13 +63,13 @@ struct test_func
typedef long result_type;
template <typename T>
long operator()(T const & elem, long value) const
long operator()(long value, T const & elem) const
{
return value + sizeof(T) * elem;
}
template <typename T>
long operator()(T & elem, long value) const
long operator()(long value, T & elem) const
{
elem += sizeof(T);
return value;

View File

@@ -14,6 +14,7 @@
#include <boost/fusion/sequence/intrinsic/back.hpp>
#include <boost/fusion/sequence/intrinsic/has_key.hpp>
#include <boost/fusion/sequence/intrinsic/at_key.hpp>
#include <boost/fusion/sequence/intrinsic/value_at.hpp>
#include <boost/fusion/sequence/intrinsic/value_at_key.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/container/vector/vector.hpp>
@@ -26,7 +27,10 @@
#include <boost/fusion/sequence/comparison/less_equal.hpp>
#include <boost/fusion/sequence/comparison/greater.hpp>
#include <boost/fusion/sequence/comparison/greater_equal.hpp>
#include <boost/fusion/mpl.hpp>
#include <boost/fusion/support/is_view.hpp>
#include <boost/mpl/front.hpp>
#include <boost/mpl/is_sequence.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/not.hpp>
#include <boost/type_traits/is_same.hpp>
@@ -126,6 +130,13 @@ main()
BOOST_TEST(at_key<ns::y_member>(p) == 3);
}
{
BOOST_MPL_ASSERT((mpl::is_sequence<ns::point>));
BOOST_MPL_ASSERT((boost::is_same<
fusion::result_of::value_at_c<ns::point,0>::type
, mpl::front<ns::point>::type>));
}
return boost::report_errors();
}

View File

@@ -11,6 +11,7 @@
#include <boost/fusion/sequence/intrinsic/empty.hpp>
#include <boost/fusion/sequence/intrinsic/front.hpp>
#include <boost/fusion/sequence/intrinsic/back.hpp>
#include <boost/fusion/sequence/intrinsic/value_at.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/container/vector/vector.hpp>
#include <boost/fusion/container/list/list.hpp>
@@ -22,7 +23,10 @@
#include <boost/fusion/sequence/comparison/less_equal.hpp>
#include <boost/fusion/sequence/comparison/greater.hpp>
#include <boost/fusion/sequence/comparison/greater_equal.hpp>
#include <boost/fusion/mpl.hpp>
#include <boost/fusion/support/is_view.hpp>
#include <boost/mpl/front.hpp>
#include <boost/mpl/is_sequence.hpp>
#include <boost/mpl/assert.hpp>
#include <iostream>
#include <string>
@@ -114,6 +118,14 @@ main()
BOOST_MPL_ASSERT((is_same<result_of::next<b>::type, e>));
}
{
BOOST_MPL_ASSERT((mpl::is_sequence<ns::point>));
BOOST_MPL_ASSERT((boost::is_same<
fusion::result_of::value_at_c<ns::point,0>::type
, mpl::front<ns::point>::type>));
}
return boost::report_errors();
}

View File

@@ -15,8 +15,12 @@
#include <boost/fusion/support/is_sequence.hpp>
#include <boost/fusion/support/is_view.hpp>
#include <boost/fusion/iterator.hpp>
#include <boost/fusion/mpl.hpp>
#include <boost/mpl/is_sequence.hpp>
#include <boost/mpl/front.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/type_traits/is_same.hpp>
int main()
{
@@ -37,5 +41,8 @@ int main()
BOOST_TEST(size(arr) == 3);
BOOST_TEST(distance(begin(arr), end(arr)) == 3);
BOOST_MPL_ASSERT((boost::mpl::is_sequence<array_type>));
BOOST_MPL_ASSERT((boost::is_same<int, boost::mpl::front<array_type>::type>));
return boost::report_errors();
}

View File

@@ -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));

View File

@@ -23,8 +23,11 @@
#include <boost/fusion/sequence/comparison/less_equal.hpp>
#include <boost/fusion/sequence/comparison/greater.hpp>
#include <boost/fusion/sequence/comparison/greater_equal.hpp>
#include <boost/fusion/mpl.hpp>
#include <boost/fusion/support/is_view.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/mpl/is_sequence.hpp>
#include <boost/mpl/front.hpp>
#include <boost/mpl/assert.hpp>
#include <iostream>
#include <string>
@@ -96,6 +99,12 @@ main()
BOOST_TEST(2u == fusion::distance(fusion::begin(t), fusion::end(t)));
}
{
typedef boost::tuple<int, std::string> tuple_type;
BOOST_MPL_ASSERT((mpl::is_sequence<tuple_type>));
BOOST_MPL_ASSERT((boost::is_same<int, mpl::front<tuple_type>::type>));
}
return boost::report_errors();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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));
}
{

View File

@@ -12,12 +12,17 @@
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/view/reverse_view/reverse_view.hpp>
#include <boost/fusion/sequence/intrinsic/begin.hpp>
#include <boost/fusion/sequence/intrinsic/at.hpp>
#include <boost/fusion/sequence/intrinsic/value_at.hpp>
#include <boost/fusion/iterator/next.hpp>
#include <boost/fusion/iterator/prior.hpp>
#include <boost/fusion/iterator/deref.hpp>
#include <boost/fusion/iterator/advance.hpp>
#include <boost/fusion/iterator/distance.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/range_c.hpp>
#include <boost/type_traits/is_same.hpp>
int
main()
@@ -57,6 +62,24 @@ main()
BOOST_TEST((*prior(second_it) == s));
BOOST_TEST((*advance_c<2>(first_it) == 'x'));
BOOST_TEST((distance(first_it, second_it) == 1));
BOOST_TEST((at_c<0>(rev)==s));
BOOST_TEST((at_c<1>(rev)==123456789));
BOOST_TEST((at_c<2>(rev)=='x'));
BOOST_TEST((at_c<3>(rev)==123));
BOOST_MPL_ASSERT((
boost::is_same<result_of::value_at_c<view_type,0>::type,char const*>
));
BOOST_MPL_ASSERT((
boost::is_same<result_of::value_at_c<view_type,1>::type,long>
));
BOOST_MPL_ASSERT((
boost::is_same<result_of::value_at_c<view_type,2>::type,char>
));
BOOST_MPL_ASSERT((
boost::is_same<result_of::value_at_c<view_type,3>::type,int>
));
}
return boost::report_errors();

View File

@@ -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));
}
{

View File

@@ -22,7 +22,10 @@
#include <boost/fusion/sequence/comparison/less_equal.hpp>
#include <boost/fusion/sequence/comparison/greater.hpp>
#include <boost/fusion/sequence/comparison/greater_equal.hpp>
#include <boost/fusion/mpl.hpp>
#include <boost/fusion/support/is_view.hpp>
#include <boost/mpl/is_sequence.hpp>
#include <boost/mpl/front.hpp>
#include <boost/mpl/assert.hpp>
#include <iostream>
#include <string>
@@ -86,6 +89,12 @@ main()
l = std::make_pair(123, "Hola!!!");
}
{
typedef std::pair<int, std::string> pair_type;
BOOST_MPL_ASSERT((mpl::is_sequence<pair_type>));
BOOST_MPL_ASSERT((boost::is_same<int, mpl::front<pair_type>::type>));
}
return boost::report_errors();
}