adding fusion docs and tests

[SVN r34920]
This commit is contained in:
Joel de Guzman
2006-08-22 15:57:13 +00:00
parent 75b9d13a88
commit c31253d8c1
351 changed files with 42280 additions and 0 deletions

96
test/Jamfile.v2 Normal file
View File

@ -0,0 +1,96 @@
#==============================================================================
# Copyright (c) 2003-2006 Joel de Guzman
#
# Use, modification and distribution is subject to 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)
#==============================================================================
# bring in rules for testing
import testing ;
{
test-suite fusion :
[ run algorithm/all.cpp : : : : ]
[ run algorithm/any.cpp : : : : ]
[ run algorithm/clear.cpp : : : : ]
[ run algorithm/count.cpp : : : : ]
[ run algorithm/count_if.cpp : : : : ]
[ run algorithm/erase.cpp : : : : ]
[ run algorithm/erase_key.cpp : : : : ]
[ run algorithm/filter.cpp : : : : ]
[ run algorithm/filter_if.cpp : : : : ]
[ run algorithm/find.cpp : : : : ]
[ run algorithm/find_if.cpp : : : : ]
[ run algorithm/fold.cpp : : : : ]
[ run algorithm/for_each.cpp : : : : ]
[ run algorithm/insert.cpp : : : : ]
[ run algorithm/insert_range.cpp : : : : ]
[ run algorithm/none.cpp : : : : ]
[ run algorithm/pop_back.cpp : : : : ]
[ run algorithm/pop_front.cpp : : : : ]
[ run algorithm/push_back.cpp : : : : ]
[ run algorithm/push_front.cpp : : : : ]
[ run algorithm/remove.cpp : : : : ]
[ run algorithm/remove_if.cpp : : : : ]
[ run algorithm/replace.cpp : : : : ]
[ run algorithm/replace_if.cpp : : : : ]
[ run algorithm/reverse.cpp : : : : ]
[ run algorithm/transform.cpp : : : : ]
[ run algorithm/join.cpp : : : : ]
[ run algorithm/zip.cpp : : : : ]
[ run sequence/as_list.cpp : : : : ]
[ run sequence/as_map.cpp : : : : ]
[ run sequence/as_set.cpp : : : : ]
[ run sequence/as_vector.cpp : : : : ]
[ run sequence/cons.cpp : : : : ]
[ run sequence/filter_view.cpp : : : : ]
[ run sequence/io.cpp : : : : ]
[ run sequence/iterator_range.cpp : : : : ]
[ run sequence/joint_view.cpp : : : : ]
[ run sequence/list_comparison.cpp : : : : ]
[ run sequence/list_construction.cpp : : : : ]
[ run sequence/list_copy.cpp : : : : ]
[ run sequence/list_iterator.cpp : : : : ]
[ run sequence/list_make.cpp : : : : ]
[ run sequence/list_misc.cpp : : : : ]
[ run sequence/list_mutate.cpp : : : : ]
[ run sequence/list_tie.cpp : : : : ]
[ run sequence/list_value_at.cpp : : : : ]
[ run sequence/make_list.cpp : : : : ]
[ run sequence/make_vector.cpp : : : : ]
[ run sequence/map.cpp : : : : ]
[ run sequence/reverse_view.cpp : : : : ]
[ run sequence/set.cpp : : : : ]
[ run sequence/single_view.cpp : : : : ]
[ run sequence/std_pair.cpp : : : : ]
[ run sequence/array.cpp : : : : ]
[ run sequence/tuple_comparison.cpp : : : : ]
[ run sequence/tuple_construction.cpp : : : : ]
[ run sequence/tuple_copy.cpp : : : : ]
[ run sequence/tuple_element.cpp : : : : ]
[ run sequence/tuple_make.cpp : : : : ]
[ run sequence/tuple_misc.cpp : : : : ]
[ run sequence/tuple_mutate.cpp : : : : ]
[ run sequence/tuple_tie.cpp : : : : ]
[ run sequence/transform_view.cpp : : : : ]
[ run sequence/unpack_args.cpp ]
[ run sequence/vector_comparison.cpp : : : : ]
[ run sequence/vector_construction.cpp : : : : ]
[ run sequence/vector_copy.cpp : : : : ]
[ run sequence/vector_iterator.cpp : : : : ]
[ run sequence/vector_make.cpp : : : : ]
[ run sequence/vector_misc.cpp : : : : ]
[ run sequence/vector_mutate.cpp : : : : ]
[ run sequence/vector_n.cpp : : : : ]
[ run sequence/vector_tie.cpp : : : : ]
[ run sequence/vector_value_at.cpp : : : : ]
[ run sequence/zip_view.cpp : : : : ]
[ run sequence/zip_view2.cpp : : : : ]
# [ compile-fail xxx.cpp : : : : ]
;
}

38
test/algorithm/all.cpp Normal file
View File

@ -0,0 +1,38 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/algorithm/query/all.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/mpl/vector_c.hpp>
int
main()
{
{
boost::fusion::vector<int, short, double> t(1, 2, 3.3);
BOOST_TEST((boost::fusion::all(t, boost::lambda::_1 < 4)));
BOOST_TEST((boost::fusion::all(t, boost::lambda::_1 > 0)));
}
{
boost::fusion::vector<int, short, double> t(1, 2, 3.3);
BOOST_TEST((!boost::fusion::all(t, boost::lambda::_1 == 1)));
BOOST_TEST((!boost::fusion::all(t, boost::lambda::_1 < 3)));
}
{
typedef boost::mpl::vector_c<int, 1, 2, 3> mpl_vec;
BOOST_TEST(boost::fusion::all(mpl_vec(), boost::lambda::_1 < 4));
BOOST_TEST(!boost::fusion::all(mpl_vec(), boost::lambda::_1 == 2));
}
return boost::report_errors();
}

37
test/algorithm/any.cpp Normal file
View File

@ -0,0 +1,37 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Copyright (c) 2005 Eric Niebler
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/algorithm/query/any.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/mpl/vector_c.hpp>
int
main()
{
{
boost::fusion::vector<int, short, double> t(1, 2, 3.3);
BOOST_TEST(boost::fusion::any(t, boost::lambda::_1 == 2));
}
{
boost::fusion::vector<int, short, double> t(1, 2, 3.3);
BOOST_TEST(!boost::fusion::any(t, boost::lambda::_1 == 3));
}
{
typedef boost::mpl::vector_c<int, 1, 2, 3> mpl_vec;
BOOST_TEST(boost::fusion::any(mpl_vec(), boost::lambda::_1 == 2));
BOOST_TEST(!boost::fusion::any(mpl_vec(), boost::lambda::_1 == 4));
}
return boost::report_errors();
}

46
test/algorithm/clear.cpp Normal file
View File

@ -0,0 +1,46 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/algorithm/transformation/clear.hpp>
#include <boost/mpl/vector_c.hpp>
int
main()
{
using namespace boost::fusion;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
/// Testing pop_back
{
char const* s = "Ruby";
typedef vector<int, char, double, char const*> vector_type;
vector_type t1(1, 'x', 3.3, s);
{
std::cout << clear(t1) << std::endl;
BOOST_TEST((clear(t1) == make_vector()));
}
}
{
typedef boost::mpl::vector_c<int, 1, 2, 3, 4, 5> mpl_vec;
std::cout << boost::fusion::clear(mpl_vec()) << std::endl;
BOOST_TEST((boost::fusion::clear(mpl_vec()) == make_vector()));
}
return boost::report_errors();
}

42
test/algorithm/count.cpp Normal file
View File

@ -0,0 +1,42 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Copyright (c) 2005 Eric Niebler
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/algorithm/query/count.hpp>
#include <boost/mpl/vector_c.hpp>
#include <string>
int
main()
{
{
boost::fusion::vector<int, short, double> t(1, 1, 1);
BOOST_TEST(boost::fusion::count(t, 1) == 3);
}
{
boost::fusion::vector<int, short, double> t(1, 2, 3.3);
BOOST_TEST(boost::fusion::count(t, 3) == 0);
}
{
boost::fusion::vector<int, std::string, double> t(4, "hello", 4);
BOOST_TEST(boost::fusion::count(t, "hello") == 1);
}
{
typedef boost::mpl::vector_c<int, 1, 2, 2, 2, 3, 3> mpl_vec;
BOOST_TEST(boost::fusion::count(mpl_vec(), 2) == 3);
BOOST_TEST(boost::fusion::count(mpl_vec(), 3) == 2);
}
return boost::report_errors();
}

View File

@ -0,0 +1,37 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Copyright (c) 2005 Eric Niebler
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/algorithm/query/count_if.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/mpl/vector_c.hpp>
int
main()
{
{
boost::fusion::vector<int, short, double> t(1, 2, 3.3);
BOOST_TEST(boost::fusion::count_if(t, boost::lambda::_1 == 2) == 1);
}
{
boost::fusion::vector<int, short, double> t(1, 2, 3.3);
BOOST_TEST(boost::fusion::count_if(t, boost::lambda::_1 == 3) == 0);
}
{
typedef boost::mpl::vector_c<int, 1, 2, 3> mpl_vec;
BOOST_TEST(boost::fusion::count_if(mpl_vec(), boost::lambda::_1 <= 2) == 2);
BOOST_TEST(boost::fusion::count_if(mpl_vec(), boost::lambda::_1 > 2) == 1);
}
return boost::report_errors();
}

64
test/algorithm/erase.cpp Normal file
View File

@ -0,0 +1,64 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/container/vector/vector_iterator.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/algorithm/transformation/erase.hpp>
#include <boost/mpl/vector_c.hpp>
#include <boost/mpl/begin_end.hpp>
#include <boost/mpl/advance.hpp>
#include <boost/mpl/int.hpp>
int
main()
{
using namespace boost::fusion;
using boost::mpl::vector_c;
using boost::mpl::begin;
using boost::mpl::advance;
using boost::mpl::int_;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
/// Testing erase
{
typedef vector<int, char, double, char const*> vector_type;
vector_type t1(1, 'x', 3.3, "Ruby");
vector_iterator<vector_type, 2> pos(t1);
std::cout << erase(t1, pos) << std::endl;
BOOST_TEST((erase(t1, pos) == make_vector(1, 'x', std::string("Ruby"))));
BOOST_TEST((erase(t1, end(t1)) == make_vector(1, 'x', 3.3, std::string("Ruby"))));
}
{
typedef vector_c<int, 1, 2, 3, 4, 5> mpl_vec;
typedef boost::mpl::begin<mpl_vec>::type mpl_vec_begin;
typedef boost::mpl::advance<mpl_vec_begin, int_<3> >::type mpl_vec_at3;
typedef boost::mpl::next<mpl_vec_begin>::type n1;
typedef boost::mpl::next<n1>::type n2;
typedef boost::mpl::next<n2>::type n3;
BOOST_STATIC_ASSERT((boost::is_same<mpl_vec_at3, n3>::value));
std::cout << erase(mpl_vec(), mpl_vec_at3()) << std::endl;
BOOST_TEST((erase(mpl_vec(), mpl_vec_at3())
== make_vector(1, 2, 3, 5)));
}
return boost::report_errors();
}

View File

@ -0,0 +1,75 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/set/set.hpp>
#include <boost/fusion/sequence/generation/make_set.hpp>
#include <boost/fusion/sequence/container/map/map.hpp>
#include <boost/fusion/sequence/generation/make_map.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/sequence/conversion/as_vector.hpp>
#include <boost/fusion/sequence/conversion/as_set.hpp>
#include <boost/fusion/sequence/conversion/as_map.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/sequence/intrinsic/size.hpp>
#include <boost/fusion/iterator/deref.hpp>
#include <boost/fusion/algorithm/transformation/erase_key.hpp>
#include <boost/fusion/algorithm/query/find.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/support/pair.hpp>
#include <boost/static_assert.hpp>
#include <iostream>
#include <string>
template <typename Set>
void test_set(Set const& set)
{
using namespace boost::fusion;
std::cout << set << std::endl;
BOOST_STATIC_ASSERT(result_of::size<Set>::value == 3);
BOOST_TEST((*find<int>(set) == 1));
BOOST_TEST((*find<double>(set) == 1.5));
BOOST_TEST((*find<std::string>(set) == "hello"));
}
typedef boost::mpl::int_<1> _1;
typedef boost::mpl::int_<2> _2;
typedef boost::mpl::int_<3> _3;
typedef boost::mpl::int_<4> _4;
template <typename Map>
void test_map(Map const& map)
{
using namespace boost::fusion;
std::cout << map << std::endl;
BOOST_STATIC_ASSERT(result_of::size<Map>::value == 3);
BOOST_TEST(((*find<_1>(map)).second == 1));
BOOST_TEST(((*find<_3>(map)).second == 1.5));
BOOST_TEST(((*find<_4>(map)).second == std::string("hello")));
}
int
main()
{
using namespace boost::fusion;
using namespace boost;
using namespace std;
using boost::fusion::pair;
using boost::fusion::make_pair;
std::cout << tuple_open('[');
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"))));
return boost::report_errors();
}

44
test/algorithm/filter.cpp Normal file
View File

@ -0,0 +1,44 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Copyright (c) 2005-2006 Dan Marsden
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/algorithm/transformation/filter.hpp>
#include <boost/mpl/vector.hpp>
int
main()
{
using namespace boost::fusion;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
typedef boost::fusion::vector<char,double,char> vector_type;
vector_type t('a', 6.6, 'b');
{
std::cout << filter<char>(t) << std::endl;
BOOST_TEST((filter<char>(t)
== make_vector('a', 'b')));
}
{
typedef boost::mpl::vector<char,double,char> mpl_vec;
BOOST_TEST((filter<char>(mpl_vec())
== make_vector('\0', '\0')));
}
return boost::report_errors();
}

View File

@ -0,0 +1,78 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/algorithm/transformation/filter_if.hpp>
#include <boost/type_traits/is_class.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/not.hpp>
struct X
{
operator char const*() const
{
return "<X-object>";
}
};
struct Y
{
operator char const*() const
{
return "<Y-object>";
}
};
int
main()
{
using namespace boost::fusion;
using boost::mpl::_;
using boost::mpl::not_;
using boost::is_class;
using boost::is_same;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
/// Testing filter_if
X x; Y y;
typedef boost::fusion::vector<Y, char, long, X, bool, double> vector_type;
vector_type t(y, '@', 987654, x, true, 6.6);
{
std::cout << filter_if<not_<is_class<_> > >(t) << std::endl;
BOOST_TEST((filter_if<not_<is_class<_> > >(t)
== make_vector('@', 987654, true, 6.6)));
}
{
std::cout << filter_if<is_class<_> >(t) << std::endl;
BOOST_TEST((filter_if<is_class<_> >(t)
== make_vector(y, x)));
}
{
typedef boost::mpl::vector<Y, char, long, X, bool> mpl_vec;
BOOST_TEST((filter_if<not_<is_class<_> > >(mpl_vec())
== make_vector(char(), long(), bool())));
BOOST_TEST((filter_if<is_class<_> >(mpl_vec())
== make_vector(y, x)));
}
return boost::report_errors();
}

80
test/algorithm/find.cpp Normal file
View File

