forked from boostorg/fusion
Full merge from trunk at revision 41356 of entire boost-root tree.
[SVN r41370]
This commit is contained in:
58
test/algorithm/all.cpp
Normal file
58
test/algorithm/all.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
Copyright (c) 2007 Dan Marsden
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/adapted/mpl.hpp>
|
||||
#include <boost/fusion/algorithm/query/all.hpp>
|
||||
#include <boost/lambda/lambda.hpp>
|
||||
#include <boost/mpl/vector_c.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
struct search_for
|
||||
{
|
||||
explicit search_for(int search)
|
||||
: search(search)
|
||||
{}
|
||||
|
||||
template<typename T>
|
||||
bool operator()(T const& v) const
|
||||
{
|
||||
return v == search;
|
||||
}
|
||||
|
||||
int search;
|
||||
};
|
||||
}
|
||||
|
||||
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> mpl_vec;
|
||||
// We cannot use lambda here as mpl vec iterators return
|
||||
// rvalues, and lambda needs lvalues.
|
||||
BOOST_TEST(boost::fusion::all(mpl_vec(), search_for(1)));
|
||||
BOOST_TEST(!boost::fusion::all(mpl_vec(), search_for(2)));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
57
test/algorithm/any.cpp
Normal file
57
test/algorithm/any.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
Copyright (c) 2005 Eric Niebler
|
||||
Copyright (c) Dan Marsden
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/adapted/mpl.hpp>
|
||||
#include <boost/fusion/algorithm/query/any.hpp>
|
||||
#include <boost/lambda/lambda.hpp>
|
||||
#include <boost/mpl/vector_c.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
struct search_for
|
||||
{
|
||||
explicit search_for(int search)
|
||||
: search(search)
|
||||
{}
|
||||
|
||||
template<typename T>
|
||||
bool operator()(T const& v) const
|
||||
{
|
||||
return v == search;
|
||||
}
|
||||
|
||||
int search;
|
||||
};
|
||||
}
|
||||
|
||||
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;
|
||||
// We cannot use lambda here as mpl vec iterators return
|
||||
// rvalues, and lambda needs lvalues.
|
||||
BOOST_TEST(boost::fusion::any(mpl_vec(), search_for(2)));
|
||||
BOOST_TEST(!boost::fusion::any(mpl_vec(), search_for(4)));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
45
test/algorithm/clear.cpp
Normal file
45
test/algorithm/clear.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/sequence/io/out.hpp>
|
||||
#include <boost/fusion/sequence/comparison/equal_to.hpp>
|
||||
#include <boost/fusion/container/generation/make_vector.hpp>
|
||||
#include <boost/fusion/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();
|
||||
}
|
||||
|
41
test/algorithm/count.cpp
Normal file
41
test/algorithm/count.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
Copyright (c) 2005 Eric Niebler
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/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();
|
||||
}
|
||||
|
38
test/algorithm/count_if.cpp
Normal file
38
test/algorithm/count_if.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
Copyright (c) 2005 Eric Niebler
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/adapted/mpl.hpp>
|
||||
#include <boost/fusion/algorithm/query/count_if.hpp>
|
||||
#include <boost/lambda/lambda.hpp>
|
||||
#include <boost/mpl/vector_c.hpp>
|
||||
#include <functional>
|
||||
|
||||
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;
|
||||
// Cannot use lambda here as mpl iterators return rvalues and lambda needs lvalues
|
||||
BOOST_TEST(boost::fusion::count_if(mpl_vec(), std::bind2nd(std::less_equal<int>(), 2)) == 2);
|
||||
BOOST_TEST(boost::fusion::count_if(mpl_vec(), std::bind2nd(std::greater<int>(), 2)) == 1);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
63
test/algorithm/erase.cpp
Normal file
63
test/algorithm/erase.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/container/vector/vector_iterator.hpp>
|
||||
#include <boost/fusion/adapted/mpl.hpp>
|
||||
#include <boost/fusion/sequence/io/out.hpp>
|
||||
#include <boost/fusion/sequence/comparison/equal_to.hpp>
|
||||
#include <boost/fusion/container/generation/make_vector.hpp>
|
||||
#include <boost/fusion/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();
|
||||
}
|
||||
|
74
test/algorithm/erase_key.cpp
Normal file
74
test/algorithm/erase_key.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/set/set.hpp>
|
||||
#include <boost/fusion/container/generation/make_set.hpp>
|
||||
#include <boost/fusion/container/map/map.hpp>
|
||||
#include <boost/fusion/container/generation/make_map.hpp>
|
||||
#include <boost/fusion/sequence/comparison/equal_to.hpp>
|
||||
#include <boost/fusion/container/vector/convert.hpp>
|
||||
#include <boost/fusion/container/set/convert.hpp>
|
||||
#include <boost/fusion/container/map/convert.hpp>
|
||||
#include <boost/fusion/container/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();
|
||||
}
|
||||
|
109
test/algorithm/ext_/find_if_s.cpp
Executable file
109
test/algorithm/ext_/find_if_s.cpp
Executable file
@ -0,0 +1,109 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/adapted/mpl.hpp>
|
||||
#include <boost/fusion/sequence/io/out.hpp>
|
||||
#include <boost/fusion/algorithm/query/ext_/find_if_s.hpp>
|
||||
#include <boost/fusion/container/ext_/tree.hpp>
|
||||
#include <boost/fusion/container/generation/make_vector.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;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Tree>
|
||||
void
|
||||
process_tree(Tree const &tree)
|
||||
{
|
||||
using namespace boost;
|
||||
using mpl::_;
|
||||
|
||||
typedef typename fusion::result_of::find_if_s<Tree const, is_same<_,short> >::type short_iter;
|
||||
typedef typename fusion::result_of::find_if_s<Tree const, is_same<_,float> >::type float_iter;
|
||||
|
||||
// find_if_s of a segmented data structure returns generic
|
||||
// segmented iterators
|
||||
short_iter si = fusion::find_if_s<is_same<_,short> >(tree);
|
||||
float_iter fi = fusion::find_if_s<is_same<_,float> >(tree);
|
||||
|
||||
// they behave like ordinary Fusion iterators ...
|
||||
BOOST_TEST((*si == short('d')));
|
||||
BOOST_TEST((*fi == float(1)));
|
||||
}
|
||||
|
||||
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_s<is_same<_, char> >(v) << std::endl;
|
||||
BOOST_TEST((*find_if_s<is_same<_, char> >(v) == 'x'));
|
||||
|
||||
std::cout << *find_if_s<is_same<_, int> >(v) << std::endl;
|
||||
BOOST_TEST((*find_if_s<is_same<_, int> >(v) == 12345));
|
||||
|
||||
std::cout << *find_if_s<is_same<_, double> >(v) << std::endl;
|
||||
BOOST_TEST((*find_if_s<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_s<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_s<less<_, int_<3> > >(mpl_vec()) == 1));
|
||||
}
|
||||
|
||||
{
|
||||
process_tree(
|
||||
make_tree(
|
||||
make_vector(double(0),'B')
|
||||
, make_tree(
|
||||
make_vector(1,2,long(3))
|
||||
, make_tree(make_vector('a','b','c'))
|
||||
, make_tree(make_vector(short('d'),'e','f'))
|
||||
)
|
||||
, make_tree(
|
||||
make_vector(4,5,6)
|
||||
, make_tree(make_vector(float(1),'h','i'))
|
||||
, make_tree(make_vector('j','k','l'))
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
82
test/algorithm/ext_/for_each_s.cpp
Executable file
82
test/algorithm/ext_/for_each_s.cpp
Executable file
@ -0,0 +1,82 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman, Eric Niebler
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/adapted/mpl.hpp>
|
||||
#include <boost/fusion/sequence/io/out.hpp>
|
||||
#include <boost/fusion/algorithm/iteration/ext_/for_each_s.hpp>
|
||||
#include <boost/mpl/vector_c.hpp>
|
||||
#include <boost/fusion/container/generation/make_vector.hpp>
|
||||
#include <boost/fusion/container/ext_/tree.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_s(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_s(v, increment());
|
||||
std::cout << v << std::endl;
|
||||
}
|
||||
|
||||
{
|
||||
typedef vector_c<int, 2, 3, 4, 5, 6> mpl_vec;
|
||||
fusion::for_each_s(mpl_vec(), print());
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
{
|
||||
fusion::for_each_s(
|
||||
make_tree(
|
||||
make_vector(double(0),'B')
|
||||
, make_tree(
|
||||
make_vector(1,2,long(3))
|
||||
, make_tree(make_vector('a','b','c'))
|
||||
, make_tree(make_vector(short('d'),'e','f'))
|
||||
)
|
||||
, make_tree(
|
||||
make_vector(4,5,6)
|
||||
, make_tree(make_vector(float(1),'h','i'))
|
||||
, make_tree(make_vector('j','k','l'))
|
||||
)
|
||||
)
|
||||
, print()
|
||||
);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
43
test/algorithm/filter.cpp
Normal file
43
test/algorithm/filter.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
Copyright (c) 2005-2006 Dan Marsden
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/adapted/mpl.hpp>
|
||||
#include <boost/fusion/sequence/io/out.hpp>
|
||||
#include <boost/fusion/container/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();
|
||||
}
|
||||
|
77
test/algorithm/filter_if.cpp
Normal file
77
test/algorithm/filter_if.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/adapted/mpl.hpp>
|
||||
#include <boost/fusion/sequence/io/out.hpp>
|
||||
#include <boost/fusion/container/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();
|
||||
}
|
||||
|
79
test/algorithm/find.cpp
Normal file
79
test/algorithm/find.cpp
Normal file
@ -0,0 +1,79 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/adapted/mpl.hpp>
|
||||
#include <boost/fusion/container/set/set.hpp>
|
||||
#include <boost/fusion/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();
|
||||
}
|
||||
|
69
test/algorithm/find_if.cpp
Normal file
69
test/algorithm/find_if.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/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();
|
||||
}
|
||||
|
222
test/algorithm/fold.cpp
Normal file
222
test/algorithm/fold.cpp
Normal file
@ -0,0 +1,222 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
Copyright (c) 2007 Dan Marsden
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/adapted/mpl.hpp>
|
||||
#include <boost/fusion/sequence/io/out.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/at.hpp>
|
||||
#include <boost/fusion/container/generation/make_vector.hpp>
|
||||
#include <boost/fusion/algorithm/iteration/fold.hpp>
|
||||
#include <boost/fusion/algorithm/iteration/accumulate.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>
|
||||
|
||||
#include <boost/type_traits/remove_const.hpp>
|
||||
#include <boost/type_traits/remove_reference.hpp>
|
||||
#include <boost/type_traits/is_reference.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
using boost::mpl::if_;
|
||||
using boost::mpl::int_;
|
||||
using boost::is_same;
|
||||
|
||||
struct add_ints_only
|
||||
{
|
||||
template<typename T>
|
||||
struct result;
|
||||
|
||||
template <typename T, typename State>
|
||||
struct result<add_ints_only(T,State)>
|
||||
{
|
||||
typedef typename boost::remove_const<
|
||||
typename boost::remove_reference<State>::type>::type type;
|
||||
};
|
||||
|
||||
template <typename T, typename State>
|
||||
State const&
|
||||
operator()(T const& x, State const& state) const
|
||||
{
|
||||
return state;
|
||||
}
|
||||
|
||||
int
|
||||
operator()(int x, int state) const
|
||||
{
|
||||
return x + state;
|
||||
}
|
||||
};
|
||||
|
||||
struct count_ints
|
||||
{
|
||||
template<typename T>
|
||||
struct result;
|
||||
|
||||
template <typename T, typename CountT>
|
||||
struct result<count_ints(T,CountT)>
|
||||
{
|
||||
typedef typename boost::remove_const<
|
||||
typename boost::remove_reference<T>::type>::type elem;
|
||||
typedef typename boost::remove_const<
|
||||
typename boost::remove_reference<CountT>::type>::type state;
|
||||
|
||||
typedef typename
|
||||
if_<
|
||||
is_same<elem, int>
|
||||
, typename boost::mpl::next<state>::type
|
||||
, state
|
||||
>::type
|
||||
type;
|
||||
};
|
||||
|
||||
template <typename T, typename CountT>
|
||||
typename result<count_ints(T, CountT)>::type
|
||||
operator()(T const&, CountT const&) const
|
||||
{
|
||||
typedef typename result<count_ints(T, CountT)>::type result;
|
||||
return result();
|
||||
}
|
||||
};
|
||||
|
||||
struct appender
|
||||
{
|
||||
typedef std::string result_type;
|
||||
|
||||
std::string operator()(char c, std::string const& str) const
|
||||
{
|
||||
return str + c;
|
||||
}
|
||||
};
|
||||
|
||||
struct lvalue_adder
|
||||
{
|
||||
template<typename Sig>
|
||||
struct result;
|
||||
|
||||
template<typename T0, typename T1>
|
||||
struct result<lvalue_adder(T0&, T1)>
|
||||
{
|
||||
// Second argument still needs to support rvalues - see definition of fusion::fold
|
||||
typedef T0 type;
|
||||
};
|
||||
|
||||
template<typename T0, typename T1>
|
||||
T0 operator()(T0& lhs, T1 const& rhs) const
|
||||
{
|
||||
return lhs + rhs;
|
||||
}
|
||||
};
|
||||
|
||||
int add(int lhs, int rhs)
|
||||
{
|
||||
return lhs + rhs;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_TEST(fusion::fold(fusion::make_vector('a','b','c','d','e'), std::string(""), appender())
|
||||
== "abcde");
|
||||
}
|
||||
|
||||
{
|
||||
vector<int, int> vec(1,2);
|
||||
BOOST_TEST(fusion::fold(vec, 0, lvalue_adder()) == 3);
|
||||
}
|
||||
|
||||
{
|
||||
vector<int, int> vec(1,2);
|
||||
BOOST_TEST(fusion::fold(vec, 0, add) == 3);
|
||||
}
|
||||
|
||||
{
|
||||
typedef vector<int, char, int, double> vector_type;
|
||||
vector_type v(12345, 'x', 678910, 3.36);
|
||||
int result = accumulate(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::accumulate(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::accumulate(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::accumulate(mpl_vec(), int_<0>(), count_ints());
|
||||
std::cout << n << std::endl;
|
||||
BOOST_TEST(n == 3);
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_TEST(fusion::accumulate(fusion::make_vector('a','b','c','d','e'), std::string(""), appender())
|
||||
== "abcde");
|
||||
}
|
||||
|
||||
{
|
||||
vector<int, int> vec(1,2);
|
||||
BOOST_TEST(fusion::accumulate(vec, 0, add) == 3);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
61
test/algorithm/for_each.cpp
Normal file
61
test/algorithm/for_each.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/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();
|
||||
}
|
||||
|
67
test/algorithm/insert.cpp
Normal file
67
test/algorithm/insert.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/adapted/mpl.hpp>
|
||||
#include <boost/fusion/sequence/io/out.hpp>
|
||||
#include <boost/fusion/sequence/comparison/equal_to.hpp>
|
||||
#include <boost/fusion/container/generation/make_vector.hpp>
|
||||
#include <boost/fusion/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();
|
||||
}
|
||||
|
71
test/algorithm/insert_range.cpp
Normal file
71
test/algorithm/insert_range.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/adapted/mpl.hpp>
|
||||
#include <boost/fusion/sequence/io/out.hpp>
|
||||
#include <boost/fusion/sequence/comparison/equal_to.hpp>
|
||||
#include <boost/fusion/container/generation/make_vector.hpp>
|
||||
#include <boost/fusion/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();
|
||||
}
|
||||
|
28
test/algorithm/join.cpp
Normal file
28
test/algorithm/join.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
Copyright (c) 2006 Dan Marsden
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/algorithm/transformation/join.hpp>
|
||||
#include <boost/fusion/container/generation/make_vector.hpp>
|
||||
#include <boost/fusion/sequence/comparison/equal_to.hpp>
|
||||
#include <boost/fusion/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();
|
||||
}
|
58
test/algorithm/none.cpp
Normal file
58
test/algorithm/none.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
Copyright (c) 2007 Dan Marsden
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/adapted/mpl.hpp>
|
||||
#include <boost/fusion/algorithm/query/none.hpp>
|
||||
#include <boost/lambda/lambda.hpp>
|
||||
#include <boost/mpl/vector_c.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
struct search_for
|
||||
{
|
||||
explicit search_for(int search)
|
||||
: search(search)
|
||||
{}
|
||||
|
||||
template<typename T>
|
||||
bool operator()(T const& v) const
|
||||
{
|
||||
return v == search;
|
||||
}
|
||||
|
||||
int search;
|
||||
};
|
||||
}
|
||||
|
||||
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;
|
||||
// We cannot use lambda here as mpl vec iterators return
|
||||
// rvalues, and lambda needs lvalues.
|
||||
BOOST_TEST(boost::fusion::none(mpl_vec(), search_for(4)));
|
||||
BOOST_TEST(!boost::fusion::none(mpl_vec(), search_for(3)));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
46
test/algorithm/pop_back.cpp
Normal file
46
test/algorithm/pop_back.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/adapted/mpl.hpp>
|
||||
#include <boost/fusion/sequence/io/out.hpp>
|
||||
#include <boost/fusion/sequence/comparison/equal_to.hpp>
|
||||
#include <boost/fusion/container/generation/make_vector.hpp>
|
||||
#include <boost/fusion/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();
|
||||
}
|
||||
|
46
test/algorithm/pop_front.cpp
Normal file
46
test/algorithm/pop_front.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/adapted/mpl.hpp>
|
||||
#include <boost/fusion/sequence/io/out.hpp>
|
||||
#include <boost/fusion/sequence/comparison/equal_to.hpp>
|
||||
#include <boost/fusion/container/generation/make_vector.hpp>
|
||||
#include <boost/fusion/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();
|
||||
}
|
||||
|
72
test/algorithm/push_back.cpp
Normal file
72
test/algorithm/push_back.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/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/container/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();
|
||||
}
|
||||
|
55
test/algorithm/push_front.cpp
Normal file
55
test/algorithm/push_front.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/adapted/mpl.hpp>
|
||||
#include <boost/fusion/sequence/io/out.hpp>
|
||||
#include <boost/fusion/sequence/comparison/equal_to.hpp>
|
||||
#include <boost/fusion/container/generation/make_vector.hpp>
|
||||
#include <boost/fusion/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();
|
||||
}
|
||||
|
80
test/algorithm/remove.cpp
Normal file
80
test/algorithm/remove.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/adapted/mpl.hpp>
|
||||
#include <boost/fusion/sequence/io/out.hpp>
|
||||
#include <boost/fusion/container/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();
|
||||
}
|
||||
|
78
test/algorithm/remove_if.cpp
Normal file
78
test/algorithm/remove_if.cpp
Normal file
@ -0,0 +1,78 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/adapted/mpl.hpp>
|
||||
#include <boost/fusion/sequence/io/out.hpp>
|
||||
#include <boost/fusion/container/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();
|
||||
}
|
||||
|
49
test/algorithm/replace.cpp
Normal file
49
test/algorithm/replace.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/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/container/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();
|
||||
}
|
||||
|
52
test/algorithm/replace_if.cpp
Normal file
52
test/algorithm/replace_if.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/adapted/mpl.hpp>
|
||||
#include <boost/fusion/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/container/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();
|
||||
}
|
||||
|
49
test/algorithm/reverse.cpp
Normal file
49
test/algorithm/reverse.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/adapted/mpl.hpp>
|
||||
#include <boost/fusion/sequence/io/out.hpp>
|
||||
#include <boost/fusion/container/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();
|
||||
}
|
||||
|
||||
|
157
test/algorithm/transform.cpp
Normal file
157
test/algorithm/transform.cpp
Normal file
@ -0,0 +1,157 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
Copyright (c) 2007 Dan Marsden
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/adapted/mpl.hpp>
|
||||
#include <boost/fusion/sequence/io/out.hpp>
|
||||
#include <boost/fusion/container/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 Sig>
|
||||
struct result;
|
||||
|
||||
template <typename T>
|
||||
struct result<square(T)>
|
||||
{
|
||||
typedef int type;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
int operator()(T x) const
|
||||
{
|
||||
return x * x;
|
||||
}
|
||||
};
|
||||
|
||||
struct add
|
||||
{
|
||||
template<typename Sig>
|
||||
struct result;
|
||||
|
||||
template <typename A, typename B>
|
||||
struct result<add(A, B)>
|
||||
{
|
||||
typedef int type;
|
||||
};
|
||||
|
||||
template <typename A, typename B>
|
||||
int operator()(A a, B b) const
|
||||
{
|
||||
return a + b;
|
||||
}
|
||||
};
|
||||
|
||||
struct unary_lvalue_transform
|
||||
{
|
||||
template<typename Sig>
|
||||
struct result;
|
||||
|
||||
template<typename T>
|
||||
struct result<unary_lvalue_transform(T&)>
|
||||
{
|
||||
typedef T* type;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
T* operator()(T& t) const
|
||||
{
|
||||
return &t;
|
||||
}
|
||||
};
|
||||
|
||||
int twice(int v)
|
||||
{
|
||||
return v*2;
|
||||
}
|
||||
|
||||
struct binary_lvalue_transform
|
||||
{
|
||||
template<typename Sig>
|
||||
struct result;
|
||||
|
||||
template<typename T0, typename T1>
|
||||
struct result<binary_lvalue_transform(T0&,T1&)>
|
||||
{
|
||||
typedef T0* type;
|
||||
};
|
||||
|
||||
template<typename T0, typename T1>
|
||||
T0* operator()(T0& t0, T1&) const
|
||||
{
|
||||
return &t0;
|
||||
}
|
||||
};
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
{
|
||||
// Unary transform that requires lvalues, just check compilation
|
||||
vector<int, int, int> tup1(1, 2, 3);
|
||||
BOOST_TEST(at_c<0>(transform(tup1, unary_lvalue_transform())) == &at_c<0>(tup1));
|
||||
BOOST_TEST(*begin(transform(tup1, unary_lvalue_transform())) == &at_c<0>(tup1));
|
||||
}
|
||||
|
||||
{
|
||||
vector<int, int, int> tup1(1, 2, 3);
|
||||
vector<int, int, int> tup2(4, 5, 6);
|
||||
BOOST_TEST(at_c<0>(transform(tup1, tup2, binary_lvalue_transform())) == &at_c<0>(tup1));
|
||||
BOOST_TEST(*begin(transform(tup1, tup2, binary_lvalue_transform())) == &at_c<0>(tup1));
|
||||
}
|
||||
|
||||
{
|
||||
vector<int, int, int> tup1(1, 2, 3);
|
||||
BOOST_TEST(transform(tup1, twice) == make_vector(2,4,6));
|
||||
}
|
||||
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
30
test/algorithm/zip.cpp
Normal file
30
test/algorithm/zip.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
Copyright (c) 2006 Dan Marsden
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/algorithm/transformation/zip.hpp>
|
||||
#include <boost/fusion/container/generation/make_vector.hpp>
|
||||
#include <boost/fusion/sequence/comparison/equal_to.hpp>
|
||||
#include <boost/fusion/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();
|
||||
}
|
30
test/algorithm/zip2.cpp
Normal file
30
test/algorithm/zip2.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2006 Joel de Guzman
|
||||
Copyright (c) 2006 Dan Marsden
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/algorithm/transformation/zip.hpp>
|
||||
#include <boost/fusion/sequence/comparison/equal_to.hpp>
|
||||
#include <boost/fusion/adapted/mpl.hpp>
|
||||
#include <boost/mpl/vector.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace boost::fusion;
|
||||
{
|
||||
const vector2<int,int> shorter(1,2);
|
||||
const vector3<char,char,char> longer('a', 'b', 'c');
|
||||
const vector2<vector2<int,char>, vector2<int,char> > result(vector2<int,char>(1,'a'), vector2<int,char>(2,'b'));
|
||||
BOOST_TEST(zip(shorter, longer) == result);
|
||||
}
|
||||
{
|
||||
const vector3<int,int,int> longer(1,2,3);
|
||||
const vector2<char,char> shorter('a', 'b');
|
||||
const vector2<vector2<int,char>, vector2<int,char> > result(vector2<int,char>(1,'a'), vector2<int,char>(2,'b'));
|
||||
BOOST_TEST(zip(longer, shorter) == result);
|
||||
}
|
||||
return boost::report_errors();
|
||||
}
|
28
test/algorithm/zip_ignore.cpp
Normal file
28
test/algorithm/zip_ignore.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2007 Joel de Guzman
|
||||
Copyright (c) 2007 Dan Marsden
|
||||
|
||||
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/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/vector.hpp>
|
||||
#include <boost/fusion/algorithm/transformation/zip.hpp>
|
||||
#include <boost/fusion/support/unused.hpp>
|
||||
#include <boost/fusion/iterator.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace boost::fusion;
|
||||
{
|
||||
vector<int, int> iv(1,2);
|
||||
vector<char, char> cv('a', 'b');
|
||||
BOOST_TEST(at_c<0>(at_c<0>(zip(iv, unused, cv))) == 1);
|
||||
BOOST_TEST(at_c<2>(at_c<0>(zip(iv, unused, cv))) == 'a');
|
||||
|
||||
BOOST_TEST(at_c<0>(at_c<1>(zip(iv, unused, cv))) == 2);
|
||||
BOOST_TEST(at_c<2>(at_c<1>(zip(iv, unused, cv))) == 'b');
|
||||
}
|
||||
return boost::report_errors();
|
||||
}
|
Reference in New Issue
Block a user