@ -0,0 +1,80 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/sequence/container/set/set.hpp>
#include <boost/fusion/sequence/container/map/map.hpp>
#include <boost/fusion/algorithm/query/find.hpp>
#include <boost/fusion/iterator/deref.hpp>
#include <boost/mpl/vector.hpp>
#include <string>
struct X
{
operator int() const
{
return 12345;
}
};
int
main()
{
using namespace boost::fusion;
using boost::mpl::identity;
{
typedef vector<int, char, int, double> seq_type;
seq_type seq(12345, 'x', 678910, 3.36);
std::cout << *boost::fusion::find<char>(seq) << std::endl;
BOOST_TEST(*boost::fusion::find<char>(seq) == 'x');
std::cout << *boost::fusion::find<int>(seq) << std::endl;
BOOST_TEST(*boost::fusion::find<int>(seq) == 12345);
std::cout << *boost::fusion::find<double>(seq) << std::endl;
BOOST_TEST(*boost::fusion::find<double>(seq) == 3.36);
BOOST_TEST(boost::fusion::find<bool>(seq) == boost::fusion::end(seq));
}
{
typedef set<int, char, double> seq_type;
seq_type seq(12345, 'x', 3.36);
std::cout << *boost::fusion::find<char>(seq) << std::endl;
BOOST_TEST(*boost::fusion::find<char>(seq) == 'x');
BOOST_TEST(boost::fusion::find<bool>(seq) == boost::fusion::end(seq));
}
{
typedef map<
pair<int, char>
, pair<double, std::string> >
map_type;
map_type seq(
make_pair<int>('X')
, make_pair<double>("Men"));
std::cout << *boost::fusion::find<int>(seq) << std::endl;
std::cout << *boost::fusion::find<double>(seq) << std::endl;
BOOST_TEST((*boost::fusion::find<int>(seq)).second == 'X');
BOOST_TEST((*boost::fusion::find<double>(seq)).second == "Men");
BOOST_TEST(boost::fusion::find<bool>(seq) == boost::fusion::end(seq));
}
{
typedef boost::mpl::vector<int, char, X, double> mpl_vec;
BOOST_TEST((*boost::fusion::find<X>(mpl_vec()) == 12345));
BOOST_TEST(boost::fusion::find<bool>(mpl_vec()) == boost::fusion::end(mpl_vec()));
}
return boost::report_errors();
}

View File

@ -0,0 +1,70 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/algorithm/query/find_if.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/vector_c.hpp>
#include <boost/mpl/less.hpp>
#include <boost/type_traits/is_same.hpp>
struct X
{
operator int() const
{
return 12345;
}
};
int
main()
{
using namespace boost::fusion;
{
using boost::is_same;
using boost::mpl::_;
typedef vector<int, char, int, double> vector_type;
vector_type v(12345, 'x', 678910, 3.36);
std::cout << *find_if<is_same<_, char> >(v) << std::endl;
BOOST_TEST((*find_if<is_same<_, char> >(v) == 'x'));
std::cout << *find_if<is_same<_, int> >(v) << std::endl;
BOOST_TEST((*find_if<is_same<_, int> >(v) == 12345));
std::cout << *find_if<is_same<_, double> >(v) << std::endl;
BOOST_TEST((*find_if<is_same<_, double> >(v) == 3.36));
}
{
using boost::mpl::vector;
using boost::is_same;
using boost::mpl::_;
typedef vector<int, char, X, double> mpl_vec;
BOOST_TEST((*find_if<is_same<_, X> >(mpl_vec()) == 12345));
}
{
using boost::mpl::vector_c;
using boost::mpl::less;
using boost::mpl::int_;
using boost::is_same;
using boost::mpl::_;
typedef vector_c<int, 1, 2, 3, 4> mpl_vec;
BOOST_TEST((*find_if<less<_, int_<3> > >(mpl_vec()) == 1));
}
return boost::report_errors();
}

110
test/algorithm/fold.cpp Normal file
View File

@ -0,0 +1,110 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/sequence/intrinsic/at.hpp>
#include <boost/fusion/algorithm/iteration/fold.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/next.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/vector.hpp>
using boost::mpl::if_;
using boost::mpl::int_;
using boost::is_same;
struct add_ints_only
{
template <typename T, typename State>
struct result
{
typedef State type;
};
template <typename T, typename State>
State const&
operator()(T const& x, State const& state) const
{
return state;
}
int
operator()(int x, int state) const
{
return x + state;
}
};
struct count_ints
{
template <typename T, typename CountT>
struct result
{
typedef typename
if_<
is_same<T, int>
, typename boost::mpl::next<CountT>::type
, CountT
>::type
type;
};
template <typename T, typename CountT>
typename result<T, CountT>::type
operator()(T const&, CountT const&) const
{
typedef typename result<T, CountT>::type result;
return result();
}
};
int
main()
{
using namespace boost::fusion;
namespace fusion = boost::fusion;
{
typedef vector<int, char, int, double> vector_type;
vector_type v(12345, 'x', 678910, 3.36);
int result = fold(v, 0, add_ints_only());
std::cout << result << std::endl;
BOOST_TEST(result == 12345+678910);
}
{
typedef vector<int> vector_type;
vector_type v(12345);
int n = fusion::fold(v, int_<0>(), count_ints());
std::cout << n << std::endl;
BOOST_TEST(n == 1);
}
{
typedef vector<int, char, int, double, int> vector_type;
vector_type v(12345, 'x', 678910, 3.36, 8756);
int n = fusion::fold(v, int_<0>(), count_ints());
std::cout << n << std::endl;
BOOST_TEST(n == 3);
}
{
typedef boost::mpl::vector<int, char, int, double, int> mpl_vec;
int n = fusion::fold(mpl_vec(), int_<0>(), count_ints());
std::cout << n << std::endl;
BOOST_TEST(n == 3);
}
return boost::report_errors();
}

View File

@ -0,0 +1,62 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/algorithm/iteration/for_each.hpp>
#include <boost/mpl/vector_c.hpp>
struct print
{
template <typename T>
void operator()(T const& v) const
{
std::cout << "[ " << v << " ] ";
}
};
struct increment
{
template <typename T>
void operator()(T& v) const
{
++v;
}
};
int
main()
{
using namespace boost::fusion;
using boost::mpl::vector_c;
namespace fusion = boost::fusion;
{
typedef vector<int, char, double, char const*> vector_type;
vector_type v(1, 'x', 3.3, "Ruby");
for_each(v, print());
std::cout << std::endl;
}
{
typedef vector<int, char, double, char const*> vector_type;
vector_type v(1, 'x', 3.3, "Ruby");
for_each(v, increment());
std::cout << v << std::endl;
}
{
typedef vector_c<int, 2, 3, 4, 5, 6> mpl_vec;
fusion::for_each(mpl_vec(), print());
std::cout << std::endl;
}
return boost::report_errors();
}

68
test/algorithm/insert.cpp Normal file
View File

@ -0,0 +1,68 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/algorithm/transformation/insert.hpp>
#include <boost/mpl/vector_c.hpp>
#include <boost/mpl/begin_end.hpp>
#include <boost/mpl/advance.hpp>
#include <boost/mpl/int.hpp>
#include <string>
int
main()
{
using namespace boost::fusion;
using boost::mpl::vector_c;
using boost::mpl::advance;
using boost::mpl::int_;
namespace fusion = boost::fusion;
namespace mpl = boost::mpl;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
/// Testing insert
{
char const* s = "Ruby";
typedef vector<int, char, double, char const*> vector_type;
vector_type t1(1, 'x', 3.3, s);
vector_iterator<vector_type, 2> pos(t1);
std::cout << insert(t1, pos, 123456) << std::endl;
BOOST_TEST((insert(t1, pos, 123456)
== make_vector(1, 'x', 123456, 3.3, s)));
std::cout << insert(t1, end(t1), 123456) << std::endl;
BOOST_TEST((insert(t1, end(t1), 123456)
== make_vector(1, 'x', 3.3, s, 123456)));
std::cout << insert(t1, begin(t1), "glad") << std::endl;
BOOST_TEST((insert(t1, begin(t1), "glad")
== make_vector(std::string("glad"), 1, 'x', 3.3, s)));
}
{
typedef vector_c<int, 1, 2, 3, 4, 5> mpl_vec;
typedef mpl::begin<mpl_vec>::type mpl_vec_begin;
typedef advance<mpl_vec_begin, int_<3> >::type mpl_vec_at3;
std::cout << fusion::insert(mpl_vec(), mpl_vec_at3(), int_<66>()) << std::endl;
BOOST_TEST((fusion::insert(mpl_vec(), mpl_vec_at3(), int_<66>())
== make_vector(1, 2, 3, 66, 4, 5)));
}
return boost::report_errors();
}

View File

@ -0,0 +1,72 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/algorithm/transformation/insert_range.hpp>
#include <boost/mpl/vector_c.hpp>
#include <boost/mpl/begin_end.hpp>
#include <boost/mpl/advance.hpp>
#include <boost/mpl/int.hpp>
#include <string>
int
main()
{
using namespace boost::fusion;
using boost::mpl::vector_c;
using boost::mpl::advance;
using boost::mpl::int_;
namespace fusion = boost::fusion;
namespace mpl = boost::mpl;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
/// Testing insert_range
{
char const* s = "Ruby";
typedef vector<int, char, double, char const*> vector_type;
vector_type t1(1, 'x', 3.3, s);
vector_iterator<vector_type, 2> pos(t1);
typedef vector<int, char> vector_type2;
vector_type2 t2(999, 'z');
std::cout << insert_range(t1, pos, t2) << std::endl;
BOOST_TEST((insert_range(t1, pos, t2)
== make_vector(1, 'x', 999, 'z', 3.3, s)));
std::cout << insert_range(t1, end(t1), t2) << std::endl;
BOOST_TEST((insert_range(t1, end(t1), t2)
== make_vector(1, 'x', 3.3, s, 999, 'z')));
std::cout << insert_range(t1, begin(t1), t2) << std::endl;
BOOST_TEST((insert_range(t1, begin(t1), t2)
== make_vector(999, 'z', 1, 'x', 3.3, s)));
}
{
typedef vector_c<int, 1, 2, 3, 4, 5> mpl_vec;
typedef mpl::begin<mpl_vec>::type mpl_vec_begin;
typedef advance<mpl_vec_begin, int_<3> >::type mpl_vec_at3;
typedef vector_c<int, -1, -2> mpl_vec2;
std::cout << fusion::insert_range(mpl_vec(), mpl_vec_at3(), mpl_vec2()) << std::endl;
BOOST_TEST((fusion::insert_range(mpl_vec(), mpl_vec_at3(), mpl_vec2())
== make_vector(1, 2, 3, -1, -2, 4, 5)));
}
return boost::report_errors();
}

29
test/algorithm/join.cpp Normal file
View File

@ -0,0 +1,29 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Copyright (c) 2006 Dan Marsden
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/algorithm/transformation/join.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/mpl/vector/vector10_c.hpp>
int main()
{
using namespace boost::fusion;
{
BOOST_TEST(join(make_vector(1,2), make_vector('a','b')) == make_vector(1,2,'a','b'));
}
{
typedef boost::mpl::vector2_c<int,1,2> vec1;
typedef boost::mpl::vector2_c<int,3,4> vec2;
BOOST_TEST(join(vec1(), vec2()) == make_vector(1,2,3,4));
}
return boost::report_errors();
}

38
test/algorithm/none.cpp Normal file
View File

@ -0,0 +1,38 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/algorithm/query/none.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/mpl/vector_c.hpp>
int
main()
{
{
boost::fusion::vector<int, short, double> t(1, 2, 3.3);
BOOST_TEST((boost::fusion::none(t, boost::lambda::_1 > 4)));
BOOST_TEST((boost::fusion::none(t, boost::lambda::_1 < 0)));
}
{
boost::fusion::vector<int, short, double> t(1, 2, 3.3);
BOOST_TEST((!boost::fusion::none(t, boost::lambda::_1 == 1)));
BOOST_TEST((!boost::fusion::none(t, boost::lambda::_1 < 3)));
}
{
typedef boost::mpl::vector_c<int, 1, 2, 3> mpl_vec;
BOOST_TEST(boost::fusion::none(mpl_vec(), boost::lambda::_1 > 4));
BOOST_TEST(!boost::fusion::none(mpl_vec(), boost::lambda::_1 != 2));
}
return boost::report_errors();
}

View File

@ -0,0 +1,47 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/algorithm/transformation/pop_back.hpp>
#include <boost/mpl/vector_c.hpp>
int
main()
{
using namespace boost::fusion;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
/// Testing pop_back
{
char const* s = "Ruby";
typedef vector<int, char, double, char const*> vector_type;
vector_type t1(1, 'x', 3.3, s);
{
std::cout << pop_back(t1) << std::endl;
BOOST_TEST((pop_back(t1) == make_vector(1, 'x', 3.3)));
}
}
{
typedef boost::mpl::vector_c<int, 1, 2, 3, 4, 5> mpl_vec;
std::cout << boost::fusion::pop_back(mpl_vec()) << std::endl;
BOOST_TEST((boost::fusion::pop_back(mpl_vec()) == make_vector(1, 2, 3, 4)));
}
return boost::report_errors();
}

View File

@ -0,0 +1,47 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/algorithm/transformation/pop_front.hpp>
#include <boost/mpl/vector_c.hpp>
int
main()
{
using namespace boost::fusion;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
/// Testing pop_front
{
char const* s = "Ruby";
typedef vector<int, char, double, char const*> vector_type;
vector_type t1(1, 'x', 3.3, s);
{
std::cout << pop_front(t1) << std::endl;
BOOST_TEST((pop_front(t1) == make_vector('x', 3.3, s)));
}
}
{
typedef boost::mpl::vector_c<int, 1, 2, 3, 4, 5> mpl_vec;
std::cout << boost::fusion::pop_front(mpl_vec()) << std::endl;
BOOST_TEST((boost::fusion::pop_front(mpl_vec()) == make_vector(2, 3, 4, 5)));
}
return boost::report_errors();
}

View File

@ -0,0 +1,73 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/sequence/intrinsic/at.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/algorithm/transformation/push_back.hpp>
#include <boost/fusion/algorithm/iteration/for_each.hpp>
#include <boost/mpl/vector_c.hpp>
#include <string>
struct plus_one
{
template <typename T>
void operator()(T& v) const
{
v += 1;
}
};
int
main()
{
using namespace boost::fusion;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
/// Testing push_back
{
char const* s = "Ruby";
typedef vector<int, char, double, char const*> vector_type;
vector_type t1(1, 'x', 3.3, s);
{
std::cout << push_back(t1, 123456) << std::endl;
BOOST_TEST((push_back(t1, 123456)
== make_vector(1, 'x', 3.3, s, 123456)));
}
{
std::cout << push_back(t1, "funny") << std::endl;
BOOST_TEST((push_back(t1, "funny")
== make_vector(1, 'x', 3.3, s, std::string("funny"))));
}
{
std::cout << push_back(t1, t1) << std::endl;
BOOST_TEST((push_back(t1, t1)
== make_vector(1, 'x', 3.3, s, t1)));
}
}
{
typedef boost::mpl::vector_c<int, 1, 2, 3, 4, 5> mpl_vec;
std::cout << boost::fusion::push_back(mpl_vec(), boost::mpl::int_<6>()) << std::endl;
BOOST_TEST((boost::fusion::push_back(mpl_vec(), boost::mpl::int_<6>())
== make_vector(1, 2, 3, 4, 5, 6)));
}
return boost::report_errors();
}

View File

@ -0,0 +1,56 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/algorithm/transformation/push_front.hpp>
#include <boost/mpl/vector_c.hpp>
#include <string>
int
main()
{
using namespace boost::fusion;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
/// Testing push_front
{
char const* s = "Ruby";
typedef vector<int, char, double, char const*> vector_type;
vector_type t1(1, 'x', 3.3, s);
{
std::cout << push_front(t1, 123456) << std::endl;
BOOST_TEST((push_front(t1, 123456)
== make_vector(123456, 1, 'x', 3.3, s)));
}
{
std::cout << push_front(t1, "lively") << std::endl;
BOOST_TEST((push_front(t1, "lively")
== make_vector(std::string("lively"), 1, 'x', 3.3, s)));
}
}
{
typedef boost::mpl::vector_c<int, 2, 3, 4, 5, 6> mpl_vec;
std::cout << boost::fusion::push_front(mpl_vec(), boost::mpl::int_<1>()) << std::endl;
BOOST_TEST((boost::fusion::push_front(mpl_vec(), boost::mpl::int_<1>())
== make_vector(1, 2, 3, 4, 5, 6)));
}
return boost::report_errors();
}

81
test/algorithm/remove.cpp Normal file
View File

@ -0,0 +1,81 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/algorithm/transformation/remove.hpp>
#include <boost/mpl/vector.hpp>
struct X
{
operator char const*() const
{
return "<X-object>";
}
};
struct Y
{
operator char const*() const
{
return "<Y-object>";
}
};
int
main()
{
using namespace boost::fusion;
using boost::mpl::identity;
using boost::mpl::vector;
namespace fusion = boost::fusion;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
/// Testing remove
X x; Y y;
typedef fusion::vector<Y, char, long, X, bool, double> vector_type;
vector_type t(y, '@', 987654, x, true, 6.6);
{
std::cout << fusion::remove<X>(t) << std::endl;
BOOST_TEST((fusion::remove<X>(t)
== make_vector(y, '@', 987654, true, 6.6)));
}
{
std::cout << fusion::remove<Y>(t) << std::endl;
BOOST_TEST((fusion::remove<Y>(t)
== make_vector('@', 987654, x, true, 6.6)));
}
{
std::cout << fusion::remove<long>(t) << std::endl;
BOOST_TEST((fusion::remove<long>(t)
== make_vector(y, '@', x, true, 6.6)));
}
{
typedef vector<Y, char, long, X, bool> mpl_vec;
BOOST_TEST((fusion::remove<X>(mpl_vec())
== vector<Y, char, long, bool>()));
BOOST_TEST((fusion::remove<Y>(mpl_vec())
== vector<char, long, X, bool>()));
BOOST_TEST((fusion::remove<long>(mpl_vec())
== vector<Y, char, X, bool>()));
}
return boost::report_errors();
}

View File

@ -0,0 +1,79 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/algorithm/transformation/remove_if.hpp>
#include <boost/type_traits/is_class.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/not.hpp>
#include <boost/mpl/vector.hpp>
struct X
{
operator char const*() const
{
return "<X-object>";
}
};
struct Y
{
operator char const*() const
{
return "<Y-object>";
}
};
int
main()
{
using namespace boost::fusion;
using boost::mpl::vector;
using boost::mpl::_;
using boost::mpl::not_;
using boost::is_class;
using boost::is_same;
namespace fusion = boost::fusion;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
/// Testing remove_if
X x; Y y;
typedef fusion::vector<Y, char, long, X, bool, double> vector_type;
vector_type t(y, '@', 987654, x, true, 6.6);
{
std::cout << remove_if<not_<is_class<_> > >(t) << std::endl;
BOOST_TEST((remove_if<not_<is_class<_> > >(t)
== make_vector(y, x)));
}
{
std::cout << remove_if<is_class<_> >(t) << std::endl;
BOOST_TEST((remove_if<is_class<_> >(t)
== make_vector('@', 987654, true, 6.6)));
}
{
typedef vector<Y, char, long, X, bool> mpl_vec;
BOOST_TEST((remove_if<not_<is_class<_> > >(mpl_vec())
== vector<Y, X>()));
BOOST_TEST((remove_if<is_class<_> >(mpl_vec())
== vector<char, long, bool>()));
}
return boost::report_errors();
}

View File

@ -0,0 +1,50 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/sequence/intrinsic/at.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/algorithm/transformation/replace.hpp>
#include <string>
int
main()
{
using namespace boost::fusion;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
/// Testing replace
{
char const* s = "Ruby";
typedef vector<int, char, long, char const*> vector_type;
vector_type t1(1, 'x', 3, s);
{
std::cout << replace(t1, 'x', 'y') << std::endl;
BOOST_TEST((replace(t1, 'x', 'y')
== make_vector(1, 'y', 3, s)));
}
{
char const* s2 = "funny";
std::cout << replace(t1, s, s2) << std::endl;
BOOST_TEST((replace(t1, s, s2)
== make_vector(1, 'x', 3, s2)));
}
}
return boost::report_errors();
}

View File

@ -0,0 +1,53 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/sequence/intrinsic/at.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/algorithm/transformation/replace_if.hpp>
#include <string>
struct gt3
{
template <typename T>
bool operator()(T x) const
{
return x > 3;
}
};
int
main()
{
using namespace boost::fusion;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
/// Testing replace
{
char const* s = "Ruby";
typedef vector<int, short, double, long, char const*, float> vector_type;
vector_type t1(1, 2, 3.3, 4, s, 5.5);
{
std::cout << replace_if(t1, gt3(), -456) << std::endl;
BOOST_TEST((replace_if(t1, gt3(), -456)
== make_vector(1, 2, -456, -456, s, -456)));
}
}
return boost::report_errors();
}

View File

@ -0,0 +1,50 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/algorithm/transformation/reverse.hpp>
#include <boost/mpl/range_c.hpp>
int
main()
{
using namespace boost::fusion;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
/// Testing the reverse_view
{
typedef boost::mpl::range_c<int, 5, 9> mpl_list1;
mpl_list1 sequence;
std::cout << reverse(sequence) << std::endl;
BOOST_TEST((reverse(sequence) == make_vector(8, 7, 6, 5)));
}
{
char const* s = "Hi Kim";
typedef vector<int, char, double, char const*> vector_type;
vector_type t(123, 'x', 3.36, s);
std::cout << reverse(t) << std::endl;
BOOST_TEST((reverse(t) == make_vector(s, 3.36, 'x', 123)));
std::cout << reverse(reverse(t)) << std::endl;
BOOST_TEST((reverse(reverse(t)) == t));
}
return boost::report_errors();
}

View File

@ -0,0 +1,91 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/algorithm/transformation/transform.hpp>
#include <boost/type_traits/is_class.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/range_c.hpp>
#include <boost/type_traits/is_reference.hpp>
struct square
{
template <typename T>
struct result
{
BOOST_STATIC_ASSERT(!boost::is_reference<T>::value);
typedef int type;
};
template <typename T>
int operator()(T x) const
{
return x * x;
}
};
struct add
{
template <typename A, typename B>
struct result
{
typedef int type;
};
template <typename A, typename B>
int operator()(A a, B b) const
{
return a + b;
}
};
int
main()
{
using namespace boost::fusion;
using boost::mpl::range_c;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
/// Testing the transform
{
typedef range_c<int, 5, 9> sequence_type;
sequence_type sequence;
std::cout << transform(sequence, square()) << std::endl;
BOOST_TEST((transform(sequence, square()) == make_vector(25, 36, 49, 64)));
}
{
typedef range_c<int, 5, 9> mpl_list1;
std::cout << transform(mpl_list1(), square()) << std::endl;
BOOST_TEST((transform(mpl_list1(), square()) == make_vector(25, 36, 49, 64)));
}
{
vector<int, int, int> tup(1, 2, 3);
std::cout << transform(tup, square()) << std::endl;
BOOST_TEST((transform(tup, square()) == make_vector(1, 4, 9)));
}
{
vector<int, int, int> tup1(1, 2, 3);
vector<int, int, int> tup2(4, 5, 6);
std::cout << transform(tup1, tup2, add()) << std::endl;
BOOST_TEST((transform(tup1, tup2, add()) == make_vector(5, 7, 9)));
}
return boost::report_errors();
}

31
test/algorithm/zip.cpp Normal file
View File

@ -0,0 +1,31 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Copyright (c) 2006 Dan Marsden
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/algorithm/transformation/zip.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/mpl/vector.hpp>
int main()
{
using namespace boost::fusion;
{
BOOST_TEST(zip(make_vector(1,2), make_vector('a','b')) == make_vector(make_vector(1,'a'), make_vector(2,'b')));
BOOST_TEST(
zip(
make_vector(1,2),
make_vector('a','b'),
make_vector(-1,-2))
== make_vector(
make_vector(1,'a',-1),
make_vector(2,'b',-2))); // Zip more than 2 sequences
}
return boost::report_errors();
}

42
test/sequence/array.cpp Normal file
View File

@ -0,0 +1,42 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Copyright (c) 2005-2006 Dan Marsden
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/adapted/array.hpp>
#include <boost/array.hpp>
#include <boost/fusion/sequence/intrinsic.hpp>
#include <boost/fusion/support/is_sequence.hpp>
#include <boost/fusion/support/is_view.hpp>
#include <boost/fusion/iterator.hpp>
#include <boost/mpl/assert.hpp>
int main()
{
using namespace boost::fusion;
typedef boost::array<int,3> array_type;
BOOST_MPL_ASSERT((traits::is_sequence<array_type>));
BOOST_MPL_ASSERT_NOT((traits::is_view<array_type>));
array_type arr = {{1,2,3}};
BOOST_TEST(*begin(arr) == 1);
BOOST_TEST(*next(begin(arr)) == 2);
BOOST_TEST(*advance_c<2>(begin(arr)) == 3);
BOOST_TEST(prior(next(begin(arr))) == begin(arr));
BOOST_TEST(*prior(end(arr)) == 3);
BOOST_TEST(at_c<2>(arr) == 3);
BOOST_TEST(size(arr) == 3);
BOOST_TEST(distance(begin(arr), end(arr)) == 3);
return boost::report_errors();
}

54
test/sequence/as_list.cpp Normal file
View File

@ -0,0 +1,54 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/sequence/generation/make_list.hpp>
#include <boost/fusion/sequence/conversion/as_list.hpp>
#include <boost/fusion/algorithm/transformation/push_back.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/mpl/vector_c.hpp>
int
main()
{
using namespace boost::fusion;
using namespace boost;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
{
vector0 empty;
std::cout << as_list(make_vector(1, 1.23, "harru")) << std::endl;
std::cout << as_list(push_back(empty, 999)) << std::endl;
BOOST_TEST(as_list(make_vector(1, 1.23, "harru")) == make_vector(1, 1.23, std::string("harru")));
BOOST_TEST(as_list(push_back(empty, 999)) == push_back(empty, 999));
}
{
std::cout << as_list(mpl::vector_c<int, 1, 2, 3, 4, 5>()) << std::endl;
BOOST_TEST((as_list(mpl::vector_c<int, 1, 2, 3, 4, 5>())
== mpl::vector_c<int, 1, 2, 3, 4, 5>()));
}
{
// test conversion
list<int, std::string> l(make_vector(123, "harru"));
BOOST_TEST(l == make_vector(123, "harru"));
l = (make_vector(235, "hola")); // test assign
BOOST_TEST(l == make_vector(235, "hola"));
}
return boost::report_errors();
}

62
test/sequence/as_map.cpp Normal file
View File

@ -0,0 +1,62 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/sequence/generation/make_list.hpp>
#include <boost/fusion/sequence/conversion/as_map.hpp>
#include <boost/fusion/sequence/conversion/as_vector.hpp>
#include <boost/fusion/algorithm/transformation/push_back.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/sequence/intrinsic/at_key.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/support/pair.hpp>
int
main()
{
using namespace boost::fusion;
using namespace boost;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
{
vector0 empty;
std::cout << as_map(make_list(make_pair<int>('X'), make_pair<double>("Men"))) << std::endl;
std::cout << as_map(push_back(empty, make_pair<int>(999))) << std::endl;
}
{
typedef pair<int, char> p1;
typedef pair<double, std::string> p2;
result_of::as_map<list<p1, p2> >::type map(make_pair<int>('X'), make_pair<double>("Men"));
std::cout << at_key<int>(map) << std::endl;
std::cout << at_key<double>(map) << std::endl;
BOOST_TEST(at_key<int>(map) == 'X');
BOOST_TEST(at_key<double>(map) == "Men");
}
{
// test conversion
typedef map<
pair<int, char>
, pair<double, std::string> >
map_type;
map_type m(make_vector(make_pair<int>('X'), make_pair<double>("Men")));
BOOST_TEST(as_vector(m) == make_vector(make_pair<int>('X'), make_pair<double>("Men")));
m = (make_vector(make_pair<int>('X'), make_pair<double>("Men"))); // test assign
BOOST_TEST(as_vector(m) == make_vector(make_pair<int>('X'), make_pair<double>("Men")));
}
return boost::report_errors();
}

65
test/sequence/as_set.cpp Normal file
View File

@ -0,0 +1,65 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/sequence/generation/make_list.hpp>
#include <boost/fusion/sequence/conversion/as_set.hpp>
#include <boost/fusion/sequence/conversion/as_list.hpp>
#include <boost/fusion/sequence/conversion/as_vector.hpp>
#include <boost/fusion/algorithm/transformation/push_back.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/sequence/intrinsic/at_key.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/mpl/vector_c.hpp>
int
main()
{
using namespace boost::fusion;
using namespace boost;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
{
vector0 empty;
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")))
== make_list(1, 1.23, std::string("harru")));
BOOST_TEST(as_list(as_set(push_back(empty, 999)))
== push_back(empty, 999));
}
{
result_of::as_set<list<int, double, std::string> >::type set(1, 1.23, "harru");
std::cout << at_key<int>(set) << std::endl;
BOOST_TEST(at_key<int>(set) == 1);
}
{
std::cout << as_set(mpl::vector_c<int, 1, 2, 3, 4, 5>()) << std::endl;
BOOST_TEST((as_list(as_set(mpl::vector_c<int, 1, 2, 3, 4, 5>()))
== mpl::vector_c<int, 1, 2, 3, 4, 5>()));
}
{
// test conversion
set<int, std::string> s(make_vector(123, "harru"));
BOOST_TEST(as_vector(s) == make_vector(123, "harru"));
s = (make_vector(235, "hola")); // test assign
BOOST_TEST(as_vector(s) == make_vector(235, "hola"));
}
return boost::report_errors();
}

View File

@ -0,0 +1,55 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/sequence/generation/make_list.hpp>
#include <boost/fusion/sequence/conversion/as_vector.hpp>
#include <boost/fusion/algorithm/transformation/push_back.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/mpl/vector_c.hpp>
#include <string>
int
main()
{
using namespace boost::fusion;
using namespace boost;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
{
vector0 empty;
std::cout << as_vector(make_list(1, 1.23, "harru")) << std::endl;
std::cout << as_vector(push_back(empty, 999)) << std::endl;
BOOST_TEST(as_vector(make_list(1, 1.23, "harru")) == make_list(1, 1.23, std::string("harru")));
BOOST_TEST(as_vector(push_back(empty, 999)) == push_back(empty, 999));
}
{
std::cout << as_vector(mpl::vector_c<int, 1, 2, 3, 4, 5>()) << std::endl;
BOOST_TEST((as_vector(mpl::vector_c<int, 1, 2, 3, 4, 5>())
== mpl::vector_c<int, 1, 2, 3, 4, 5>()));
}
{
// test conversion
vector<int, std::string> v(make_list(123, "harru"));
BOOST_TEST(v == make_list(123, "harru"));
v = (make_list(235, "hola")); // test assign
BOOST_TEST(v == make_list(235, "hola"));
}
return boost::report_errors();
}

View File

@ -0,0 +1,58 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/comparison.hpp>
void
equality_test()
{
using namespace boost::fusion;
FUSION_SEQUENCE<int, char> v1(5, 'a');
FUSION_SEQUENCE<int, char> v2(5, 'a');
BOOST_TEST(v1 == v2);
FUSION_SEQUENCE<int, char> v3(5, 'b');
FUSION_SEQUENCE<int, char> t4(2, 'a');
BOOST_TEST(v1 != v3);
BOOST_TEST(v1 != t4);
BOOST_TEST(!(v1 != v2));
FUSION_SEQUENCE<int, char, bool> v5(5, 'a', true);
BOOST_TEST(v1 != v5);
BOOST_TEST(!(v1 == v5));
BOOST_TEST(v5 != v1);
BOOST_TEST(!(v5 == v1));
}
void
ordering_test()
{
using namespace boost::fusion;
FUSION_SEQUENCE<int, float> v1(4, 3.3f);
FUSION_SEQUENCE<short, float> v2(5, 3.3f);
FUSION_SEQUENCE<long, double> v3(5, 4.4);
BOOST_TEST(v1 < v2);
BOOST_TEST(v1 <= v2);
BOOST_TEST(v2 > v1);
BOOST_TEST(v2 >= v1);
BOOST_TEST(v2 < v3);
BOOST_TEST(v2 <= v3);
BOOST_TEST(v3 > v2);
BOOST_TEST(v3 >= v2);
#if defined(FUSION_TEST_FAIL)
FUSION_SEQUENCE<int, char, bool> v5(5, 'a', true);
v1 >= v5;
#endif
}

88
test/sequence/cons.cpp Normal file
View File

@ -0,0 +1,88 @@
/*=============================================================================
Copyright (c) 2005 Joel de Guzman
Copyright (c) 2005 Eric Niebler
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <string>
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/list/cons.hpp>
#include <boost/fusion/sequence/generation/make_cons.hpp>
#include <boost/fusion/sequence/generation/cons_tie.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/fusion/algorithm/iteration/for_each.hpp>
#include <boost/fusion/algorithm/transformation/filter_if.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/lambda.hpp>
int
main()
{
using namespace boost::fusion;
using boost::is_same;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
/// Testing cons
{
std::string hello("hello");
cons<int, cons<std::string> > ns =
make_cons(1, make_cons(hello));
BOOST_TEST((*begin(ns) == 1));
BOOST_TEST((*next(begin(ns)) == hello));
*begin(ns) += 1;
*next(begin(ns)) += ' ';
BOOST_TEST((*begin(ns) == 2));
BOOST_TEST((*next(begin(ns)) == hello + ' '));
for_each(ns, boost::lambda::_1 += ' ');
BOOST_TEST((*begin(ns) == 2 + ' '));
BOOST_TEST((*next(begin(ns)) == hello + ' ' + ' '));
}
{
BOOST_TEST(
make_cons("hello") == make_vector(std::string("hello"))
);
BOOST_TEST(
make_cons(123, make_cons("hello")) ==
make_vector(123, std::string("hello"))
);
}
{
vector<int, float> t(1, 1.1f);
cons<int, cons<float> > nf =
make_cons(1, make_cons(1.1f));
BOOST_TEST((t == nf));
BOOST_TEST((vector<int>(1) == filter_if<is_same<boost::mpl::_, int> >(nf)));
std::cout << nf << std::endl;
std::cout << filter_if<is_same<boost::mpl::_, int> >(nf) << std::endl;
}
{
int i = 3;
cons<int&> tie(cons_tie(i));
BOOST_TEST((*begin(tie) == 3));
}
return boost::report_errors();
}

View File

@ -0,0 +1,110 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/intrinsic/at.hpp>
#if !defined(FUSION_AT)
#define FUSION_AT at_c
#endif
namespace
{
// something to prevent warnings for unused variables
template<class T> void dummy(const T&) {}
// no public default constructor
class foo
{
public:
explicit foo(int v) : val(v) {}
bool operator==(const foo& other) const
{
return val == other.val;
}
private:
foo() {}
int val;
};
// another class without a public default constructor
class no_def_constructor
{
no_def_constructor() {}
public:
no_def_constructor(std::string) {}
};
}
inline void
test()
{
using namespace boost::fusion;
FUSION_SEQUENCE<int> t1;
BOOST_TEST(FUSION_AT<0>(t1) == int());
FUSION_SEQUENCE<float> t2(5.5f);
BOOST_TEST(FUSION_AT<0>(t2) > 5.4f && FUSION_AT<0>(t2) < 5.6f);
FUSION_SEQUENCE<foo> t3(foo(12));
BOOST_TEST(FUSION_AT<0>(t3) == foo(12));
FUSION_SEQUENCE<double> t4(t2);
BOOST_TEST(FUSION_AT<0>(t4) > 5.4 && FUSION_AT<0>(t4) < 5.6);
FUSION_SEQUENCE<int, float> t5;
BOOST_TEST(FUSION_AT<0>(t5) == int());
BOOST_TEST(FUSION_AT<1>(t5) == float());
FUSION_SEQUENCE<int, float> t6(12, 5.5f);
BOOST_TEST(FUSION_AT<0>(t6) == 12);
BOOST_TEST(FUSION_AT<1>(t6) > 5.4f && FUSION_AT<1>(t6) < 5.6f);
FUSION_SEQUENCE<int, float> t7(t6);
BOOST_TEST(FUSION_AT<0>(t7) == 12);
BOOST_TEST(FUSION_AT<1>(t7) > 5.4f && FUSION_AT<1>(t7) < 5.6f);
FUSION_SEQUENCE<long, double> t8(t6);
BOOST_TEST(FUSION_AT<0>(t8) == 12);
BOOST_TEST(FUSION_AT<1>(t8) > 5.4f && FUSION_AT<1>(t8) < 5.6f);
dummy
(
FUSION_SEQUENCE<no_def_constructor, no_def_constructor, no_def_constructor>(
std::string("Jaba"), // ok, since the default
std::string("Daba"), // constructor is not used
std::string("Doo")
)
);
dummy(FUSION_SEQUENCE<int, double>());
dummy(FUSION_SEQUENCE<int, double>(1,3.14));
#if defined(FUSION_TEST_FAIL)
dummy(FUSION_SEQUENCE<double&>()); // should fail, no defaults for references
dummy(FUSION_SEQUENCE<const double&>()); // likewise
#endif
{
double dd = 5;
dummy(FUSION_SEQUENCE<double&>(dd)); // ok
dummy(FUSION_SEQUENCE<const double&>(dd+3.14)); // ok, but dangerous
}
#if defined(FUSION_TEST_FAIL)
dummy(FUSION_SEQUENCE<double&>(dd+3.14)); // should fail,
// temporary to non-const reference
#endif
}

63
test/sequence/copy.hpp Normal file
View File

@ -0,0 +1,63 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/intrinsic/at.hpp>
#include <boost/preprocessor/cat.hpp>
#if !defined(FUSION_AT)
#define FUSION_AT at_c
#endif
#if !defined(FUSION_MAKE)
#define FUSION_MAKE BOOST_PP_CAT(make_, FUSION_SEQUENCE)
#endif
#if !defined(FUSION_TIE)
#define FUSION_TIE BOOST_PP_CAT(FUSION_SEQUENCE, _tie)
#endif
namespace
{
// classes with different kinds of conversions
class AA {};
class BB : public AA {};
struct CC { CC() {} CC(const BB&) {} };
struct DD { operator CC() const { return CC(); }; };
}
void
test()
{
using namespace boost::fusion;
FUSION_SEQUENCE<int, char> t1(4, 'a');
FUSION_SEQUENCE<int, char> t2(5, 'b');
t2 = t1;
BOOST_TEST(FUSION_AT<0>(t1) == FUSION_AT<0>(t2));
BOOST_TEST(FUSION_AT<1>(t1) == FUSION_AT<1>(t2));
FUSION_SEQUENCE<long, std::string> t3(2, "a");
t3 = t1;
BOOST_TEST((double)FUSION_AT<0>(t1) == FUSION_AT<0>(t3));
BOOST_TEST(FUSION_AT<1>(t1) == FUSION_AT<1>(t3)[0]);
// testing copy and assignment with implicit conversions
// between elements testing tie
FUSION_SEQUENCE<char, BB*, BB, DD> t;
FUSION_SEQUENCE<int, AA*, CC, CC> a(t);
a = t;
int i; char c; double d;
FUSION_TIE(i, c, d) = FUSION_MAKE(1, 'a', 5.5);
BOOST_TEST(i==1);
BOOST_TEST(c=='a');
BOOST_TEST(d>5.4 && d<5.6);
}

View File

@ -0,0 +1,118 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/sequence/container/vector/vector_iterator.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/sequence/view/filter_view/filter_view.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/sequence/intrinsic/size.hpp>
#include <boost/type_traits/is_class.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/arg.hpp>
#include <boost/mpl/not.hpp>
#include <boost/mpl/vector_c.hpp>
#include <boost/mpl/less.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/mpl/assert.hpp>
struct X
{
operator char const*() const
{
return "<X-object>";
}
};
struct Y
{
operator char const*() const
{
return "<Y-object>";
}
};
struct reject_all
{
template<typename T>
struct apply : boost::mpl::false_
{};
};
int
main()
{
using namespace boost::fusion;
using boost::mpl::int_;
using boost::mpl::_;
using boost::mpl::not_;
using boost::mpl::less;
using boost::mpl::vector_c;
using boost::is_class;
using boost::is_same;
std::cout << tuple_open('[');
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;
X x; Y y;
vector_type v(y, '@', 987654, x, true, 6.6);
typedef filter_view<vector_type const, not_<is_class<_> > > filter_view_type;
filter_view_type view(v);
std::cout << view << std::endl;
BOOST_TEST((view == make_vector('@', 987654, true, 6.6)));
BOOST_STATIC_ASSERT(result_of::size<filter_view_type>::value == 4);
}
{
// $$$ JDG $$$ For some obscure reason, comeau 4.3.3 has problems with this.
// vc7.1 and g++ are ok. The errors from comeau are useless.
typedef vector_c<int, 5, 1, 2, 3, 6, 0, -1> vector_type;
typedef filter_view<vector_type const, less<_, int_<3> > > filter_view_type;
vector_type v;
filter_view_type view(v);
std::cout << view << std::endl;
BOOST_TEST((view == make_vector(1, 2, 0, -1)));
BOOST_STATIC_ASSERT(result_of::size<filter_view_type>::value == 4);
}
{
// Previous filtering out all values caused problems as begin<seq> was not equal to end<seq>
// Picked up by Andreas Pokorny
typedef vector<int> vec;
typedef filter_view<vec, reject_all> filter_view_type;
BOOST_MPL_ASSERT((result_of::equal_to<result_of::begin<filter_view_type>::type, result_of::end<filter_view_type>::type>));
}
return boost::report_errors();
}

117
test/sequence/io.cpp Normal file
View File

@ -0,0 +1,117 @@
/*=============================================================================
Copyright (C) 1999-2003 Jaakko J<>rvi
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/sequence/io/in.hpp>
#include <fstream>
#include <iterator>
#include <algorithm>
#include <string>
#if defined BOOST_NO_STRINGSTREAM
# include <strstream>
#else
# include <sstream>
#endif
using boost::fusion::vector;
using boost::fusion::make_vector;
using boost::fusion::tuple_close;
using boost::fusion::tuple_open;
using boost::fusion::tuple_delimiter;
#if defined BOOST_NO_STRINGSTREAM
using std::ostrstream;
using std::istrstream;
typedef ostrstream useThisOStringStream;
typedef istrstream useThisIStringStream;
#else
using std::ostringstream;
using std::istringstream;
typedef ostringstream useThisOStringStream;
typedef istringstream useThisIStringStream;
#endif
using std::endl;
using std::ofstream;
using std::ifstream;
using std::string;
int
main()
{
using boost::fusion::tuple_close;
using boost::fusion::tuple_open;
using boost::fusion::tuple_delimiter;
useThisOStringStream os1;
// Set format [a, b, c] for os1
os1 << tuple_open('[');
os1 << tuple_close(']');
os1 << tuple_delimiter(',');
os1 << make_vector(1, 2, 3);
BOOST_TEST (os1.str() == std::string("[1,2,3]") );
{
useThisOStringStream os2;
// Set format (a:b:c) for os2;
os2 << tuple_open('(');
os2 << tuple_close(')');
os2 << tuple_delimiter(':');
os2 << make_vector("TUPU", "HUPU", "LUPU", 4.5);
BOOST_TEST (os2.str() == std::string("(TUPU:HUPU:LUPU:4.5)") );
}
// The format is still [a, b, c] for os1
os1 << make_vector(1, 2, 3);
BOOST_TEST (os1.str() == std::string("[1,2,3][1,2,3]") );
std::ofstream tmp("temp.tmp");
tmp << make_vector("One", "Two", 3);
tmp << tuple_delimiter(':');
tmp << make_vector(1000, 2000, 3000) << endl;
tmp.close();
// When reading tuples from a stream, manipulators must be set correctly:
ifstream tmp3("temp.tmp");
vector<string, string, int> j;
tmp3 >> j;
BOOST_TEST (tmp3.good() );
tmp3 >> tuple_delimiter(':');
vector<int, int, int> i;
tmp3 >> i;
BOOST_TEST (tmp3.good() );
tmp3.close();
// reading vector<int, int, int> in format (a b c);
useThisIStringStream is("(100 200 300)");
vector<int, int, int> ti;
BOOST_TEST(bool((is >> ti) != 0));
BOOST_TEST(ti == make_vector(100, 200, 300));
// Note that strings are problematic:
// writing a tuple on a stream and reading it back doesn't work in
// general. If this is wanted, some kind of a parseable string class
// should be used.
return boost::report_errors();
}

198
test/sequence/iterator.hpp Normal file
View File

@ -0,0 +1,198 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <string>
#include <boost/static_assert.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/support/category_of.hpp>
#include <boost/fusion/iterator/deref.hpp>
#include <boost/fusion/iterator/next.hpp>
#include <boost/fusion/iterator/prior.hpp>
#include <boost/fusion/iterator/equal_to.hpp>
#include <boost/fusion/iterator/distance.hpp>
#include <boost/fusion/iterator/advance.hpp>
#include <boost/fusion/iterator/value_of.hpp>
#include <boost/fusion/sequence/intrinsic/begin.hpp>
#include <boost/fusion/sequence/intrinsic/end.hpp>
#include <boost/fusion/sequence/intrinsic/at.hpp>
#include <boost/fusion/sequence/intrinsic/value_at.hpp>
void test()
{
using namespace boost::fusion;
using namespace boost;
{ // Testing deref, next, prior, begin, end
char const* s = "Hello";
typedef FUSION_SEQUENCE<int, char, double, char const*> seq_type;
seq_type v(1, 'x', 3.3, s);
result_of::begin<seq_type>::type i(v);
BOOST_TEST(*i == 1);
BOOST_TEST(*next(i) == 'x');
BOOST_TEST(*next(next(i)) == 3.3);
BOOST_TEST(*next(next(next(i))) == s);
next(next(next(next(i)))); // end
#if !defined(FUSION_NO_PRIOR)
BOOST_TEST(*prior(next(next(next(i)))) == 3.3);
BOOST_TEST(*prior(prior(next(next(next(i))))) == 'x');
BOOST_TEST(*prior(prior(prior(next(next(next(i)))))) == 1);
#endif
BOOST_TEST(*begin(v) == 1);
#if !defined(FUSION_NO_PRIOR)
BOOST_TEST(*prior(end(v)) == s);
#endif
*i = 3;
BOOST_TEST(*i == 3);
BOOST_TEST(&*i == &at_c<0>(v));
// prove that it is mutable
*i = 987;
BOOST_TEST(*i == 987);
}
{ // Testing const sequence and const iterator
char const* s = "Hello";
typedef FUSION_SEQUENCE<int, char, double, char const*> const seq_type;
seq_type t(1, 'x', 3.3, s);
result_of::begin<seq_type>::type i(t);
BOOST_TEST(*i == 1);
BOOST_TEST(*next(i) == 'x');
BOOST_TEST(*begin(t) == 1);
#if !defined(FUSION_NO_PRIOR)
BOOST_TEST(*prior(end(t)) == s);
#endif
#ifdef FUSION_TEST_FAIL
*i = 3; // must not compile
#endif
}
{ // Testing iterator equality
typedef FUSION_SEQUENCE<int, char, double, char const*> seq_type;
typedef FUSION_SEQUENCE<int, char, double, char const*> const cseq_type;
typedef result_of::begin<seq_type>::type vi1;
typedef result_of::begin<cseq_type>::type vi2;
BOOST_STATIC_ASSERT((result_of::equal_to<vi1 const, vi1>::value));
BOOST_STATIC_ASSERT((result_of::equal_to<vi1, vi1 const>::value));
BOOST_STATIC_ASSERT((result_of::equal_to<vi1, vi2>::value));
BOOST_STATIC_ASSERT((result_of::equal_to<vi1 const, vi2>::value));
BOOST_STATIC_ASSERT((result_of::equal_to<vi1, vi2 const>::value));
BOOST_STATIC_ASSERT((result_of::equal_to<vi1 const, vi2 const>::value));
}
{
typedef FUSION_SEQUENCE<int, int> seq_type;
typedef result_of::begin<seq_type>::type begin_type;
typedef result_of::end<seq_type>::type end_type;
typedef result_of::next<begin_type>::type i1;
typedef result_of::next<i1>::type i2;
BOOST_STATIC_ASSERT((is_same<end_type, i2>::value));
}
{ // testing deref, next, prior, begin, end
char const* s = "Hello";
typedef FUSION_SEQUENCE<int, char, double, char const*> seq_type;
seq_type t(1, 'x', 3.3, s);
result_of::begin<seq_type>::type i(t);
BOOST_TEST(*i == 1);
BOOST_TEST(*next(i) == 'x');
BOOST_TEST(*next(next(i)) == 3.3);
BOOST_TEST(*next(next(next(i))) == s);
next(next(next(next(i)))); // end
#ifdef FUSION_TEST_FAIL
next(next(next(next(next(i))))); // past the end: must not compile
#endif
#if !defined(FUSION_NO_PRIOR)
BOOST_TEST(*prior(next(next(next(i)))) == 3.3);
BOOST_TEST(*prior(prior(next(next(next(i))))) == 'x');
BOOST_TEST(*prior(prior(prior(next(next(next(i)))))) == 1);
#endif
BOOST_TEST(*begin(t) == 1);
#if !defined(FUSION_NO_PRIOR)
BOOST_TEST(*prior(end(t)) == s);
#endif
*i = 3;
BOOST_TEST(*i == 3);
BOOST_TEST(*i == at_c<0>(t));
}
{ // Testing distance
typedef FUSION_SEQUENCE<int, char, double, char const*> seq_type;
seq_type t(1, 'x', 3.3, "Hello");
BOOST_STATIC_ASSERT((result_of::distance<
result_of::begin<seq_type>::type
, result_of::end<seq_type>::type >::value == 4));
BOOST_TEST(distance(begin(t), end(t)).value == 4);
}
{ // Testing tuple iterator result_of::value_of, result_of::deref, result_of::value_at
typedef FUSION_SEQUENCE<int, char&> seq_type;
typedef result_of::begin<seq_type>::type i0;
typedef result_of::next<i0>::type i1;
typedef result_of::next<result_of::begin<const seq_type>::type>::type i2;
BOOST_STATIC_ASSERT((
is_same<result_of::value_at_c<seq_type, 0>::type, int>::value));
BOOST_STATIC_ASSERT((
is_same<result_of::value_at_c<seq_type, 1>::type, char&>::value));
BOOST_STATIC_ASSERT((
is_same<traits::category_of<i0>::type, FUSION_TRAVERSAL_TAG>::value));
BOOST_STATIC_ASSERT((is_same<result_of::deref<i0>::type, int&>::value));
BOOST_STATIC_ASSERT((is_same<result_of::deref<i1>::type, char&>::value));
BOOST_STATIC_ASSERT((is_same<result_of::value_of<i0>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of::value_of<i1>::type, char&>::value));
}
{ // Testing advance
typedef FUSION_SEQUENCE<int, char, double, char const*> seq_type;
seq_type t(1, 'x', 3.3, "Hello");
BOOST_TEST(*advance_c<0>(begin(t)) == at_c<0>(t));
BOOST_TEST(*advance_c<1>(begin(t)) == at_c<1>(t));
BOOST_TEST(*advance_c<2>(begin(t)) == at_c<2>(t));
BOOST_TEST(*advance_c<3>(begin(t)) == at_c<3>(t));
#if !defined(FUSION_NO_PRIOR)
BOOST_TEST(*advance_c<-1>(end(t)) == at_c<3>(t));
BOOST_TEST(*advance_c<-2>(end(t)) == at_c<2>(t));
BOOST_TEST(*advance_c<-3>(end(t)) == at_c<1>(t));
BOOST_TEST(*advance_c<-4>(end(t)) == at_c<0>(t));
#endif
BOOST_TEST(&*advance_c<0>(begin(t)) == &at_c<0>(t));
BOOST_TEST(&*advance_c<1>(begin(t)) == &at_c<1>(t));
BOOST_TEST(&*advance_c<2>(begin(t)) == &at_c<2>(t));
BOOST_TEST(&*advance_c<3>(begin(t)) == &at_c<3>(t));
}
}

View File

@ -0,0 +1,82 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/sequence/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/mpl/vector_c.hpp>
#include <boost/mpl/begin.hpp>
#include <boost/mpl/next.hpp>
#include <boost/static_assert.hpp>
int
main()
{
using namespace boost::fusion;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
{
char const* s = "Ruby";
typedef vector<int, char, double, char const*> vector_type;
vector_type vec(1, 'x', 3.3, s);
{
typedef vector_iterator<vector_type, 1> i1t;
typedef vector_iterator<vector_type, 3> i3t;
i1t i1(vec);
i3t i3(vec);
typedef iterator_range<i1t, i3t> slice_t;
slice_t slice(i1, i3);
std::cout << slice << std::endl;
BOOST_TEST((slice == make_vector('x', 3.3)));
BOOST_STATIC_ASSERT(result_of::size<slice_t>::value == 2);
}
{
typedef vector_iterator<vector_type, 0> i1t;
typedef vector_iterator<vector_type, 0> i3t;
i1t i1(vec);
i3t i3(vec);
typedef iterator_range<i1t, i3t> slice_t;
slice_t slice(i1, i3);
std::cout << slice << std::endl;
BOOST_TEST(slice == make_vector());
BOOST_STATIC_ASSERT(result_of::size<slice_t>::value == 0);
}
}
{
typedef boost::mpl::vector_c<int, 2, 3, 4, 5, 6> mpl_vec;
typedef boost::mpl::begin<mpl_vec>::type it0;
typedef boost::mpl::next<it0>::type it1;
typedef boost::mpl::next<it1>::type it2;
typedef boost::mpl::next<it2>::type it3;
it1 f;
it3 l;
typedef iterator_range<it1, it3> slice_t;
slice_t slice(f, l);
std::cout << slice << std::endl;
BOOST_TEST((slice == make_vector(3, 4)));
BOOST_STATIC_ASSERT(result_of::size<slice_t>::value == 2);
}
return boost::report_errors();
}

View File

@ -0,0 +1,145 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/view/joint_view/joint_view.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/sequence/intrinsic/at.hpp>
#include <boost/mpl/vector_c.hpp>
struct X
{
operator char const*() const
{
return "<X-object>";
}
};
int
main()
{
using namespace boost::fusion;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
/// Testing joint_view
{
vector<int> t1(3);
vector<X> t2;
typedef joint_view<vector<int>, vector<X> > view_type;
view_type view(t1, t2);
std::cout << view << std::endl;
BOOST_TEST((view == make_vector(3, X())));
}
{
vector<int, char> t1(3, 'x');
vector<X> t2;
typedef joint_view<vector<int, char>, vector<X> > view_type;
view_type view(t1, t2);
std::cout << view << std::endl;
BOOST_TEST((view == make_vector(3, 'x', X())));
*begin(view) = 4;
BOOST_TEST(at_c<0>(t1) == 4);
}
{
vector<int, char> t1(3, 'x');
vector<X, int> t2;
typedef joint_view<vector<int, char>, vector<X, int> > view_type;
view_type view(t1, t2);
std::cout << view << std::endl;
BOOST_TEST((view == make_vector(3, 'x', X(), 0)));
}
{
typedef vector<int> t1_type;
t1_type t1(777);
typedef vector<int, char, double> t2_type;
t2_type t2(1, 'x', 3.3);
{
typedef joint_view<t1_type, t2_type> view_type;
view_type view(t1, t2);
std::cout << view << std::endl;
BOOST_TEST((view == make_vector(777, 1, 'x', 3.3)));
}
{
typedef joint_view<t2_type, t1_type> view_type;
view_type view(t2, t1);
std::cout << view << std::endl;
BOOST_TEST((view == make_vector(1, 'x', 3.3, 777)));
}
{
typedef joint_view<t2_type, t1_type> jv_type;
typedef joint_view<jv_type, jv_type> jv2_type;
jv_type jv(t2, t1);
jv2_type jv2(jv, jv);
std::cout << jv << std::endl;
std::cout << jv2 << std::endl;
BOOST_TEST(jv2
== make_vector(1, 'x', 3.3, 777, 1, 'x', 3.3, 777));
}
{
typedef joint_view<t2_type, t1_type> jt_type;
typedef joint_view<t1_type, t2_type> jv2_type;
typedef joint_view<jt_type, jv2_type> jv3_type;
jt_type jt(t2, t1);
jv2_type jv2(t1, t2);
jv3_type jv3(jt, jv2);
std::cout << jt << std::endl;
std::cout << jv2 << std::endl;
std::cout << jv3 << std::endl;
BOOST_TEST(jv3
== make_vector(1, 'x', 3.3, 777, 777, 1, 'x', 3.3));
}
{
typedef joint_view<vector<>, t1_type> jt_type;
vector<> empty;
jt_type jt(empty, t1);
std::cout << jt << std::endl;
BOOST_TEST(jt == make_vector(777));
}
{
typedef joint_view<t1_type, vector<> > jt_type;
vector<> empty;
jt_type jt(t1, empty);
std::cout << jt << std::endl;
BOOST_TEST(jt == make_vector(777));
}
{
typedef joint_view<vector<>, vector<> > jt_type;
vector<> empty;
jt_type jt(empty, empty);
std::cout << jt << std::endl;
BOOST_TEST(jt == make_vector());
}
}
return boost::report_errors();
}

View File

@ -0,0 +1,20 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/fusion/sequence/container/list/list.hpp>
#define FUSION_SEQUENCE list
#include "comparison.hpp"
int
main()
{
equality_test();
ordering_test();
return boost::report_errors();
}

View File

@ -0,0 +1,19 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/fusion/sequence/container/list/list.hpp>
#define FUSION_SEQUENCE list
#include "construction.hpp"
int
main()
{
test();
return boost::report_errors();
}

View File

@ -0,0 +1,22 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/fusion/sequence/container/list/list.hpp>
#include <boost/fusion/sequence/generation/make_list.hpp>
#include <boost/fusion/sequence/generation/list_tie.hpp>
#define FUSION_SEQUENCE list
#include "copy.hpp"
int
main()
{
test();
return boost::report_errors();
}

View File

@ -0,0 +1,23 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/fusion/sequence/container/list/list.hpp>
#define FUSION_SEQUENCE list
#define FUSION_NO_PRIOR
#define FUSION_TRAVERSAL_TAG forward_traversal_tag
#include "./iterator.hpp"
int
main()
{
test();
return boost::report_errors();
}

View File

@ -0,0 +1,21 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/fusion/sequence/container/list/list.hpp>
#include <boost/fusion/sequence/generation/make_list.hpp>
#define FUSION_SEQUENCE list
#include "make.hpp"
int
main()
{
test();
return boost::report_errors();
}

View File

@ -0,0 +1,22 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/fusion/sequence/container/list/list.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#define FUSION_SEQUENCE list
#define FUSION_FORWARD_ONLY
#include "misc.hpp"
int
main()
{
test();
return boost::report_errors();
}

View File

@ -0,0 +1,20 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/fusion/sequence/container/list/list.hpp>
#define FUSION_SEQUENCE list
#include "mutate.hpp"
int
main()
{
test();
return boost::report_errors();
}

View File

@ -0,0 +1,23 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/fusion/sequence/container/list/list.hpp>
#include <boost/fusion/sequence/generation/list_tie.hpp>
#include <boost/fusion/sequence/generation/ignore.hpp>
#include <boost/fusion/sequence/generation/make_list.hpp>
#define FUSION_SEQUENCE list
#include "tie.hpp"
int
main()
{
test();
return boost::report_errors();
}

View File

@ -0,0 +1,20 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/fusion/sequence/container/list/list.hpp>
#define FUSION_SEQUENCE list
#include "value_at.hpp"
int
main()
{
test();
return boost::report_errors();
}

88
test/sequence/make.hpp Normal file
View File

@ -0,0 +1,88 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/intrinsic/at.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <string>
#if !defined(FUSION_AT)
#define FUSION_AT at_c
#endif
#if !defined(FUSION_MAKE)
#define FUSION_MAKE BOOST_PP_CAT(make_, FUSION_SEQUENCE)
#endif
namespace
{
// something to prevent warnings for unused variables
template<class T> void dummy(const T&) {}
class A {};
class B {};
}
void make_tuple_test() {}
void
test()
{
using namespace boost::fusion;
{
FUSION_SEQUENCE<int, char> t1 = FUSION_MAKE(5, 'a');
BOOST_TEST(FUSION_AT<0>(t1) == 5);
BOOST_TEST(FUSION_AT<1>(t1) == 'a');
FUSION_SEQUENCE<int, std::string> t2;
t2 = FUSION_MAKE((short int)2, std::string("Hi"));
BOOST_TEST(FUSION_AT<0>(t2) == 2);
BOOST_TEST(FUSION_AT<1>(t2) == "Hi");
}
{ // This test was previously disallowed for non-PTS compilers.
A a = A(); B b;
const A ca = a;
FUSION_MAKE(boost::cref(a), b);
FUSION_MAKE(boost::ref(a), b);
FUSION_MAKE(boost::ref(a), boost::cref(b));
FUSION_MAKE(boost::ref(ca));
}
{ // the result of make_xxx is assignable:
BOOST_TEST(FUSION_MAKE(2, 4, 6) ==
(FUSION_MAKE(1, 2, 3) = FUSION_MAKE(2, 4, 6)));
}
{ // This test was previously disallowed for non-PTS compilers.
FUSION_MAKE("Donald", "Daisy"); // should work;
// std::make_pair("Doesn't","Work"); // fails
}
{
// You can store a reference to a function in a sequence
FUSION_SEQUENCE<void(&)()> adf(make_tuple_test);
dummy(adf); // avoid warning for unused variable
}
#if defined(FUSION_TEST_FAIL)
{
// But make_xxx doesn't work
// with function references, since it creates a const
// qualified function type
FUSION_MAKE(make_tuple_test);
}
#endif
{
// With function pointers, make_xxx works just fine
FUSION_MAKE(&make_tuple_test);
}
}

View File

@ -0,0 +1,21 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/fusion/sequence/container/list/list.hpp>
#include <boost/fusion/sequence/generation/make_list.hpp>
#define FUSION_SEQUENCE list
#include "make.hpp"
int
main()
{
test();
return boost::report_errors();
}

View File

@ -0,0 +1,21 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#define FUSION_SEQUENCE vector
#include "make.hpp"
int
main()
{
test();
return boost::report_errors();
}

73
test/sequence/map.cpp Normal file
View File

@ -0,0 +1,73 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/map/map.hpp>
#include <boost/fusion/sequence/generation/make_map.hpp>
#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/io/out.hpp>
#include <boost/fusion/support/pair.hpp>
#include <boost/fusion/support/is_associative.hpp>
#include <boost/static_assert.hpp>
#include <boost/mpl/assert.hpp>
#include <iostream>
#include <string>
int
main()
{
using namespace boost::fusion;
using namespace boost;
using namespace std;
using boost::fusion::pair;
using boost::fusion::make_pair;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
{
typedef map<
pair<int, char>
, pair<double, std::string> >
map_type;
BOOST_MPL_ASSERT((traits::is_associative<map_type>));
map_type m(
make_pair<int>('X')
, make_pair<double>("Men"));
std::cout << at_key<int>(m) << std::endl;
std::cout << at_key<double>(m) << std::endl;
BOOST_TEST(at_key<int>(m) == 'X');
BOOST_TEST(at_key<double>(m) == "Men");
BOOST_STATIC_ASSERT((
boost::is_same<result_of::value_at_key<map_type, int>::type, char>::value));
BOOST_STATIC_ASSERT((
boost::is_same<result_of::value_at_key<map_type, double>::type, std::string>::value));
std::cout << m << std::endl;
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 << make_map<char, int>('X', 123) << std::endl;
BOOST_TEST(at_key<char>(make_map<char, int>('X', 123)) == 'X');
BOOST_TEST(at_key<int>(make_map<char, int>('X', 123)) == 123);
}
return boost::report_errors();
}

189
test/sequence/misc.hpp Normal file
View File

@ -0,0 +1,189 @@
/*=============================================================================
Copyright (C) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/intrinsic.hpp>
#include <boost/fusion/support/is_sequence.hpp>
#include <boost/mpl/find.hpp>
#include <boost/mpl/equal.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/integral_c.hpp>
#include <boost/type_traits/is_same.hpp>
#include <string>
#if !defined(FUSION_AT)
#define FUSION_AT at_c
#endif
#if !defined(FUSION_SIZE)
#define FUSION_SIZE result_of::size
#endif
template <typename S1, typename S2>
struct is_same
{
};
struct test_intrinsics1
{
// test at, begin, end, next, prior, advance, size, deref, etc.
typedef boost::fusion::FUSION_SEQUENCE<int, float, bool, char> sequence;
typedef boost::mpl::begin<sequence>::type first;
typedef boost::mpl::next<first>::type second;
typedef boost::mpl::next<second>::type third;
typedef boost::mpl::next<third>::type fourth;
typedef boost::mpl::end<sequence>::type last;
BOOST_STATIC_ASSERT((boost::is_same<
boost::mpl::deref<first>::type, int>::value));
BOOST_STATIC_ASSERT((boost::is_same<
boost::mpl::deref<second>::type, float>::value));
BOOST_STATIC_ASSERT((boost::is_same<
boost::mpl::deref<third>::type, bool>::value));
BOOST_STATIC_ASSERT((boost::is_same<
boost::mpl::deref<fourth>::type, char>::value));
BOOST_STATIC_ASSERT((boost::is_same<
boost::mpl::at_c<sequence, 2>::type, bool>::value));
BOOST_STATIC_ASSERT((boost::is_same<
boost::mpl::front<sequence>::type, int>::value));
BOOST_STATIC_ASSERT((boost::is_same<
boost::mpl::deref<
boost::mpl::advance_c<second, 2>::type>::type, char>::value));
BOOST_STATIC_ASSERT((boost::mpl::size<sequence>::value == 4));
BOOST_STATIC_ASSERT(!(boost::mpl::empty<sequence>::value));
BOOST_STATIC_ASSERT((boost::mpl::distance<second, fourth>::value == 2));
#if !defined(FUSION_FORWARD_ONLY) // list has no back/prev
typedef boost::mpl::prior<last>::type fourth_;
typedef boost::mpl::prior<fourth_>::type third_;
typedef boost::mpl::prior<third_>::type second_;
typedef boost::mpl::prior<second_>::type first_;
BOOST_STATIC_ASSERT((boost::is_same<
boost::mpl::deref<first_>::type, int>::value));
BOOST_STATIC_ASSERT((boost::is_same<
boost::mpl::deref<second_>::type, float>::value));
BOOST_STATIC_ASSERT((boost::is_same<
boost::mpl::deref<third_>::type, bool>::value));
BOOST_STATIC_ASSERT((boost::is_same<
boost::mpl::deref<fourth_>::type, char>::value));
BOOST_STATIC_ASSERT((boost::is_same<
boost::mpl::back<sequence>::type, char>::value));
#endif
};
struct test_intrinsics2
{
typedef boost::fusion::FUSION_SEQUENCE<> seq0;
#if !defined(FUSION_FORWARD_ONLY) // list has no back/prev
typedef boost::fusion::FUSION_SEQUENCE<int> target1;
typedef boost::mpl::push_back<seq0, int>::type seq1;
BOOST_STATIC_ASSERT((boost::mpl::equal<seq1, target1>::value));
typedef boost::fusion::FUSION_SEQUENCE<int, double> target2;
typedef boost::mpl::push_back<seq1, double>::type seq2;
BOOST_STATIC_ASSERT((boost::mpl::equal<seq2, target2>::value));
#endif
typedef boost::fusion::FUSION_SEQUENCE<int> target3;
typedef boost::mpl::push_front<seq0, int>::type seq3;
BOOST_STATIC_ASSERT((boost::mpl::equal<seq3, target3>::value));
typedef boost::fusion::FUSION_SEQUENCE<double, int> target4;
typedef boost::mpl::push_front<seq3, double>::type seq4;
BOOST_STATIC_ASSERT((boost::mpl::equal<seq4, target4>::value));
};
void
test()
{
using namespace boost::fusion;
{ // testing const sequences
const FUSION_SEQUENCE<int, float> t1(5, 3.3f);
BOOST_TEST(FUSION_AT<0>(t1) == 5);
BOOST_TEST(FUSION_AT<1>(t1) == 3.3f);
}
{ // testing at<N> works with MPL integral constants
const FUSION_SEQUENCE<int, char> t1(101, 'z');
BOOST_TEST(boost::fusion::at<boost::mpl::int_<0> >(t1) == 101);
BOOST_TEST(boost::fusion::at<boost::mpl::int_<1> >(t1) == 'z');
// explicitly try something other than mpl::int_
BOOST_TEST((boost::fusion::at<boost::mpl::integral_c<long, 0> >(t1) == 101));
BOOST_TEST((boost::fusion::at<boost::mpl::integral_c<long, 1> >(t1) == 'z'));
}
{ // testing size & empty
typedef FUSION_SEQUENCE<int, float, double> t1;
typedef FUSION_SEQUENCE<> t2;
BOOST_STATIC_ASSERT(FUSION_SIZE<t1>::value == 3);
BOOST_STATIC_ASSERT(FUSION_SIZE<t2>::value == 0);
BOOST_STATIC_ASSERT(!result_of::empty<t1>::value);
BOOST_STATIC_ASSERT(result_of::empty<t2>::value);
}
{ // testing front & back
typedef FUSION_SEQUENCE<int, float, std::string> tup;
tup t(1, 2.2, "Kimpo");
BOOST_TEST(front(t) == 1);
#if !defined(FUSION_FORWARD_ONLY) // list has no back
BOOST_TEST(back(t) == "Kimpo");
#endif
}
{ // testing is_sequence
typedef FUSION_SEQUENCE<int, float, double> t1;
typedef FUSION_SEQUENCE<> t2;
typedef FUSION_SEQUENCE<char> t3;
BOOST_STATIC_ASSERT(traits::is_sequence<t1>::value);
BOOST_STATIC_ASSERT(traits::is_sequence<t2>::value);
BOOST_STATIC_ASSERT(traits::is_sequence<t3>::value);
BOOST_STATIC_ASSERT(!traits::is_sequence<int>::value);
BOOST_STATIC_ASSERT(!traits::is_sequence<char>::value);
}
{ // testing mpl compatibility
// test begin, end, next, prior, advance, size, deref, etc.
//~ typedef FUSION_SEQUENCE<int, float, bool, char> tuple_type;
//~ test_intrinsics1<tuple_type> test1;
//~ (void)test1; // prevent unused variable warning
// test an algorithm
typedef FUSION_SEQUENCE<int, float, double> t1;
typedef boost::mpl::find<t1, float>::type iter;
typedef boost::mpl::deref<iter>::type type;
BOOST_STATIC_ASSERT((boost::is_same<type, float>::value));
}
}

52
test/sequence/mutate.hpp Normal file
View File

@ -0,0 +1,52 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/intrinsic/at.hpp>
#if !defined(FUSION_AT)
#define FUSION_AT at_c
#endif
namespace
{
// no public default constructor
class foo
{
public:
explicit foo(int v) : val(v) {}
bool operator==(const foo& other) const
{
return val == other.val;
}
private:
foo() {}
int val;
};
}
void
test()
{
using namespace boost::fusion;
FUSION_SEQUENCE<int, float, bool, foo> t1(5, 12.2f, true, foo(4));
FUSION_AT<0>(t1) = 6;
FUSION_AT<1>(t1) = 2.2f;
FUSION_AT<2>(t1) = false;
FUSION_AT<3>(t1) = foo(5);
BOOST_TEST(FUSION_AT<0>(t1) == 6);
BOOST_TEST(FUSION_AT<1>(t1) > 2.1f && FUSION_AT<1>(t1) < 2.3f);
BOOST_TEST(FUSION_AT<2>(t1) == false);
BOOST_TEST(FUSION_AT<3>(t1) == foo(5));
}

View File

@ -0,0 +1,65 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/sequence/view/reverse_view/reverse_view.hpp>
#include <boost/fusion/sequence/intrinsic/begin.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/range_c.hpp>
int
main()
{
using namespace boost::fusion;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
/// Testing the reverse_view
{
typedef boost::mpl::range_c<int, 5, 9> mpl_list1;
mpl_list1 l;
reverse_view<mpl_list1> rev(l);
std::cout << rev << std::endl;
BOOST_TEST((rev == make_vector(8, 7, 6, 5)));
}
{
char const* s = "Hi Kim";
typedef vector<int, char, long, char const*> vector_type;
vector_type t(123, 'x', 123456789, s);
typedef reverse_view<vector_type> view_type;
view_type rev(t);
std::cout << rev << std::endl;
BOOST_TEST((rev == make_vector(s, 123456789, 'x', 123)));
typedef result_of::begin<view_type>::type first_type;
first_type first_it(begin(rev));
typedef result_of::next<first_type>::type second_type;
second_type second_it(next(first_it));
BOOST_TEST((*second_it == 123456789));
BOOST_TEST((*prior(second_it) == s));
BOOST_TEST((*advance_c<2>(first_it) == 'x'));
BOOST_TEST((distance(first_it, second_it) == 1));
}
return boost::report_errors();
}

68
test/sequence/set.cpp Normal file
View File

@ -0,0 +1,68 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/set/set.hpp>
#include <boost/fusion/sequence/generation/make_set.hpp>
#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/io/out.hpp>
#include <boost/fusion/support/pair.hpp>
#include <boost/fusion/support/is_associative.hpp>
#include <boost/static_assert.hpp>
#include <boost/mpl/assert.hpp>
#include <iostream>
#include <string>
int
main()
{
using namespace boost::fusion;
using namespace boost;
using namespace std;
using boost::fusion::pair;
using boost::fusion::make_pair;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
{
typedef set<int, std::string> set_type;
BOOST_MPL_ASSERT((traits::is_associative<set_type>));
set_type m(123, "Hola");
std::cout << at_key<int>(m) << std::endl;
std::cout << at_key<std::string>(m) << std::endl;
BOOST_TEST(at_key<int>(m) == 123);
BOOST_TEST(at_key<std::string>(m) == "Hola");
BOOST_STATIC_ASSERT((
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 << make_set('X', 123) << std::endl;
BOOST_TEST(at_key<char>(make_set('X', 123)) == 'X');
BOOST_TEST(at_key<int>(make_set('X', 123)) == 123);
}
return boost::report_errors();
}

View File

@ -0,0 +1,58 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/sequence/view/single_view/single_view.hpp>
#include <boost/fusion/sequence/intrinsic/begin.hpp>
#include <boost/fusion/iterator/deref.hpp>
struct X {};
template <typename OS>
OS& operator<<(OS& os, X const&)
{
os << "<X-object>";
return os;
}
void foo() {}
int
main()
{
using namespace boost::fusion;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
{
single_view<int> view1(3);
std::cout << view1 << std::endl;
#ifdef FUSION_TEST_FAIL
// single_view is immutable
*begin(view1) += 4;
#endif
std::cout << view1 << std::endl;
BOOST_TEST(*begin(view1) == 3);
BOOST_TEST(view1.val == 3);
single_view<X> view2;
std::cout << view2 << std::endl;
}
{
std::cout << make_single_view(1) << std::endl;
std::cout << make_single_view("Hello, World") << std::endl;
std::cout << make_single_view(&foo) << std::endl;
}
return boost::report_errors();
}

View File

@ -0,0 +1,92 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/adapted/std_pair.hpp>
#include <boost/fusion/sequence/intrinsic/at.hpp>
#include <boost/fusion/sequence/intrinsic/size.hpp>
#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/io/out.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/container/list/list.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/sequence/conversion/as_vector.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/sequence/comparison/not_equal_to.hpp>
#include <boost/fusion/sequence/comparison/less.hpp>
#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/support/is_view.hpp>
#include <boost/mpl/assert.hpp>
#include <iostream>
#include <string>
#include <utility>
int
main()
{
using namespace boost::fusion;
using namespace boost;
using namespace std;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
{
typedef std::pair<int, std::string> pair_type;
BOOST_MPL_ASSERT_NOT((traits::is_view<pair_type>));
pair_type p(123, "Hola!!!");
std::cout << at_c<0>(p) << std::endl;
std::cout << at_c<1>(p) << std::endl;
std::cout << p << std::endl;
BOOST_TEST(p == make_vector(123, "Hola!!!"));
at_c<0>(p) = 6;
at_c<1>(p) = "mama mia";
BOOST_TEST(p == make_vector(6, "mama mia"));
BOOST_STATIC_ASSERT(result_of::size<pair_type>::value == 2);
BOOST_STATIC_ASSERT(!result_of::empty<pair_type>::value);
BOOST_TEST(front(p) == 6);
BOOST_TEST(back(p) == "mama mia");
}
{
fusion::vector<int, float> v1(4, 3.3f);
std::pair<short, float> v2(5, 3.3f);
fusion::vector<long, double> v3(5, 4.4);
BOOST_TEST(v1 < v2);
BOOST_TEST(v1 <= v2);
BOOST_TEST(v2 > v1);
BOOST_TEST(v2 >= v1);
BOOST_TEST(v2 < v3);
BOOST_TEST(v2 <= v3);
BOOST_TEST(v3 > v2);
BOOST_TEST(v3 >= v2);
}
{
// conversion from pair to vector
fusion::vector<int, std::string> v(std::make_pair(123, "Hola!!!"));
v = std::make_pair(123, "Hola!!!");
}
{
// conversion from pair to list
fusion::list<int, std::string> l(std::make_pair(123, "Hola!!!"));
l = std::make_pair(123, "Hola!!!");
}
return boost::report_errors();
}

85
test/sequence/tie.hpp Normal file
View File

@ -0,0 +1,85 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/intrinsic/at.hpp>
#if !defined(FUSION_AT)
#define FUSION_AT at_c
#endif
#if !defined(FUSION_MAKE)
#define FUSION_MAKE BOOST_PP_CAT(make_, FUSION_SEQUENCE)
#endif
#if !defined(FUSION_TIE)
#define FUSION_TIE BOOST_PP_CAT(FUSION_SEQUENCE, _tie)
#endif
namespace
{
// something to prevent warnings for unused variables
template<class T> void dummy(const T&) {}
// no public default constructor
class foo
{
public:
explicit foo(int v) : val(v) {}
bool operator==(const foo& other) const
{
return val == other.val;
}
private:
foo() {}
int val;
};
}
void
test()
{
using namespace boost::fusion;
int a;
char b;
foo c(5);
FUSION_TIE(a, b, c) = FUSION_MAKE(2, 'a', foo(3));
BOOST_TEST(a == 2);
BOOST_TEST(b == 'a');
BOOST_TEST(c == foo(3));
FUSION_TIE(a, ignore, c) = FUSION_MAKE((short int)5, false, foo(5));
BOOST_TEST(a == 5);
BOOST_TEST(b == 'a');
BOOST_TEST(c == foo(5));
int i, j;
FUSION_TIE(i, j) = FUSION_MAKE(1, 2);
BOOST_TEST(i == 1 && j == 2);
FUSION_SEQUENCE<int, int, float> ta;
#if defined(FUSION_TEST_FAIL)
ta = std::FUSION_MAKE(1, 2); // should fail, tuple is of length 3, not 2
#endif
dummy(ta);
// ties cannot be rebound
int d = 3;
FUSION_SEQUENCE<int&> ti(a);
BOOST_TEST(&FUSION_AT<0>(ti) == &a);
ti = FUSION_SEQUENCE<int&>(d);
BOOST_TEST(&FUSION_AT<0>(ti) == &a);
}

View File

@ -0,0 +1,102 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/sequence/view/transform_view/transform_view.hpp>
#include <boost/fusion/sequence/intrinsic/begin.hpp>
#include <boost/fusion/iterator/next.hpp>
#include <boost/fusion/iterator/prior.hpp>
#include <boost/fusion/iterator/advance.hpp>
#include <boost/fusion/iterator/deref.hpp>
#include <boost/fusion/iterator/distance.hpp>
#include <boost/mpl/range_c.hpp>
struct square
{
template <typename T>
struct result
{
typedef int type;
};
template <typename T>
int operator()(T x) const
{
return x * x;
}
};
struct add
{
template <typename A, typename B>
struct result
{
typedef int type;
};
template <typename A, typename B>
int operator()(A a, B b) const
{
return a + b;
}
};
int
main()
{
using namespace boost::fusion;
std::cout << tuple_open('[');
std::cout << tuple_close(']');
std::cout << tuple_delimiter(", ");
/// Testing the transform_view
{
typedef boost::mpl::range_c<int, 5, 9> sequence_type;
sequence_type sequence;
square sq;
typedef transform_view<sequence_type, square> xform_type;
xform_type xform(sequence, sq);
std::cout << xform << std::endl;
BOOST_TEST((xform == make_vector(25, 36, 49, 64)));
typedef boost::fusion::result_of::begin<xform_type>::type first_type;
first_type first_it(boost::fusion::begin(xform));
typedef boost::fusion::result_of::next<first_type>::type next_type;
next_type next_it(boost::fusion::next(first_it));
BOOST_TEST((*next_it == 36));
BOOST_TEST((*boost::fusion::prior(next_it) == 25));
BOOST_TEST((boost::fusion::distance(first_it, next_it) == 1));
BOOST_TEST((*boost::fusion::advance_c<3>(boost::fusion::begin(xform)) == 64));
}
{
typedef boost::mpl::range_c<int, 5, 9> sequence1_type;
typedef boost::mpl::range_c<int, 10, 14> sequence2_type;
sequence1_type sequence1;
sequence2_type sequence2;
add f;
typedef transform_view<sequence1_type, sequence2_type, add> xform_type;
xform_type xform(sequence1, sequence2, f);
std::cout << xform << std::endl;
BOOST_TEST((xform == make_vector(15, 17, 19, 21)));
}
return boost::report_errors();
}

View File

@ -0,0 +1,21 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/fusion/tuple/tuple.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#define FUSION_SEQUENCE tuple
#include "comparison.hpp"
int
main()
{
equality_test();
ordering_test();
return boost::report_errors();
}

View File

@ -0,0 +1,21 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/fusion/tuple/tuple.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#define FUSION_SEQUENCE tuple
#define FUSION_AT get
#include "construction.hpp"
int
main()
{
test();
return boost::report_errors();
}

View File

@ -0,0 +1,23 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/fusion/tuple.hpp>
#define FUSION_SEQUENCE tuple
#define FUSION_AT get
#define FUSION_MAKE make_tuple
#define FUSION_TIE tie
#include "copy.hpp"
int
main()
{
test();
return boost::report_errors();
}

View File

@ -0,0 +1,22 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/fusion/tuple.hpp>
#define FUSION_SEQUENCE tuple
#define FUSION_AT get
#define FUSION_VALUE_AT(S, N) tuple_element<N, S>
#include "value_at.hpp"
int
main()
{
test();
return boost::report_errors();
}

View File

@ -0,0 +1,22 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/fusion/tuple.hpp>
#define FUSION_SEQUENCE tuple
#define FUSION_AT get
#define FUSION_MAKE make_tuple
#include "make.hpp"
int
main()
{
test();
return boost::report_errors();
}

View File

@ -0,0 +1,22 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/fusion/tuple.hpp>
#define FUSION_SEQUENCE tuple
#define FUSION_AT get
#define FUSION_SIZE tuple_size
#include "misc.hpp"
int
main()
{
test();
return boost::report_errors();
}

View File

@ -0,0 +1,21 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/fusion/tuple.hpp>
#define FUSION_SEQUENCE tuple
#define FUSION_AT get
#include "mutate.hpp"
int
main()
{
test();
return boost::report_errors();
}

View File

@ -0,0 +1,23 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/fusion/tuple.hpp>
#define FUSION_SEQUENCE tuple
#define FUSION_AT get
#define FUSION_MAKE make_tuple
#define FUSION_TIE tie
#include "tie.hpp"
int
main()
{
test();
return boost::report_errors();
}

View File

@ -0,0 +1,228 @@
//
// Copyright (c) 2006 João Abecasis
//
// 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)
//
#include <boost/fusion/sequence/utility/unpack_args.hpp>
#include <boost/fusion/sequence/container/vector.hpp>
#include <boost/fusion/sequence/container/list.hpp>
#include <boost/fusion/sequence/intrinsic/size.hpp>
#include <boost/mpl/int.hpp>
#include <boost/noncopyable.hpp>
#include <boost/detail/lightweight_test.hpp>
namespace fusion = boost::fusion;
////////////////////////////////////////////////////////////////////////////////
//
// Helper stuff
//
struct object {};
struct nc_object : boost::noncopyable {};
template <class T>
inline T const & const_(T const & t)
{
return t;
}
////////////////////////////////////////////////////////////////////////////////
//
// Test functoids
//
// polymorphic functors
struct foo
{
typedef int result_type;
int operator()() { return 0; }
int operator()() const { return 1; }
int operator()(int i) { return 2 + i; }
int operator()(int i) const { return 3 + i; }
int operator()(int i, object &) { return 4 + i; }
int operator()(int i, object &) const { return 5 + i; }
int operator()(int i, object const &) { return 6 + i; }
int operator()(int i, object const &) const { return 7 + i; }
int operator()(int i, object &, nc_object &) { return 10 + i; }
int operator()(int i, object &, nc_object &) const { return 11 + i; }
};
struct nc_foo
: boost::noncopyable
{
typedef int result_type;
int operator()() { return 0; }
int operator()() const { return 1; }
int operator()(int i) { return 2 + i; }
int operator()(int i) const { return 3 + i; }
};
// nullary function
int bar() { return 20; }
// unary function
int square(int i) { return i * i; }
// binary functions
int baz1(int i, object &) { return 30 + i; }
int baz2(int i, object const &) { return 70 + i; }
// cv-qualified unary function pointers
typedef int (* func_ptr)(int);
typedef int (* const c_func_ptr)(int);
typedef int (* volatile v_func_ptr)(int);
typedef int (* const volatile cv_func_ptr)(int);
func_ptr func_ptr1 = &square;
c_func_ptr func_ptr2 = &square;
v_func_ptr func_ptr3 = &square;
cv_func_ptr func_ptr4 = &square;
////////////////////////////////////////////////////////////////////////////////
//
// Test data
//
typedef int element1_type;
typedef object element2_type;
typedef nc_object & element3_type;
int element1 = 100;
object element2 = object();
nc_object element3;
////////////////////////////////////////////////////////////////////////////////
//
// Tests (by sequence size)
//
template <class Sequence>
void test_sequence_n(Sequence & seq, boost::mpl::int_<0>)
{
{
foo f;
BOOST_TEST( f () == fusion::unpack_args( f , seq ));
BOOST_TEST(const_(f)() == fusion::unpack_args(const_(f), seq ));
BOOST_TEST( f () == fusion::unpack_args( f , const_(seq)));
BOOST_TEST(const_(f)() == fusion::unpack_args(const_(f), const_(seq)));
}
{
nc_foo nc_f;
BOOST_TEST( nc_f () == fusion::unpack_args( nc_f , seq ));
BOOST_TEST(const_(nc_f)() == fusion::unpack_args(const_(nc_f), seq ));
BOOST_TEST( nc_f () == fusion::unpack_args( nc_f , const_(seq)));
BOOST_TEST(const_(nc_f)() == fusion::unpack_args(const_(nc_f), const_(seq)));
}
BOOST_TEST(bar() == fusion::unpack_args(bar, seq));
}
template <class Sequence>
void test_sequence_n(Sequence & seq, boost::mpl::int_<1>)
{
{
foo f;
BOOST_TEST( f (element1) == fusion::unpack_args( f , seq ));
BOOST_TEST(const_(f)(element1) == fusion::unpack_args(const_(f), seq ));
BOOST_TEST( f (element1) == fusion::unpack_args( f , const_(seq)));
BOOST_TEST(const_(f)(element1) == fusion::unpack_args(const_(f), const_(seq)));
}
{
nc_foo nc_f;
BOOST_TEST( nc_f (element1) == fusion::unpack_args( nc_f , seq ));
BOOST_TEST(const_(nc_f)(element1) == fusion::unpack_args(const_(nc_f), seq ));
BOOST_TEST( nc_f (element1) == fusion::unpack_args( nc_f , const_(seq)));
BOOST_TEST(const_(nc_f)(element1) == fusion::unpack_args(const_(nc_f), const_(seq)));
}
BOOST_TEST(square(element1) == fusion::unpack_args(square, seq));
BOOST_TEST(func_ptr1(element1) == fusion::unpack_args(func_ptr1, seq));
BOOST_TEST(func_ptr2(element1) == fusion::unpack_args(func_ptr2, seq));
BOOST_TEST(func_ptr3(element1) == fusion::unpack_args(func_ptr3, seq));
BOOST_TEST(func_ptr4(element1) == fusion::unpack_args(func_ptr4, seq));
}
template <class Sequence>
void test_sequence_n(Sequence & seq, boost::mpl::int_<2>)
{
{
foo f;
BOOST_TEST( f (element1, element2) == fusion::unpack_args( f , seq));
BOOST_TEST(const_(f)(element1, element2) == fusion::unpack_args(const_(f), seq));
BOOST_TEST( f (const_(element1), element2) == fusion::unpack_args( f , const_(seq)));
BOOST_TEST(const_(f)(const_(element1), element2) == fusion::unpack_args(const_(f), const_(seq)));
}
BOOST_TEST(baz1(element1, element2) == fusion::unpack_args(baz1, seq));
BOOST_TEST(baz2(element1, element2) == fusion::unpack_args(baz2, seq));
}
template <class Sequence>
void test_sequence_n(Sequence & seq, boost::mpl::int_<3>)
{
foo f;
BOOST_TEST( f (element1, element2, element3) == fusion::unpack_args( f , seq));
BOOST_TEST(const_(f)(element1, element2, element3) == fusion::unpack_args(const_(f), seq));
}
////////////////////////////////////////////////////////////////////////////////
template <class Sequence>
void test_sequence(Sequence & seq)
{
test_sequence_n(seq, fusion::size(seq));
}
////////////////////////////////////////////////////////////////////////////////
int main()
{
typedef fusion::vector<> vector0;
typedef fusion::vector<element1_type> vector1;
typedef fusion::vector<element1_type, element2_type> vector2;
typedef fusion::vector<element1_type, element2_type, element3_type> vector3;
vector0 v0;
vector1 v1(element1);
vector2 v2(element1, element2);
vector3 v3(element1, element2, element3);
test_sequence(v0);
test_sequence(v1);
test_sequence(v2);
test_sequence(v3);
typedef fusion::list<> list0;
typedef fusion::list<element1_type> list1;
typedef fusion::list<element1_type, element2_type> list2;
typedef fusion::list<element1_type, element2_type, element3_type> list3;
list0 l0;
list1 l1(element1);
list2 l2(element1, element2);
list3 l3(element1, element2, element3);
test_sequence(l0);
test_sequence(l1);
test_sequence(l2);
test_sequence(l3);
}

View File

@ -0,0 +1,87 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/intrinsic/at.hpp>
#include <boost/fusion/sequence/intrinsic/value_at.hpp>
#include <boost/static_assert.hpp>
#include <iostream>
#if !defined(FUSION_AT)
#define FUSION_AT at_c
#endif
#if !defined(FUSION_VALUE_AT)
#define FUSION_VALUE_AT(S, N) result_of::value_at_c<S, N>
#endif
namespace
{
// something to prevent warnings for unused variables
template<class T> void dummy(const T&) {}
class A {};
}
void
test()
{
using namespace boost::fusion;
double d = 2.7;
A a;
FUSION_SEQUENCE<int, double&, const A&, int> t(1, d, a, 2);
const FUSION_SEQUENCE<int, double&, const A, int> ct(t);
int i = FUSION_AT<0>(t);
int i2 = FUSION_AT<3>(t);
BOOST_TEST(i == 1 && i2 == 2);
int j = FUSION_AT<0>(ct);
BOOST_TEST(j == 1);
FUSION_AT<0>(t) = 5;
BOOST_TEST(FUSION_AT<0>(t) == 5);
#if defined(FUSION_TEST_FAIL)
FUSION_AT<0>(ct) = 5; // can't assign to const
#endif
double e = FUSION_AT<1>(t);
BOOST_TEST(e > 2.69 && e < 2.71);
FUSION_AT<1>(t) = 3.14+i;
BOOST_TEST(FUSION_AT<1>(t) > 4.13 && FUSION_AT<1>(t) < 4.15);
#if defined(FUSION_TEST_FAIL)
FUSION_AT<4>(t) = A(); // can't assign to const
dummy(FUSION_AT<5>(ct)); // illegal index
#endif
++FUSION_AT<0>(t);
BOOST_TEST(FUSION_AT<0>(t) == 6);
typedef FUSION_SEQUENCE<int, float> seq_type;
BOOST_STATIC_ASSERT(!(
boost::is_const<FUSION_VALUE_AT(seq_type, 0)::type>::value));
// constness should not affect
BOOST_STATIC_ASSERT(!(
boost::is_const<FUSION_VALUE_AT(const seq_type, 0)::type>::value));
BOOST_STATIC_ASSERT(!(
boost::is_const<FUSION_VALUE_AT(seq_type, 1)::type>::value));
// constness should not affect
BOOST_STATIC_ASSERT(!(
boost::is_const<FUSION_VALUE_AT(const seq_type, 1)::type>::value));
dummy(i); dummy(i2); dummy(j); dummy(e); // avoid warns for unused variables
}

View File

@ -0,0 +1,20 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/fusion/sequence/container/vector/vector.hpp>
#define FUSION_SEQUENCE vector
#include "comparison.hpp"
int
main()
{
equality_test();
ordering_test();
return boost::report_errors();
}

View File

@ -0,0 +1,19 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/fusion/sequence/container/vector/vector.hpp>
#define FUSION_SEQUENCE vector
#include "construction.hpp"
int
main()
{
test();
return boost::report_errors();
}

View File

@ -0,0 +1,22 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/sequence/generation/vector_tie.hpp>
#define FUSION_SEQUENCE vector
#include "copy.hpp"
int
main()
{
test();
return boost::report_errors();
}

View File

@ -0,0 +1,23 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/container/vector/vector_iterator.hpp>
#define FUSION_SEQUENCE vector
#define FUSION_TRAVERSAL_TAG random_access_traversal_tag
#include "./iterator.hpp"
int
main()
{
test();
return boost::report_errors();
}

View File

@ -0,0 +1,21 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#define FUSION_SEQUENCE vector
#include "make.hpp"
int
main()
{
test();
return boost::report_errors();
}

View File

@ -0,0 +1,20 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/fusion/sequence/container/vector/vector.hpp>
#define FUSION_SEQUENCE vector
#include "misc.hpp"
int
main()
{
test();
return boost::report_errors();
}

View File

@ -0,0 +1,20 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/fusion/sequence/container/vector/vector.hpp>
#define FUSION_SEQUENCE vector
#include "mutate.hpp"
int
main()
{
test();
return boost::report_errors();
}

231
test/sequence/vector_n.cpp Normal file
View File

@ -0,0 +1,231 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/sequence/container/vector/vector10.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/fusion/sequence/intrinsic/size.hpp>
#include <boost/fusion/sequence/intrinsic/at.hpp>
#include <boost/fusion/sequence/intrinsic/value_at.hpp>
#include <boost/fusion/sequence/container/vector/vector20.hpp>
#include <boost/fusion/sequence/container/vector/vector30.hpp>
#include <boost/fusion/sequence/container/vector/vector40.hpp>
#include <boost/fusion/sequence/container/vector/vector50.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/static_assert.hpp>
#include <iostream>
#include <boost/fusion/algorithm/transformation/push_back.hpp>
#include <boost/mpl/vector_c.hpp>
int
main()
{
using namespace boost::fusion;
using namespace boost;
using namespace std;
{
vector0 vec;
(void) vec;
cout << "(): " << sizeof(vec) << endl;
}
{
typedef vector1<int> type;
type vec;
BOOST_STATIC_ASSERT(result_of::size<type>::value == 1);
BOOST_TEST(at_c<0>(vec) == 0);
BOOST_STATIC_ASSERT((is_same<int, result_of::value_at_c<type, 0>::type>::value));
// prove that it is mutable
at_c<0>(vec) = 987;
BOOST_TEST(at_c<0>(vec) == 987);
}
{
typedef vector1<int> type;
type vec(123);
BOOST_TEST(at_c<0>(vec) == 123);
cout << "(int): " << sizeof(vec) << endl;
}
{ // testing const vector
vector1<short> const vec(999);
BOOST_TEST(at_c<0>(vec) == 999);
#ifdef FUSION_TEST_COMPILE_FAIL
at_c<0>(vec) = 321;
#endif
}
{
vector1<int> t1(123L); // try conversion from long to int
vector1<double> t2(t1); // try copy
(void)t2;
}
{
typedef vector2<int, char> type;
type vec;
BOOST_STATIC_ASSERT(result_of::size<type>::value == 2);
BOOST_TEST(at_c<0>(vec) == 0);
BOOST_TEST(at_c<1>(vec) == char());
BOOST_STATIC_ASSERT((is_same<int, result_of::value_at_c<type, 0>::type>::value));
BOOST_STATIC_ASSERT((is_same<char, result_of::value_at_c<type, 1>::type>::value));
}
{
typedef vector2<int, char> type;
type vec(123, 'x');
BOOST_TEST(at_c<0>(vec) == 123);
BOOST_TEST(at_c<1>(vec) == 'x');
cout << "(int, char): " << sizeof(vec) << endl;
}
{
vector2<int, int> t1(123, 456);
vector2<double, float> t2(t1);
(void)t2;
}
{
typedef vector3<int, char, double> type;
type vec;
BOOST_STATIC_ASSERT(result_of::size<type>::value == 3);
BOOST_TEST(at_c<0>(vec) == 0);
BOOST_TEST(at_c<1>(vec) == char());
BOOST_TEST(at_c<2>(vec) == double());
BOOST_STATIC_ASSERT((is_same<int, result_of::value_at_c<type, 0>::type>::value));
BOOST_STATIC_ASSERT((is_same<char, result_of::value_at_c<type, 1>::type>::value));
BOOST_STATIC_ASSERT((is_same<double, result_of::value_at_c<type, 2>::type>::value));
}
{
typedef vector3<int, char, double> type;
type vec(123, 'x', 123.456);
BOOST_TEST(at_c<0>(vec) == 123);
BOOST_TEST(at_c<1>(vec) == 'x');
BOOST_TEST(at_c<2>(vec) >= 123.455 && at_c<2>(vec) <= 123.457);
cout << "(int, char, double): " << sizeof(vec) << endl;
}
{
typedef vector4<int, char, double, bool> type;
type vec(123, 'x', 123.456, true);
cout << "(int, char, double, bool): " << sizeof(vec) << endl;
}
{
typedef vector4<int, char, bool, double> type;
type vec(123, 'x', true, 123.456);
cout << "(int, char, bool, double): " << sizeof(vec) << endl;
}
{
typedef vector7<bool, char, short, int, long, float, double> type;
type vec(false, 'x', 3, 4, 5, 6.0, 7.0);
BOOST_TEST(at_c<0>(vec) == false);
BOOST_TEST(at_c<1>(vec) == 'x');
BOOST_TEST(at_c<2>(vec) == 3);
BOOST_TEST(at_c<3>(vec) == 4);
BOOST_TEST(at_c<4>(vec) == 5);
BOOST_TEST(at_c<5>(vec) >= 5.9 && at_c<5>(vec) <= 6.1);
BOOST_TEST(at_c<6>(vec) >= 6.9 && at_c<6>(vec) <= 7.1);
BOOST_STATIC_ASSERT((is_same<bool, result_of::value_at_c<type, 0>::type>::value));
BOOST_STATIC_ASSERT((is_same<char, result_of::value_at_c<type, 1>::type>::value));
BOOST_STATIC_ASSERT((is_same<short, result_of::value_at_c<type, 2>::type>::value));
BOOST_STATIC_ASSERT((is_same<int, result_of::value_at_c<type, 3>::type>::value));
BOOST_STATIC_ASSERT((is_same<long, result_of::value_at_c<type, 4>::type>::value));
BOOST_STATIC_ASSERT((is_same<float, result_of::value_at_c<type, 5>::type>::value));
BOOST_STATIC_ASSERT((is_same<double, result_of::value_at_c<type, 6>::type>::value));
cout << "(bool, char, short, int, long, float, double): " << sizeof(vec) << endl;
}
{
typedef vector10<int, int, int, int, int, int, int, int, int, int> type;
type vec; // compile check only
cout << "vector10 of int: " << sizeof(vec) << endl;
}
{
typedef vector20<
int, int, int, int, int, int, int, int, int, int
, int, int, int, int, int, int, int, int, int, int> type;
type vec; // compile check only
cout << "vector20 of int: " << sizeof(vec) << endl;
}
{
typedef vector30<
int, int, int, int, int, int, int, int, int, int
, int, int, int, int, int, int, int, int, int, int
, int, int, int, int, int, int, int, int, int, int> type;
type vec; // compile check only
cout << "vector30 of int: " << sizeof(vec) << endl;
}
{
typedef vector40<
int, int, int, int, int, int, int, int, int, int
, int, int, int, int, int, int, int, int, int, int
, int, int, int, int, int, int, int, int, int, int
, int, int, int, int, int, int, int, int, int, int> type;
type vec; // compile check only
cout << "vector40 of int: " << sizeof(vec) << endl;
}
{
typedef vector50<
int, int, int, int, int, int, int, int, int, int
, int, int, int, int, int, int, int, int, int, int
, int, int, int, int, int, int, int, int, int, int
, int, int, int, int, int, int, int, int, int, int
, int, int, int, int, int, int, int, int, int, int> type;
type vec; // compile check only
cout << "vector50 of int: " << sizeof(vec) << endl;
}
{
// testing copy and assign from a view
vector0 empty;
fusion::vector2<int, long> v(fusion::push_back(fusion::push_back(empty, 123), 456));
BOOST_TEST(at_c<0>(v) == 123);
BOOST_TEST(at_c<1>(v) == 456);
v = fusion::push_back(fusion::push_back(empty, 123), 456); // test assign
BOOST_TEST(at_c<0>(v) == 123);
BOOST_TEST(at_c<1>(v) == 456);
}
{
// testing copy and assign from a vector_c
mpl::vector_c<int, 123, 456> vec_c;
fusion::vector2<int, long> v(vec_c);
BOOST_TEST(at_c<0>(v) == 123);
BOOST_TEST(at_c<1>(v) == 456);
v = mpl::vector_c<int, 123, 456>(); // test assign
BOOST_TEST(at_c<0>(v) == 123);
BOOST_TEST(at_c<1>(v) == 456);
}
return boost::report_errors();
}

View File

@ -0,0 +1,23 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/fusion/sequence/container/vector/vector.hpp>
#include <boost/fusion/sequence/generation/vector_tie.hpp>
#include <boost/fusion/sequence/generation/ignore.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#define FUSION_SEQUENCE vector
#include "tie.hpp"
int
main()
{
test();
return boost::report_errors();
}

View File

@ -0,0 +1,20 @@
/*=============================================================================
Copyright (c) 1999-2003 Jaakko J<>rvi
Copyright (c) 2001-2006 Joel de Guzman
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/fusion/sequence/container/vector/vector.hpp>
#define FUSION_SEQUENCE vector
#include "value_at.hpp"
int
main()
{
test();
return boost::report_errors();
}

View File

@ -0,0 +1,88 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Copyright (c) 2006 Dan Marsden
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/support/category_of.hpp>
#include <boost/fusion/sequence/view/zip_view.hpp>
#include <boost/fusion/sequence/container/vector.hpp>
#include <boost/fusion/sequence/container/list.hpp>
#include <boost/fusion/sequence/intrinsic/size.hpp>
#include <boost/fusion/sequence/intrinsic/at.hpp>
#include <boost/fusion/sequence/intrinsic/front.hpp>
#include <boost/fusion/sequence/intrinsic/back.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/sequence/comparison/equal_to.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/equal_to.hpp>
#include <boost/mpl/vector_c.hpp>
#include <boost/type_traits/is_reference.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/static_assert.hpp>
int main()
{
using namespace boost::fusion;
{
typedef vector2<int,int> int_vector;
typedef vector2<char,char> char_vector;
typedef vector<int_vector&, char_vector&> seqs_type;
typedef zip_view<seqs_type> view;
BOOST_MPL_ASSERT((boost::mpl::equal_to<boost::fusion::result_of::size<view>::type, boost::fusion::result_of::size<int_vector>::type>));
BOOST_STATIC_ASSERT((boost::fusion::result_of::size<view>::value == 2));
int_vector iv(1,2);
char_vector cv('a', 'b');
seqs_type seqs(iv, cv);
view v(seqs);
BOOST_TEST(at_c<0>(v) == make_vector(1, 'a'));
BOOST_TEST(at_c<1>(v) == make_vector(2, 'b'));
BOOST_TEST(front(v) == make_vector(1, 'a'));
BOOST_TEST(back(v) == make_vector(2, 'b'));
BOOST_TEST(*next(begin(v)) == make_vector(2, 'b'));
BOOST_TEST(*prior(end(v)) == make_vector(2, 'b'));
BOOST_TEST(advance_c<2>(begin(v)) == end(v));
BOOST_TEST(advance_c<-2>(end(v)) == begin(v));
BOOST_TEST(distance(begin(v), end(v)) == 2);
BOOST_STATIC_ASSERT((boost::fusion::result_of::distance<boost::fusion::result_of::begin<view>::type, boost::fusion::result_of::end<view>::type>::value == 2));
BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_at_c<view,0>::type, vector<int,char> >));
BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_of<boost::fusion::result_of::begin<view>::type>::type, vector<int,char> >));
}
{
using namespace boost;
typedef mpl::vector2<int,bool> v1_type;
typedef mpl::vector2<char,long> v2_type;
typedef fusion::vector<v1_type&, v2_type&> seqs_type;
typedef fusion::zip_view<seqs_type> view;
v1_type v1;
v2_type v2;
seqs_type seqs(v1,v2);
view v(seqs);
BOOST_TEST((fusion::at_c<0>(v) == mpl::vector2<int,char>()));
BOOST_TEST((fusion::at_c<1>(v) == mpl::vector2<bool,long>()));
BOOST_TEST((fusion::front(v) == mpl::vector2<int,char>()));
BOOST_TEST((fusion::back(v) == mpl::vector2<bool,long>()));
BOOST_TEST((*fusion::next(fusion::begin(v)) == mpl::vector2<bool,long>()));
BOOST_TEST((*fusion::prior(fusion::end(v)) == mpl::vector2<bool,long>()));
BOOST_TEST(fusion::advance_c<2>(fusion::begin(v)) == fusion::end(v));
BOOST_TEST(fusion::advance_c<-2>(fusion::end(v)) == fusion::begin(v));
BOOST_TEST(fusion::distance(fusion::begin(v), fusion::end(v)) == 2);
}
return boost::report_errors();
}

View File

@ -0,0 +1,65 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Copyright (c) 2006 Dan Marsden
Use, modification and distribution is subject to 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)
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/support/category_of.hpp>
#include <boost/fusion/sequence/view/zip_view.hpp>
#include <boost/fusion/sequence/container/vector.hpp>
#include <boost/fusion/sequence/container/list.hpp>
#include <boost/fusion/sequence/intrinsic/size.hpp>
#include <boost/fusion/sequence/intrinsic/at.hpp>
#include <boost/fusion/sequence/intrinsic/front.hpp>
#include <boost/fusion/sequence/intrinsic/back.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/sequence/comparison/equal_to.hpp>
#include <boost/fusion/sequence/generation/make_vector.hpp>
#include <boost/fusion/sequence/adapted/mpl.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/equal_to.hpp>
#include <boost/type_traits/is_reference.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/static_assert.hpp>
int main()
{
{
using namespace boost::fusion;
typedef vector2<int,int> int_vector;
typedef vector2<char,char> char_vector;
typedef list<char,char> char_list;
typedef vector<int_vector&, char_vector&, char_list&> seqs_type;
typedef zip_view<seqs_type> view;
BOOST_MPL_ASSERT((boost::mpl::equal_to<boost::fusion::result_of::size<view>::type, boost::fusion::result_of::size<int_vector>::type>));
BOOST_STATIC_ASSERT((boost::fusion::result_of::size<view>::value == 2));
int_vector iv(1,2);
char_vector cv('a', 'b');
char_list cl('y','z');
seqs_type seqs(iv, cv, cl);
view v(seqs);
BOOST_TEST(at_c<0>(v) == make_vector(1, 'a', 'y'));
BOOST_TEST(at_c<1>(v) == make_vector(2, 'b', 'z'));
BOOST_TEST(front(v) == make_vector(1, 'a', 'y'));
BOOST_TEST(*next(begin(v)) == make_vector(2, 'b', 'z'));
BOOST_TEST(advance_c<2>(begin(v)) == end(v));
BOOST_TEST(distance(begin(v), end(v)) == 2);
BOOST_STATIC_ASSERT((boost::fusion::result_of::distance<boost::fusion::result_of::begin<view>::type, boost::fusion::result_of::end<view>::type>::value == 2));
BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_at_c<view,0>::type, vector<int,char,char> >));
BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_of<boost::fusion::result_of::begin<view>::type>::type, vector<int,char,char> >));
}
return boost::report_errors();
}