diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2013-06-25 22:59:01 +0000 |
---|---|---|
committer | <> | 2013-09-27 11:49:28 +0000 |
commit | 8c4528713d907ee2cfd3bfcbbad272c749867f84 (patch) | |
tree | c09e2ce80f47b90c85cc720f5139089ad9c8cfff /libs/fusion/test | |
download | boost-tarball-baserock/morph.tar.gz |
Imported from /home/lorry/working-area/delta_boost-tarball/boost_1_54_0.tar.bz2.boost_1_54_0baserock/morph
Diffstat (limited to 'libs/fusion/test')
160 files changed, 12066 insertions, 0 deletions
diff --git a/libs/fusion/test/Jamfile b/libs/fusion/test/Jamfile new file mode 100644 index 000000000..7e464575d --- /dev/null +++ b/libs/fusion/test/Jamfile @@ -0,0 +1,163 @@ +##============================================================================== +# 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 ; + +project + : requirements + ; + +{ + test-suite fusion : + + [ run algorithm/all.cpp : : : : ] + [ run algorithm/any.cpp : : : : ] + [ run algorithm/clear.cpp : : : : ] + [ run algorithm/copy.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/fold2.cpp : : : : ] + [ run algorithm/for_each.cpp : : : : ] + [ run algorithm/insert.cpp : : : : ] + [ run algorithm/insert_range.cpp : : : : ] + [ run algorithm/iter_fold.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_fold.cpp : : : : ] + [ run algorithm/reverse_iter_fold.cpp : : : : ] + [ run algorithm/reverse.cpp : : : : ] + [ run algorithm/segmented_for_each.cpp : : : : ] + [ run algorithm/segmented_find.cpp : : : : ] + [ run algorithm/segmented_find_if.cpp : : : : ] + [ run algorithm/segmented_fold.cpp : : : : ] + [ run algorithm/transform.cpp : : : : ] + [ run algorithm/join.cpp : : : : ] + [ run algorithm/zip.cpp : : : : ] + [ run algorithm/zip2.cpp : : : : ] + [ run algorithm/zip_ignore.cpp : : : : ] + + [ run sequence/as_list.cpp : : : : ] + [ run sequence/as_map.cpp : : : : ] + [ run sequence/as_set.cpp : : : : ] + [ run sequence/as_vector.cpp : : : : ] + [ run sequence/boost_tuple.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/deque_comparison.cpp : : : : ] + [ run sequence/deque_construction.cpp : : : : ] + [ run sequence/deque_copy.cpp : : : : ] + [ run sequence/deque_iterator.cpp : : : : ] + [ run sequence/deque_make.cpp : : : : ] + [ run sequence/deque_misc.cpp : : : : ] + [ run sequence/deque_move.cpp : : : : ] + [ run sequence/deque_mutate.cpp : : : : ] + [ run sequence/deque_tie.cpp : : : : ] + [ run sequence/deque_value_at.cpp : : : : ] + [ run sequence/front_extended_deque.cpp : : : : ] + [ run sequence/back_extended_deque.cpp : : : : ] + [ run sequence/make_list.cpp : : : : ] + [ run sequence/make_vector.cpp : : : : ] + [ run sequence/map.cpp : : : : ] + [ run sequence/map_tie.cpp : : : : ] + [ run sequence/nview.cpp : : : : ] + [ run sequence/reverse_view.cpp : : : : ] + [ run sequence/segmented_iterator_range.cpp : : : : ] + [ run sequence/set.cpp : : : : ] + [ run sequence/single_view.cpp : : : : ] + [ run sequence/std_pair.cpp : : : : ] + [ run sequence/boost_array.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/tr1_tuple_auto_conv.cpp : : : : ] + [ run sequence/transform_view.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_move.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 : : : : ] + [ run sequence/zip_view_ignore.cpp : : : : ] + [ run sequence/repetitive_view.cpp : : : : ] + [ run sequence/deduce_sequence.cpp : : : : ] + [ run sequence/adapt_adt_named.cpp : : : : ] + [ run sequence/adapt_adt.cpp : : : : ] + [ run sequence/adapt_assoc_adt_named.cpp : : : : ] + [ run sequence/adapt_assoc_adt.cpp : : : : ] + [ run sequence/adapt_assoc_struct_named.cpp : : : : ] + [ run sequence/adapt_assoc_struct.cpp : : : : ] + [ run sequence/adapt_assoc_tpl_adt.cpp : : : : ] + [ run sequence/adapt_assoc_tpl_struct.cpp : : : : ] + [ run sequence/adapt_struct_named.cpp : : : : ] + [ run sequence/adapt_struct.cpp : : : : ] + [ run sequence/adapt_tpl_adt.cpp : : : : ] + [ run sequence/adapt_tpl_struct.cpp : : : : ] + [ run sequence/adt_attribute_proxy.cpp : : : : ] + [ run sequence/define_struct.cpp : : : : ] + [ run sequence/define_assoc_struct.cpp : : : : ] + [ run sequence/define_tpl_struct.cpp : : : : ] + [ run sequence/define_assoc_tpl_struct.cpp : : : : ] + [ run sequence/std_tuple_iterator.cpp : : : : ] + + [ run functional/fused.cpp : : : : ] + [ run functional/fused_function_object.cpp : : : : ] + [ run functional/fused_procedure.cpp : : : : ] + [ run functional/unfused.cpp : : : : ] + [ run functional/unfused_typed.cpp : : : : ] + [ run functional/make_fused.cpp : : : : ] + [ run functional/make_fused_function_object.cpp : : : : ] + [ run functional/make_fused_procedure.cpp : : : : ] + [ run functional/make_unfused.cpp : : : : ] + [ run functional/invoke.cpp : : : : ] + [ run functional/invoke_function_object.cpp : : : : ] + [ run functional/invoke_procedure.cpp : : : : ] + [ run sequence/swap.cpp : : : : ] + +# [ compile-fail xxx.cpp : : : : ] + + ; +} diff --git a/libs/fusion/test/algorithm/all.cpp b/libs/fusion/test/algorithm/all.cpp new file mode 100644 index 000000000..7b5550732 --- /dev/null +++ b/libs/fusion/test/algorithm/all.cpp @@ -0,0 +1,70 @@ +/*============================================================================= + Copyright (c) 2001-2011 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 in_search) + : search(in_search) + {} + + template<typename T> + bool operator()(T const& v) const + { + return v == search; + } + + int search; + }; +} + +int +main() +{ + { + boost::fusion::vector<> t; + 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 < 4))); + BOOST_TEST((boost::fusion::all(t, boost::lambda::_1 > 0))); + } + + { + boost::fusion::vector<int, short, double, long> t(1, 2, 3.3, 2); + 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(); +} + diff --git a/libs/fusion/test/algorithm/any.cpp b/libs/fusion/test/algorithm/any.cpp new file mode 100644 index 000000000..da0aa7933 --- /dev/null +++ b/libs/fusion/test/algorithm/any.cpp @@ -0,0 +1,57 @@ +/*============================================================================= + Copyright (c) 2001-2011 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 in_search) + : search(in_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(); +} + diff --git a/libs/fusion/test/algorithm/clear.cpp b/libs/fusion/test/algorithm/clear.cpp new file mode 100644 index 000000000..f90f5c0a6 --- /dev/null +++ b/libs/fusion/test/algorithm/clear.cpp @@ -0,0 +1,45 @@ +/*============================================================================= + Copyright (c) 2001-2011 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(); +} + diff --git a/libs/fusion/test/algorithm/copy.cpp b/libs/fusion/test/algorithm/copy.cpp new file mode 100644 index 000000000..330caca62 --- /dev/null +++ b/libs/fusion/test/algorithm/copy.cpp @@ -0,0 +1,26 @@ +/*============================================================================= + Copyright (c) 2001-2011 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/list/list.hpp> +#include <boost/fusion/sequence/comparison.hpp> +#include <boost/fusion/algorithm/auxiliary/copy.hpp> + +int +main() +{ + { + boost::fusion::vector<int, short, double> v(1, 2, 3); + boost::fusion::list<int, short, double> l; + + boost::fusion::copy(v, l); + BOOST_TEST(v == l); + } + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/algorithm/count.cpp b/libs/fusion/test/algorithm/count.cpp new file mode 100644 index 000000000..13aaad1a6 --- /dev/null +++ b/libs/fusion/test/algorithm/count.cpp @@ -0,0 +1,41 @@ +/*============================================================================= + Copyright (c) 2001-2011 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(); +} + diff --git a/libs/fusion/test/algorithm/count_if.cpp b/libs/fusion/test/algorithm/count_if.cpp new file mode 100644 index 000000000..d70628903 --- /dev/null +++ b/libs/fusion/test/algorithm/count_if.cpp @@ -0,0 +1,38 @@ +/*============================================================================= + Copyright (c) 2001-2011 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(); +} + diff --git a/libs/fusion/test/algorithm/erase.cpp b/libs/fusion/test/algorithm/erase.cpp new file mode 100644 index 000000000..f376ba2a5 --- /dev/null +++ b/libs/fusion/test/algorithm/erase.cpp @@ -0,0 +1,63 @@ +/*============================================================================= + Copyright (c) 2001-2011 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(); +} + diff --git a/libs/fusion/test/algorithm/erase_key.cpp b/libs/fusion/test/algorithm/erase_key.cpp new file mode 100644 index 000000000..34f69248c --- /dev/null +++ b/libs/fusion/test/algorithm/erase_key.cpp @@ -0,0 +1,74 @@ +/*============================================================================= + Copyright (c) 2001-2011 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(boost::fusion::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(boost::fusion::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(erase_key<char>(make_set(1, 'x', 1.5, std::string("hello")))); + test_map(erase_key<_2>(make_map<_1, _2, _3, _4>(1, 'x', 1.5, "hello"))); + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/algorithm/filter.cpp b/libs/fusion/test/algorithm/filter.cpp new file mode 100644 index 000000000..e762e4322 --- /dev/null +++ b/libs/fusion/test/algorithm/filter.cpp @@ -0,0 +1,43 @@ +/*============================================================================= + Copyright (c) 2001-2011 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(); +} + diff --git a/libs/fusion/test/algorithm/filter_if.cpp b/libs/fusion/test/algorithm/filter_if.cpp new file mode 100644 index 000000000..830813de6 --- /dev/null +++ b/libs/fusion/test/algorithm/filter_if.cpp @@ -0,0 +1,77 @@ +/*============================================================================= + Copyright (c) 2001-2011 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(); +} + diff --git a/libs/fusion/test/algorithm/find.cpp b/libs/fusion/test/algorithm/find.cpp new file mode 100644 index 000000000..83a86f1d9 --- /dev/null +++ b/libs/fusion/test/algorithm/find.cpp @@ -0,0 +1,79 @@ +/*============================================================================= + Copyright (c) 2001-2011 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(); +} + diff --git a/libs/fusion/test/algorithm/find_if.cpp b/libs/fusion/test/algorithm/find_if.cpp new file mode 100644 index 000000000..c4dfafa28 --- /dev/null +++ b/libs/fusion/test/algorithm/find_if.cpp @@ -0,0 +1,69 @@ +/*============================================================================= + Copyright (c) 2001-2011 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(); +} + diff --git a/libs/fusion/test/algorithm/fold.cpp b/libs/fusion/test/algorithm/fold.cpp new file mode 100644 index 000000000..1db081815 --- /dev/null +++ b/libs/fusion/test/algorithm/fold.cpp @@ -0,0 +1,222 @@ +/*============================================================================= + Copyright (c) 2001-2011 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 State, typename T> + struct result<add_ints_only(State, T)> + { + typedef typename boost::remove_const< + typename boost::remove_reference<State>::type>::type type; + }; + + template <typename State, typename T> + State + operator()(State const& state, T const& /*x*/) const + { + return state; + } + + int + operator()(int state, int x) const + { + return x + state; + } +}; + +struct count_ints +{ + template<typename T> + struct result; + + template <typename CountT, typename T> + struct result<count_ints(CountT, T)> + { + typedef typename boost::remove_const< + typename boost::remove_reference<CountT>::type>::type state; + typedef typename boost::remove_const< + typename boost::remove_reference<T>::type>::type elem; + + typedef typename + if_< + is_same<elem, int> + , typename boost::mpl::next<state>::type + , state + >::type + type; + }; + + template <typename CountT, typename T> + typename result<count_ints(CountT, T)>::type + operator()(CountT const&, T const&) const + { + typedef typename result<count_ints(CountT, T)>::type result_; + return result_(); + } +}; + +struct appender +{ + typedef std::string result_type; + + std::string operator()(std::string const& str, char c) 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 T1 type; + }; + + template<typename T0, typename T1> + T1 operator()(T0 const& lhs, T1& 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(); +} + diff --git a/libs/fusion/test/algorithm/fold.hpp b/libs/fusion/test/algorithm/fold.hpp new file mode 100644 index 000000000..87a81a7c1 --- /dev/null +++ b/libs/fusion/test/algorithm/fold.hpp @@ -0,0 +1,212 @@ +/*============================================================================= + Copyright (c) 2010 Christopher Schmidt + + 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/config.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <boost/fusion/sequence.hpp> +#include <boost/fusion/iterator.hpp> +#include <boost/fusion/algorithm/transformation/reverse.hpp> +#include <boost/fusion/algorithm/iteration/fold.hpp> +#include <boost/fusion/algorithm/iteration/reverse_fold.hpp> +#include <boost/fusion/algorithm/iteration/iter_fold.hpp> +#include <boost/fusion/algorithm/iteration/reverse_iter_fold.hpp> +#include <boost/fusion/container/vector/convert.hpp> +#include <boost/fusion/container/vector/vector.hpp> +#include <boost/fusion/adapted/mpl.hpp> +#include <boost/fusion/support/pair.hpp> +#include <boost/fusion/mpl.hpp> +#include <boost/mpl/transform.hpp> +#include <boost/mpl/front.hpp> +#include <boost/mpl/back.hpp> +#include <boost/mpl/int.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/mpl/for_each.hpp> +#include <boost/mpl/range_c.hpp> +#include <boost/mpl/vector.hpp> +#include <boost/mpl/if.hpp> +#include <boost/mpl/back_inserter.hpp> +#include <boost/mpl/always.hpp> +#include <boost/mpl/copy.hpp> +#include <boost/type_traits/is_same.hpp> +#include <boost/type_traits/remove_reference.hpp> +#include <iostream> + +namespace mpl=boost::mpl; +namespace fusion=boost::fusion; + +#ifdef BOOST_FUSION_TEST_REVERSE_FOLD +# ifdef BOOST_FUSION_TEST_ITER_FOLD +# define BOOST_FUSION_TEST_FOLD_NAME reverse_iter_fold +# else +# define BOOST_FUSION_TEST_FOLD_NAME reverse_fold +# endif +#else +# ifdef BOOST_FUSION_TEST_ITER_FOLD +# define BOOST_FUSION_TEST_FOLD_NAME iter_fold +# else +# define BOOST_FUSION_TEST_FOLD_NAME fold +# endif +#endif + +struct sum +{ + template<typename Sig> + struct result; + + template<typename Self, typename State, typename T> + struct result<Self(State,T)> + : boost::fusion::result_of::make_pair< + mpl::int_< + boost::remove_reference< + State + >::type::first_type::value+1 + > + , int + > + { + BOOST_MPL_ASSERT((typename boost::is_reference<State>::type)); + BOOST_MPL_ASSERT((typename boost::is_reference<T>::type)); + }; + +#ifdef BOOST_FUSION_TEST_ITER_FOLD + template<typename State, typename It> + typename result<sum const&(State const&,It const&)>::type + operator()(State const& state, It const& it)const + { + static const int n=State::first_type::value; + return fusion::make_pair<mpl::int_<n+1> >( + state.second+fusion::deref(it)*n); + } +#else + template<typename State> + typename result<sum const&(State const&, int const&)>::type + operator()(State const& state, int const& e)const + { + static const int n=State::first_type::value; + return fusion::make_pair<mpl::int_<n+1> >(state.second+e*n); + } +#endif +}; + +struct meta_sum +{ + template<typename Sig> + struct result; + + template<typename Self, typename State, typename T> + struct result<Self(State,T)> + { + BOOST_MPL_ASSERT((typename boost::is_reference<State>::type)); + BOOST_MPL_ASSERT((typename boost::is_reference<T>::type)); + + typedef typename boost::remove_reference<State>::type state; + static const int n=mpl::front<state>::type::value; + +#ifdef BOOST_FUSION_TEST_ITER_FOLD + typedef typename + boost::fusion::result_of::value_of< + typename boost::remove_reference<T>::type + >::type + t; +#else + typedef typename boost::remove_reference<T>::type t; +#endif + + typedef + mpl::vector< + mpl::int_<n+1> + , mpl::int_< + mpl::back<state>::type::value+t::value*n + > + > + type; + }; + + template<typename State, typename T> + typename result<meta_sum const&(State const&,T const&)>::type + operator()(State const&, T const&)const; +}; + +struct fold_test_n +{ + template<typename I> + void + operator()(I)const + { + static const int n=I::value; + typedef mpl::range_c<int, 0, n> range; + + static const int squares_sum=n*(n+1)*(2*n+1)/6; + + { + mpl::range_c<int, 1, n+1> init_range; + typename boost::fusion::result_of::as_vector< + typename mpl::transform< + range + , mpl::always<int> + , mpl::back_inserter<mpl::vector<> > + >::type + >::type vec( +#ifdef BOOST_FUSION_TEST_REVERSE_FOLD + fusion::reverse(init_range) +#else + init_range +#endif + ); + + int result=BOOST_FUSION_TEST_FOLD_NAME( + vec, + fusion::make_pair<mpl::int_<1> >(0), + sum()).second; + std::cout << n << ": " << result << std::endl; + BOOST_TEST(result==squares_sum); + } + + { + typedef typename +#ifdef BOOST_FUSION_TEST_REVERSE_FOLD + boost::fusion::result_of::as_vector< + typename mpl::copy< + mpl::range_c<int, 1, n+1> + , mpl::front_inserter<fusion::vector<> > + >::type + >::type +#else + boost::fusion::result_of::as_vector<mpl::range_c<int, 1, n+1> >::type +#endif + vec; + + typedef + boost::is_same< + typename boost::fusion::result_of::BOOST_FUSION_TEST_FOLD_NAME< + vec + , mpl::vector<mpl::int_<1>, mpl::int_<0> > + , meta_sum + >::type + , typename mpl::if_c< + !n + , mpl::vector<mpl::int_<1>, mpl::int_<0> > const& + , mpl::vector<mpl::int_<n+1>, mpl::int_<squares_sum> > + >::type + > + result_test; + + BOOST_MPL_ASSERT((result_test)); + } + } +}; + +int +main() +{ + mpl::for_each<mpl::range_c<int, 0, 10> >(fold_test_n()); + + return boost::report_errors(); +} + +#undef BOOST_FUSION_TEST_FOLD_NAME + diff --git a/libs/fusion/test/algorithm/fold2.cpp b/libs/fusion/test/algorithm/fold2.cpp new file mode 100644 index 000000000..51ef975db --- /dev/null +++ b/libs/fusion/test/algorithm/fold2.cpp @@ -0,0 +1,8 @@ +/*============================================================================= + Copyright (c) 2010 Christopher Schmidt + + 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 "fold.hpp" diff --git a/libs/fusion/test/algorithm/for_each.cpp b/libs/fusion/test/algorithm/for_each.cpp new file mode 100644 index 000000000..c0bc441c5 --- /dev/null +++ b/libs/fusion/test/algorithm/for_each.cpp @@ -0,0 +1,61 @@ +/*============================================================================= + Copyright (c) 2001-2011 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(); +} + diff --git a/libs/fusion/test/algorithm/insert.cpp b/libs/fusion/test/algorithm/insert.cpp new file mode 100644 index 000000000..a4239a8de --- /dev/null +++ b/libs/fusion/test/algorithm/insert.cpp @@ -0,0 +1,67 @@ +/*============================================================================= + Copyright (c) 2001-2011 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(); +} + diff --git a/libs/fusion/test/algorithm/insert_range.cpp b/libs/fusion/test/algorithm/insert_range.cpp new file mode 100644 index 000000000..28a02219b --- /dev/null +++ b/libs/fusion/test/algorithm/insert_range.cpp @@ -0,0 +1,71 @@ +/*============================================================================= + Copyright (c) 2001-2011 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(); +} + diff --git a/libs/fusion/test/algorithm/iter_fold.cpp b/libs/fusion/test/algorithm/iter_fold.cpp new file mode 100644 index 000000000..b37f90db5 --- /dev/null +++ b/libs/fusion/test/algorithm/iter_fold.cpp @@ -0,0 +1,10 @@ +/*============================================================================= + Copyright (c) 2010 Christopher Schmidt + + 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) +==============================================================================*/ + +#define BOOST_FUSION_TEST_ITER_FOLD +#include "fold.hpp" +#undef BOOST_FUSION_TEST_ITER_FOLD diff --git a/libs/fusion/test/algorithm/join.cpp b/libs/fusion/test/algorithm/join.cpp new file mode 100644 index 000000000..c0de1896a --- /dev/null +++ b/libs/fusion/test/algorithm/join.cpp @@ -0,0 +1,28 @@ +/*============================================================================= + Copyright (c) 2001-2011 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(); +} diff --git a/libs/fusion/test/algorithm/none.cpp b/libs/fusion/test/algorithm/none.cpp new file mode 100644 index 000000000..83dfa7528 --- /dev/null +++ b/libs/fusion/test/algorithm/none.cpp @@ -0,0 +1,58 @@ +/*============================================================================= + Copyright (c) 2001-2011 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 in_search) + : search(in_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(); +} + diff --git a/libs/fusion/test/algorithm/pop_back.cpp b/libs/fusion/test/algorithm/pop_back.cpp new file mode 100644 index 000000000..de7cc646a --- /dev/null +++ b/libs/fusion/test/algorithm/pop_back.cpp @@ -0,0 +1,104 @@ +/*============================================================================= + Copyright (c) 2001-2011 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/list/list.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/container/generation/make_list.hpp> +#include <boost/fusion/algorithm/transformation/pop_back.hpp> +#include <boost/fusion/algorithm/transformation/push_back.hpp> +#include <boost/fusion/algorithm/query/find.hpp> +#include <boost/fusion/include/back.hpp> +#include <boost/fusion/include/array.hpp> +#include <boost/array.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))); + } + + { + list<int, int> l(1, 2); + std::cout << pop_back(l) << std::endl; + BOOST_TEST((pop_back(l) == make_list(1))); + } + + { // make sure empty sequences are OK + list<int> l(1); + std::cout << pop_back(l) << std::endl; + BOOST_TEST((pop_back(l) == make_list())); + } + + { + single_view<int> sv(1); + std::cout << pop_back(sv) << std::endl; + + // Compile check only + begin(pop_back(sv)) == end(sv); + end(pop_back(sv)) == begin(sv); + } + + // $$$ JDG: TODO add compile fail facility $$$ + //~ { // compile fail check (Disabled for now) + //~ list<> l; + //~ std::cout << pop_back(l) << std::endl; + //~ } + +#ifndef BOOST_NO_AUTO_DECLARATIONS + { + auto vec = make_vector(1, 3.14, "hello"); + + // Compile check only + auto popv = pop_back(vec); + std::cout << popv << std::endl; + + auto push = push_back(vec, 42); + auto pop = pop_back(vec); + auto i1 = find<int>(popv); + auto i2 = find<double>(pop); + + BOOST_TEST(i1 != end(pop)); + BOOST_TEST(i2 != end(pop)); + BOOST_TEST(i1 != i2); + } +#endif + + { + boost::array<std::size_t, 2> a = { 10, 50 }; + BOOST_TEST(back(pop_back(a)) == 10); + } + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/algorithm/pop_front.cpp b/libs/fusion/test/algorithm/pop_front.cpp new file mode 100644 index 000000000..df95b38c1 --- /dev/null +++ b/libs/fusion/test/algorithm/pop_front.cpp @@ -0,0 +1,46 @@ +/*============================================================================= + Copyright (c) 2001-2011 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(); +} + diff --git a/libs/fusion/test/algorithm/push_back.cpp b/libs/fusion/test/algorithm/push_back.cpp new file mode 100644 index 000000000..b53007fcf --- /dev/null +++ b/libs/fusion/test/algorithm/push_back.cpp @@ -0,0 +1,72 @@ +/*============================================================================= + Copyright (c) 2001-2011 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(); +} + diff --git a/libs/fusion/test/algorithm/push_front.cpp b/libs/fusion/test/algorithm/push_front.cpp new file mode 100644 index 000000000..8c63c5c3c --- /dev/null +++ b/libs/fusion/test/algorithm/push_front.cpp @@ -0,0 +1,55 @@ +/*============================================================================= + Copyright (c) 2001-2011 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(); +} + diff --git a/libs/fusion/test/algorithm/remove.cpp b/libs/fusion/test/algorithm/remove.cpp new file mode 100644 index 000000000..76e0c737c --- /dev/null +++ b/libs/fusion/test/algorithm/remove.cpp @@ -0,0 +1,80 @@ +/*============================================================================= + Copyright (c) 2001-2011 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(); +} + diff --git a/libs/fusion/test/algorithm/remove_if.cpp b/libs/fusion/test/algorithm/remove_if.cpp new file mode 100644 index 000000000..62313d3a5 --- /dev/null +++ b/libs/fusion/test/algorithm/remove_if.cpp @@ -0,0 +1,78 @@ +/*============================================================================= + Copyright (c) 2001-2011 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(); +} + diff --git a/libs/fusion/test/algorithm/replace.cpp b/libs/fusion/test/algorithm/replace.cpp new file mode 100644 index 000000000..ddd651301 --- /dev/null +++ b/libs/fusion/test/algorithm/replace.cpp @@ -0,0 +1,49 @@ +/*============================================================================= + Copyright (c) 2001-2011 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(); +} + diff --git a/libs/fusion/test/algorithm/replace_if.cpp b/libs/fusion/test/algorithm/replace_if.cpp new file mode 100644 index 000000000..7327632fe --- /dev/null +++ b/libs/fusion/test/algorithm/replace_if.cpp @@ -0,0 +1,52 @@ +/*============================================================================= + Copyright (c) 2001-2011 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(); +} + diff --git a/libs/fusion/test/algorithm/reverse.cpp b/libs/fusion/test/algorithm/reverse.cpp new file mode 100644 index 000000000..718d5b248 --- /dev/null +++ b/libs/fusion/test/algorithm/reverse.cpp @@ -0,0 +1,49 @@ +/*============================================================================= + Copyright (c) 2001-2011 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(); +} + + diff --git a/libs/fusion/test/algorithm/reverse_fold.cpp b/libs/fusion/test/algorithm/reverse_fold.cpp new file mode 100644 index 000000000..7742bca84 --- /dev/null +++ b/libs/fusion/test/algorithm/reverse_fold.cpp @@ -0,0 +1,10 @@ +/*============================================================================= + Copyright (c) 2010 Christopher Schmidt + + 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) +==============================================================================*/ + +#define BOOST_FUSION_TEST_REVERSE_FOLD +#include "fold.hpp" +#undef BOOST_FUSION_TEST_REVERSE_FOLD diff --git a/libs/fusion/test/algorithm/reverse_iter_fold.cpp b/libs/fusion/test/algorithm/reverse_iter_fold.cpp new file mode 100644 index 000000000..31e4cf265 --- /dev/null +++ b/libs/fusion/test/algorithm/reverse_iter_fold.cpp @@ -0,0 +1,12 @@ +/*============================================================================= + Copyright (c) 2010 Christopher Schmidt + + 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) +==============================================================================*/ + +#define BOOST_FUSION_TEST_REVERSE_FOLD +#define BOOST_FUSION_TEST_ITER_FOLD +#include "fold.hpp" +#undef BOOST_FUSION_TEST_ITER_FOLD +#undef BOOST_FUSION_TEST_REVERSE_FOLD diff --git a/libs/fusion/test/algorithm/segmented_find.cpp b/libs/fusion/test/algorithm/segmented_find.cpp new file mode 100644 index 000000000..8ce0b6d55 --- /dev/null +++ b/libs/fusion/test/algorithm/segmented_find.cpp @@ -0,0 +1,62 @@ +/*============================================================================= + Copyright (c) 2001-2011 Joel de Guzman + Copyright (c) 2011 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/algorithm/query/find.hpp> +#include <boost/fusion/container/generation/make_vector.hpp> +#include "../sequence/tree.hpp" + +struct not_there {}; + +template<typename Tree> +void +process_tree(Tree const &tree) +{ + using namespace boost; + + typedef typename boost::fusion::result_of::find<Tree const, short>::type short_iter; + typedef typename boost::fusion::result_of::find<Tree const, float>::type float_iter; + typedef typename boost::fusion::result_of::find<Tree const, not_there>::type not_there_iter; + + // find_if_s of a segmented data structure returns generic + // segmented iterators + short_iter si = fusion::find<short>(tree); + float_iter fi = fusion::find<float>(tree); + + // they behave like ordinary Fusion iterators ... + BOOST_TEST((*si == short('d'))); + BOOST_TEST((*fi == float(1))); + + // Searching for something that's not there should return the end iterator. + not_there_iter nti = fusion::find<not_there>(tree); + BOOST_TEST((nti == fusion::end(tree))); +} + +int +main() +{ + using namespace boost::fusion; + 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(); +} + diff --git a/libs/fusion/test/algorithm/segmented_find_if.cpp b/libs/fusion/test/algorithm/segmented_find_if.cpp new file mode 100644 index 000000000..98d963cff --- /dev/null +++ b/libs/fusion/test/algorithm/segmented_find_if.cpp @@ -0,0 +1,65 @@ +/*============================================================================= + Copyright (c) 2001-2011 Joel de Guzman + Copyright (c) 2011 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/algorithm/query/find_if.hpp> +#include <boost/fusion/container/generation/make_vector.hpp> +#include <boost/mpl/placeholders.hpp> +#include <boost/type_traits/is_same.hpp> +#include "../sequence/tree.hpp" + +struct not_there {}; + +template<typename Tree> +void +process_tree(Tree const &tree) +{ + using namespace boost; + using mpl::_; + + typedef typename boost::fusion::result_of::find_if<Tree const, is_same<_,short> >::type short_iter; + typedef typename boost::fusion::result_of::find_if<Tree const, is_same<_,float> >::type float_iter; + typedef typename boost::fusion::result_of::find_if<Tree const, is_same<_,not_there> >::type not_there_iter; + + // find_if of a segmented data structure returns generic + // segmented iterators + short_iter si = fusion::find_if<is_same<_,short> >(tree); + float_iter fi = fusion::find_if<is_same<_,float> >(tree); + + // they behave like ordinary Fusion iterators ... + BOOST_TEST((*si == short('d'))); + BOOST_TEST((*fi == float(1))); + + // Searching for something that's not there should return the end iterator. + not_there_iter nti = fusion::find_if<is_same<_,not_there> >(tree); + BOOST_TEST((nti == fusion::end(tree))); +} + +int +main() +{ + using namespace boost::fusion; + 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(); +} + diff --git a/libs/fusion/test/algorithm/segmented_fold.cpp b/libs/fusion/test/algorithm/segmented_fold.cpp new file mode 100644 index 000000000..af51ca89f --- /dev/null +++ b/libs/fusion/test/algorithm/segmented_fold.cpp @@ -0,0 +1,63 @@ +/*============================================================================= + Copyright (c) 2001-2011 Joel de Guzman + Copyright (c) 2011 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 <string> +#include <sstream> +#include <iostream> +#include <boost/detail/lightweight_test.hpp> +#include <boost/fusion/container/vector/vector.hpp> +#include <boost/fusion/algorithm/iteration/fold.hpp> +#include <boost/fusion/container/generation/make_vector.hpp> +#include "../sequence/tree.hpp" + +struct write_string +{ + typedef std::ostream* result_type; + + template<typename T> + std::ostream* operator()(std::ostream* sout, T const& t) const + { + return &(*sout << t << " "); + } +}; + +template<typename Tree> +void +process_tree(Tree const &tree) +{ + using namespace boost; + + std::stringstream str; + fusion::fold(tree, &str, write_string()); + std::string res = str.str(); + + BOOST_TEST_EQ(res, "a b c 1 2 3 100 e f 0 B 1 h i 4 5 6 j k l "); +} + +int +main() +{ + using namespace boost::fusion; + 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(); +} + diff --git a/libs/fusion/test/algorithm/segmented_for_each.cpp b/libs/fusion/test/algorithm/segmented_for_each.cpp new file mode 100644 index 000000000..84260a68b --- /dev/null +++ b/libs/fusion/test/algorithm/segmented_for_each.cpp @@ -0,0 +1,49 @@ +/*============================================================================= + Copyright (c) 2001-2011 Joel de Guzman + Copyright (c) 2011 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/algorithm/iteration/for_each.hpp> +#include <boost/fusion/container/generation/make_vector.hpp> +#include "../sequence/tree.hpp" + +struct print +{ + template <typename T> + void operator()(T const& v) const + { + std::cout << "[ " << v << " ] "; + } +}; + +int +main() +{ + using namespace boost::fusion; + + { + for_each( + 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(); +} + diff --git a/libs/fusion/test/algorithm/transform.cpp b/libs/fusion/test/algorithm/transform.cpp new file mode 100644 index 000000000..8609f61cd --- /dev/null +++ b/libs/fusion/test/algorithm/transform.cpp @@ -0,0 +1,157 @@ +/*============================================================================= + Copyright (c) 2001-2011 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 << boost::fusion::transform(sequence, square()) << std::endl; + BOOST_TEST((boost::fusion::transform(sequence, square()) == make_vector(25, 36, 49, 64))); + } + + { + typedef range_c<int, 5, 9> mpl_list1; + std::cout << boost::fusion::transform(mpl_list1(), square()) << std::endl; + BOOST_TEST((boost::fusion::transform(mpl_list1(), square()) == make_vector(25, 36, 49, 64))); + } + + { + vector<int, int, int> tup(1, 2, 3); + std::cout << boost::fusion::transform(tup, square()) << std::endl; + BOOST_TEST((boost::fusion::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 << boost::fusion::transform(tup1, tup2, add()) << std::endl; + BOOST_TEST((boost::fusion::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>(boost::fusion::transform(tup1, unary_lvalue_transform())) == &at_c<0>(tup1)); + BOOST_TEST(*begin(boost::fusion::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>(boost::fusion::transform(tup1, tup2, binary_lvalue_transform())) == &at_c<0>(tup1)); + BOOST_TEST(*begin(boost::fusion::transform(tup1, tup2, binary_lvalue_transform())) == &at_c<0>(tup1)); + } + + { + vector<int, int, int> tup1(1, 2, 3); + BOOST_TEST(boost::fusion::transform(tup1, twice) == make_vector(2,4,6)); + } + + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/algorithm/zip.cpp b/libs/fusion/test/algorithm/zip.cpp new file mode 100644 index 000000000..b6a4f097e --- /dev/null +++ b/libs/fusion/test/algorithm/zip.cpp @@ -0,0 +1,30 @@ +/*============================================================================= + Copyright (c) 2001-2011 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(); +} diff --git a/libs/fusion/test/algorithm/zip2.cpp b/libs/fusion/test/algorithm/zip2.cpp new file mode 100644 index 000000000..f35e4d5d8 --- /dev/null +++ b/libs/fusion/test/algorithm/zip2.cpp @@ -0,0 +1,30 @@ +/*============================================================================= + Copyright (c) 2001-2011 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(); +} diff --git a/libs/fusion/test/algorithm/zip_ignore.cpp b/libs/fusion/test/algorithm/zip_ignore.cpp new file mode 100644 index 000000000..a12b58201 --- /dev/null +++ b/libs/fusion/test/algorithm/zip_ignore.cpp @@ -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(); +} diff --git a/libs/fusion/test/compile_time/Makefile b/libs/fusion/test/compile_time/Makefile new file mode 100644 index 000000000..4887cf248 --- /dev/null +++ b/libs/fusion/test/compile_time/Makefile @@ -0,0 +1,29 @@ +#============================================================================= +# Copyright (c) 2008 Dan Marsden +# +# Use modification and distribution are 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). +#============================================================================== + +CXX=g++ +CXXFLAGS=-I$(BOOST_ROOT) + +TEST_SRCS=\ + vector_construction.cpp\ + vector_iteration.cpp\ + vector_intrinsic.cpp\ + fold.cpp\ + transform.cpp + +TEST_OBJS=$(TEST_SRCS:.cpp=.o) + +TEST_TARGETS=$(TEST_SRCS:.cpp=.test) + +all: $(TEST_TARGETS) + +%.test : %.cpp + time $(CXX) $(CXXFLAGS) $< -o $@ + +clean: + rm -f $(TEST_TARGETS) $(TEST_OBJS) diff --git a/libs/fusion/test/compile_time/driver.hpp b/libs/fusion/test/compile_time/driver.hpp new file mode 100644 index 000000000..8d06e6deb --- /dev/null +++ b/libs/fusion/test/compile_time/driver.hpp @@ -0,0 +1,75 @@ +/*============================================================================= + Copyright (c) 2008 Dan Marsden + + Use modification and distribution are 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). +==============================================================================*/ + +#if !defined(BOOST_FUSION_COMPILE_TIME_DRIVER) +#define BOOST_FUSION_COMPILE_TIME_DRIVER + +int main() +{ + test<0>(); + test<1>(); + test<2>(); + test<3>(); + test<4>(); + + test<5>(); + test<6>(); + test<7>(); + test<8>(); + test<9>(); + + test<10>(); + test<11>(); + test<12>(); + test<13>(); + test<14>(); + + test<15>(); + test<16>(); + test<17>(); + test<18>(); + test<19>(); + + test<20>(); + test<21>(); + test<22>(); + test<23>(); + test<24>(); + + test<25>(); + test<26>(); + test<27>(); + test<28>(); + test<29>(); + + test<30>(); + test<31>(); + test<32>(); + test<33>(); + test<34>(); + + test<35>(); + test<36>(); + test<37>(); + test<38>(); + test<39>(); + + test<40>(); + test<41>(); + test<42>(); + test<43>(); + test<44>(); + + test<45>(); + test<46>(); + test<47>(); + test<48>(); + test<49>(); +} + +#endif diff --git a/libs/fusion/test/compile_time/fold.cpp b/libs/fusion/test/compile_time/fold.cpp new file mode 100644 index 000000000..5fb618dd4 --- /dev/null +++ b/libs/fusion/test/compile_time/fold.cpp @@ -0,0 +1,42 @@ +/*============================================================================= + Copyright (c) 2008 Dan Marsden + + Use modification and distribution are 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/include/fold.hpp> +#include <boost/fusion/include/vector.hpp> + +namespace fusion = boost::fusion; + +namespace +{ + template<int n, int batch> + struct distinct + {}; + + struct f + { + typedef int result_type; + + template<int n, int batch> + int operator()(int state, distinct<n, batch> const& d) const + { + return state + n; + } + }; + + template<int batch> + void test() + { + fusion::vector< + distinct<0, batch>, distinct<1, batch>, distinct<2, batch>, distinct<3, batch>, distinct<4, batch>, + distinct<5, batch>, distinct<6, batch>, distinct<7, batch>, distinct<8, batch>, distinct<9, batch> > v; + + fusion::fold(v, 0, f()); + } +} + +#include "./driver.hpp" diff --git a/libs/fusion/test/compile_time/transform.cpp b/libs/fusion/test/compile_time/transform.cpp new file mode 100644 index 000000000..04ad8ab24 --- /dev/null +++ b/libs/fusion/test/compile_time/transform.cpp @@ -0,0 +1,55 @@ +/*============================================================================= + Copyright (c) 2008 Dan Marsden + + Use modification and distribution are 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/include/transform.hpp> +#include <boost/fusion/include/for_each.hpp> +#include <boost/fusion/include/vector.hpp> + +namespace fusion = boost::fusion; + +namespace +{ + template<int n, int batch> + struct distinct + { + static const int value = n; + }; + + struct f + { + typedef int result_type; + + template<typename T> + result_type operator()(T const& t) const + { + return T::value; + } + }; + + struct touch + { + template<typename T> + void operator()(T const&) const + {} + }; + + template<int batch> + void test() + { + fusion::vector< + distinct<0, batch>, distinct<1, batch>, distinct<2, batch>, distinct<3, batch>, distinct<4, batch>, + distinct<5, batch>, distinct<6, batch>, distinct<7, batch>, distinct<8, batch>, distinct<9, batch> > v; + + // We're testing transform really + // for_each call is to force iteration through the lazy + // transform, otherwise very little will happen. + fusion::for_each(fusion::transform(v, f()), touch()); + } +} + +#include "./driver.hpp" diff --git a/libs/fusion/test/compile_time/vector_construction.cpp b/libs/fusion/test/compile_time/vector_construction.cpp new file mode 100644 index 000000000..18f9f16b4 --- /dev/null +++ b/libs/fusion/test/compile_time/vector_construction.cpp @@ -0,0 +1,28 @@ +/*============================================================================= + Copyright (c) 2008 Dan Marsden + + Use modification and distribution are 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/include/vector.hpp> + +namespace fusion = boost::fusion; + +namespace +{ + template<int n, int batch> + struct distinct + {}; + + template<int batch> + void test() + { + fusion::vector< + distinct<0, batch>, distinct<1, batch>, distinct<2, batch>, distinct<3, batch>, distinct<4, batch>, + distinct<5, batch>, distinct<6, batch>, distinct<7, batch>, distinct<8, batch>, distinct<9, batch> > v; + } +} + +#include "./driver.hpp" diff --git a/libs/fusion/test/compile_time/vector_intrinsic.cpp b/libs/fusion/test/compile_time/vector_intrinsic.cpp new file mode 100644 index 000000000..3690a496b --- /dev/null +++ b/libs/fusion/test/compile_time/vector_intrinsic.cpp @@ -0,0 +1,59 @@ +/*============================================================================= + Copyright (c) 2008 Dan Marsden + + Use modification and distribution are 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/include/vector.hpp> +#include <boost/fusion/include/intrinsic.hpp> + +namespace fusion = boost::fusion; + +namespace +{ + template<int n, int batch> + struct distinct + {}; + + template<int batch> + void test() + { + typedef fusion::vector< + distinct<0, batch>, distinct<1, batch>, distinct<2, batch>, distinct<3, batch>, distinct<4, batch>, + distinct<5, batch>, distinct<6, batch>, distinct<7, batch>, distinct<8, batch>, distinct<9, batch> > v_type; + + v_type v; + + fusion::at_c<0>(v); + fusion::at_c<1>(v); + fusion::at_c<2>(v); + fusion::at_c<3>(v); + fusion::at_c<4>(v); + + fusion::at_c<5>(v); + fusion::at_c<6>(v); + fusion::at_c<7>(v); + fusion::at_c<8>(v); + fusion::at_c<9>(v); + + typedef typename boost::fusion::result_of::value_at_c<v_type, 0>::type va0; + typedef typename boost::fusion::result_of::value_at_c<v_type, 1>::type va1; + typedef typename boost::fusion::result_of::value_at_c<v_type, 2>::type va2; + typedef typename boost::fusion::result_of::value_at_c<v_type, 3>::type va3; + typedef typename boost::fusion::result_of::value_at_c<v_type, 4>::type va4; + + typedef typename boost::fusion::result_of::value_at_c<v_type, 5>::type va5; + typedef typename boost::fusion::result_of::value_at_c<v_type, 6>::type va6; + typedef typename boost::fusion::result_of::value_at_c<v_type, 7>::type va7; + typedef typename boost::fusion::result_of::value_at_c<v_type, 8>::type va8; + typedef typename boost::fusion::result_of::value_at_c<v_type, 9>::type va9; + + fusion::begin(v); + fusion::end(v); + fusion::size(v); + } +} + +#include "./driver.hpp" diff --git a/libs/fusion/test/compile_time/vector_iteration.cpp b/libs/fusion/test/compile_time/vector_iteration.cpp new file mode 100644 index 000000000..ee63bee5a --- /dev/null +++ b/libs/fusion/test/compile_time/vector_iteration.cpp @@ -0,0 +1,38 @@ +/*============================================================================= + Copyright (c) 2008 Dan Marsden + + Use modification and distribution are 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/include/vector.hpp> +#include <boost/fusion/include/for_each.hpp> + +namespace fusion = boost::fusion; + +namespace +{ + template<int n, int batch> + struct distinct + {}; + + struct null_op + { + template<typename T> + void operator()(T const& t) const + {} + }; + + template<int batch> + void test() + { + fusion::vector< + distinct<0, batch>, distinct<1, batch>, distinct<2, batch>, distinct<3, batch>, distinct<4, batch>, + distinct<5, batch>, distinct<6, batch>, distinct<7, batch>, distinct<8, batch>, distinct<9, batch> > v; + + fusion::for_each(v, null_op()); + } +} + +#include "./driver.hpp" diff --git a/libs/fusion/test/functional/fused.cpp b/libs/fusion/test/functional/fused.cpp new file mode 100644 index 000000000..e2c893956 --- /dev/null +++ b/libs/fusion/test/functional/fused.cpp @@ -0,0 +1,97 @@ +/*============================================================================= + Copyright (c) 2006-2007 Tobias Schwinger + + Use modification and distribution are 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/functional/adapter/fused.hpp> +#include <boost/detail/lightweight_test.hpp> + +#include <boost/noncopyable.hpp> +#include <boost/blank.hpp> + +#include <boost/fusion/container/generation/make_vector.hpp> +#include <boost/fusion/container/vector.hpp> + +#include <boost/type_traits/is_same.hpp> +#include <boost/mpl/assert.hpp> + +namespace fusion = boost::fusion; +using boost::noncopyable; + +template <class Base = boost::blank> +struct test_func + : Base +{ + typedef int result_type; + + template <typename T0, typename T1> + int operator()(T0 const & x, T1 const & y) const + { + return 1+x-y; + } + + template <typename T0, typename T1> + int operator()(T0 const & x, T1 const & y) + { + return 2+x-y; + } + + template <typename T0, typename T1> + int operator()(T0 & x, T1 & y) const + { + return 3+x-y; + } + + template <typename T0, typename T1> + int operator()(T0 & x, T1 & y) + { + return 4+x-y; + } +}; + +int main() +{ + test_func<noncopyable> f; + + typedef fusion::fused< test_func<> > ff; + ff fused_func; + + typedef fusion::fused< test_func<noncopyable> & > ffr; + ffr fused_func_ref(f); + + typedef fusion::fused< test_func<> const > ffc; + ffc fused_func_c; + + typedef fusion::fused< test_func<> > const ffc2; + ffc2 fused_func_c2; + + typedef fusion::fused< test_func<noncopyable> const & > ffcr; + ffcr fused_func_c_ref(f); + + typedef fusion::vector<int,char> vec; + vec lv_vec(1,'\004'); + + BOOST_MPL_ASSERT((boost::is_same<boost::result_of<ff(vec)>::type, int>)); + BOOST_TEST(fused_func(lv_vec) == 1); + BOOST_MPL_ASSERT((boost::is_same<boost::result_of<ffr(vec)>::type, int>)); + BOOST_TEST(fused_func_c(lv_vec) == 0); + BOOST_MPL_ASSERT((boost::is_same<boost::result_of<ffc(vec)>::type, int>)); + BOOST_TEST(fused_func_c2(lv_vec) == 0); + BOOST_TEST(fused_func_ref(lv_vec) == 1); + BOOST_MPL_ASSERT((boost::is_same<boost::result_of<ffcr(vec)>::type, int>)); + BOOST_TEST(fused_func_c_ref(lv_vec) == 0); + + BOOST_TEST(fused_func(fusion::make_vector(2,'\003')) == 1); + BOOST_TEST(fused_func_c(fusion::make_vector(2,'\003')) == 0); + BOOST_TEST(fused_func_c2(fusion::make_vector(2,'\003')) == 0); + BOOST_TEST(fused_func_ref(fusion::make_vector(2,'\003')) == 1); + BOOST_TEST(fused_func_c_ref(fusion::make_vector(2,'\003')) == 0); + + return boost::report_errors(); +} + + + diff --git a/libs/fusion/test/functional/fused_function_object.cpp b/libs/fusion/test/functional/fused_function_object.cpp new file mode 100644 index 000000000..c8d4c590d --- /dev/null +++ b/libs/fusion/test/functional/fused_function_object.cpp @@ -0,0 +1,83 @@ +/*============================================================================= + Copyright (c) 2006-2007 Tobias Schwinger + + Use modification and distribution are 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/functional/adapter/fused_function_object.hpp> +#include <boost/detail/lightweight_test.hpp> + +#include <boost/noncopyable.hpp> +#include <boost/blank.hpp> + +#include <boost/fusion/container/generation/make_vector.hpp> +#include <boost/fusion/container/vector.hpp> + +namespace fusion = boost::fusion; +using boost::noncopyable; + +template <class Base = boost::blank> +struct test_func + : Base +{ + template<typename T> + struct result; + + template<class Self, typename T0, typename T1> + struct result< Self(T0, T1) > + { + typedef int type; + }; + + template <typename T0, typename T1> + int operator()(T0 const & x, T1 const & y) const + { + return 1+x-y; + } + + template <typename T0, typename T1> + int operator()(T0 const & x, T1 const & y) + { + return 2+x-y; + } + + template <typename T0, typename T1> + int operator()(T0 & x, T1 & y) const + { + return 3+x-y; + } + + template <typename T0, typename T1> + int operator()(T0 & x, T1 & y) + { + return 4+x-y; + } +}; + +int main() +{ + test_func<noncopyable> f; + fusion::fused_function_object< test_func<> > fused_func; + fusion::fused_function_object< test_func<noncopyable> & > fused_func_ref(f); + fusion::fused_function_object< test_func<> const > fused_func_c; + fusion::fused_function_object< test_func<> > const fused_func_c2; + fusion::fused_function_object< test_func<noncopyable> const & > fused_func_c_ref(f); + + fusion::vector<int,char> lv_vec(1,'\004'); + BOOST_TEST(fused_func(lv_vec) == 1); + BOOST_TEST(fused_func_c(lv_vec) == 0); + BOOST_TEST(fused_func_c2(lv_vec) == 0); + BOOST_TEST(fused_func_ref(lv_vec) == 1); + BOOST_TEST(fused_func_c_ref(lv_vec) == 0); + + BOOST_TEST(fused_func(fusion::make_vector(2,'\003')) == 1); + BOOST_TEST(fused_func_c(fusion::make_vector(2,'\003')) == 0); + BOOST_TEST(fused_func_c2(fusion::make_vector(2,'\003')) == 0); + BOOST_TEST(fused_func_ref(fusion::make_vector(2,'\003')) == 1); + BOOST_TEST(fused_func_c_ref(fusion::make_vector(2,'\003')) == 0); + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/functional/fused_procedure.cpp b/libs/fusion/test/functional/fused_procedure.cpp new file mode 100644 index 000000000..57443c208 --- /dev/null +++ b/libs/fusion/test/functional/fused_procedure.cpp @@ -0,0 +1,82 @@ +/*============================================================================= + Copyright (c) 2006-2007 Tobias Schwinger + + Use modification and distribution are 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/functional/adapter/fused_procedure.hpp> +#include <boost/detail/lightweight_test.hpp> + +#include <boost/noncopyable.hpp> +#include <boost/blank.hpp> + +#include <boost/fusion/container/generation/make_vector.hpp> +#include <boost/fusion/container/vector.hpp> + +namespace fusion = boost::fusion; +using boost::noncopyable; + +int effect; + +#define CHECK_EFFECT(t,e) \ + { \ + effect = 1234567; t; \ + BOOST_TEST(effect == e); \ + } + +template <class Base = boost::blank> +struct test_func + : Base +{ + template <typename T0, typename T1> + int operator()(T0 const & x, T1 const & y) const + { + return effect = 1+x-y; + } + + template <typename T0, typename T1> + int operator()(T0 const & x, T1 const & y) + { + return effect = 2+x-y; + } + + template <typename T0, typename T1> + int operator()(T0 & x, T1 & y) const + { + return effect = 3+x-y; + } + + template <typename T0, typename T1> + int operator()(T0 & x, T1 & y) + { + return effect = 4+x-y; + } +}; + +int main() +{ + test_func<noncopyable> f; + fusion::fused_procedure< test_func<> > fused_proc; + fusion::fused_procedure< test_func<noncopyable> & > fused_proc_ref(f); + fusion::fused_procedure< test_func<> const > fused_proc_c; + fusion::fused_procedure< test_func<> > const fused_proc_c2; + fusion::fused_procedure< test_func<noncopyable> const & > fused_proc_c_ref(f); + + fusion::vector<int,char> lv_vec(1,'\004'); + CHECK_EFFECT(fused_proc(lv_vec), 1); + CHECK_EFFECT(fused_proc_c(lv_vec), 0); + CHECK_EFFECT(fused_proc_c2(lv_vec), 0); + CHECK_EFFECT(fused_proc_ref(lv_vec), 1); + CHECK_EFFECT(fused_proc_c_ref(lv_vec), 0); + + CHECK_EFFECT(fused_proc(fusion::make_vector(2,'\003')), 1); + CHECK_EFFECT(fused_proc_c(fusion::make_vector(2,'\003')), 0); + CHECK_EFFECT(fused_proc_c2(fusion::make_vector(2,'\003')), 0); + CHECK_EFFECT(fused_proc_ref(fusion::make_vector(2,'\003')), 1); + CHECK_EFFECT(fused_proc_c_ref(fusion::make_vector(2,'\003')), 0); + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/functional/invoke.cpp b/libs/fusion/test/functional/invoke.cpp new file mode 100644 index 000000000..52740eecf --- /dev/null +++ b/libs/fusion/test/functional/invoke.cpp @@ -0,0 +1,394 @@ +/*============================================================================= + Copyright (c) 2005-2006 Joao Abecasis + Copyright (c) 2006-2007 Tobias Schwinger + + Use modification and distribution are 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/functional/invocation/invoke.hpp> +#include <boost/detail/lightweight_test.hpp> + +#include <memory> +#include <boost/noncopyable.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include <boost/mpl/int.hpp> + +#include <boost/fusion/container/vector.hpp> +#include <boost/fusion/container/list.hpp> +#include <boost/fusion/sequence/intrinsic/size.hpp> +#include <boost/fusion/sequence/intrinsic/begin.hpp> +#include <boost/fusion/view/single_view.hpp> +#include <boost/fusion/view/iterator_range.hpp> +#include <boost/fusion/iterator/advance.hpp> +#include <boost/fusion/algorithm/transformation/join.hpp> + +namespace mpl = boost::mpl; +namespace fusion = boost::fusion; + +template <typename T> +inline T const & const_(T const & t) +{ + return t; +} + +struct object {}; +struct object_nc : boost::noncopyable {}; + +struct fobj +{ + // Handle nullary separately to exercise result_of support + template <typename Sig> + struct result; + + template <class Self, typename T0> + struct result< Self(T0) > + { + typedef int type; + }; + + template <class Self, typename T0, typename T1> + struct result< Self(T0, T1) > + { + typedef int type; + }; + + template <class Self, typename T0, typename T1, typename T2> + struct result< Self(T0, T1, T2) > + { + typedef int type; + }; + + 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 &, object_nc &) { return 10 + i; } + int operator()(int i, object &, object_nc &) const { return 11 + i; } +}; + +struct nullary_fobj +{ + typedef int result_type; + + int operator()() { return 0; } + int operator()() const { return 1; } +}; + +struct fobj_nc + : boost::noncopyable +{ + // Handle nullary separately to exercise result_of support + template <typename Sig> + struct result; + + template <class Self, typename T0> + struct result< Self(T0)> + { + typedef int type; + }; + + int operator()(int i) { return 14 + i; } + int operator()(int i) const { return 15 + i; } +}; + +struct nullary_fobj_nc + : boost::noncopyable +{ + typedef int result_type; + + int operator()() { return 12; } + int operator()() const { return 13; } +}; + +int nullary() { return 16; } +int unary(int i) { return 17 + i; } +int binary1(int i, object &) { return 18 + i; } +int binary2(int i, object const &) { return 19 + i; } + +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 = &unary; + c_func_ptr func_ptr2 = &unary; + v_func_ptr func_ptr3 = &unary; +cv_func_ptr func_ptr4 = &unary; + +class members +{ + public: + int data; + + members() + : data(20) + { } + + int nullary() { return data + 1; } + int nullary_c() const { return data + 2; } + int unary(int i) { return data + 3 + i; } + int unary_c(int i) const { return data + 4 + i; } + int binary(int i, object) { return data + 5 + i; } + int binary_c(int i, object) const { return data + 6 + i; } +}; + +struct derived + : members +{ +}; + +typedef int element1_type; +typedef object element2_type; +typedef object_nc & element3_type; + +int element1 = 100; +object element2 = object(); +object_nc element3; + +members that; + +std::auto_ptr<members> spt_that(new members); +std::auto_ptr<members const> spt_that_c(new members); + +fusion::single_view<members > sv_obj_ctx( that); +fusion::single_view<members &> sv_ref_ctx( that); +fusion::single_view<members *> sv_ptr_ctx(& that); +fusion::single_view<members const > sv_obj_c_ctx( that); +fusion::single_view<members const &> sv_ref_c_ctx( that); +fusion::single_view<members const *> sv_ptr_c_ctx(& that); +fusion::single_view<std::auto_ptr<members> const &> sv_spt_ctx(spt_that); +fusion::single_view< std::auto_ptr<members const> const &> sv_spt_c_ctx(spt_that_c); + +derived derived_that; + +std::auto_ptr<derived> spt_derived_that(new derived); +std::auto_ptr<derived const> spt_derived_that_c(new derived); + +fusion::single_view<derived > sv_obj_d_ctx( derived_that); +fusion::single_view<derived &> sv_ref_d_ctx( derived_that); +fusion::single_view<derived *> sv_ptr_d_ctx(& derived_that); +fusion::single_view<derived const > sv_obj_c_d_ctx( derived_that); +fusion::single_view<derived const &> sv_ref_c_d_ctx( derived_that); +fusion::single_view<derived const *> sv_ptr_c_d_ctx(& derived_that); +fusion::single_view<std::auto_ptr<derived> const &> sv_spt_d_ctx(spt_derived_that); +fusion::single_view< std::auto_ptr<derived const> const &> sv_spt_c_d_ctx(spt_derived_that_c); + +template <class Sequence> +void test_sequence_n(Sequence & seq, mpl::int_<0>) +{ + // Function Objects + + nullary_fobj f; + + BOOST_TEST(f () == fusion::invoke(f , seq )); + BOOST_TEST(f () == fusion::invoke(f , const_(seq))); + + // Note: The function object is taken by value, so we request the copy + // to be const with an explicit template argument. We can also request + // the function object to be pased by reference... + BOOST_TEST(const_(f)() == fusion::invoke<nullary_fobj const >(const_(f), seq )); + BOOST_TEST(const_(f)() == fusion::invoke<nullary_fobj const &>(const_(f), const_(seq))); + + nullary_fobj_nc nc_f; + // ...and we further ensure there is no copying in this case, using a + // noncopyable function object. + BOOST_TEST(nc_f () == fusion::invoke<nullary_fobj_nc &>(nc_f , seq )); + BOOST_TEST(nc_f () == fusion::invoke<nullary_fobj_nc &>(nc_f , const_(seq))); + BOOST_TEST(const_(nc_f)() == fusion::invoke<nullary_fobj_nc const &>(const_(nc_f), seq )); + BOOST_TEST(const_(nc_f)() == fusion::invoke<nullary_fobj_nc const &>(const_(nc_f), const_(seq))); + + // Builtin Functions + + // Call through ref/ptr to function + BOOST_TEST(nullary() == fusion::invoke<int (&)()>(nullary, seq)); + BOOST_TEST(nullary() == fusion::invoke(& nullary, seq)); + + // Call through ptr to member function + // Note: The non-const function members::nullary can't be invoked with + // fusion::join(sv_obj_ctx,seq)), which is const and so is its first element + BOOST_TEST(that.nullary() == fusion::invoke(& members::nullary, fusion::join(sv_ref_ctx,seq))); + BOOST_TEST(that.nullary() == fusion::invoke(& members::nullary, fusion::join(sv_ptr_ctx,seq))); + BOOST_TEST(that.nullary() == fusion::invoke(& members::nullary, fusion::join(sv_spt_ctx,seq))); + BOOST_TEST(that.nullary_c() == fusion::invoke(& members::nullary_c, fusion::join(sv_obj_ctx,seq))); + BOOST_TEST(that.nullary_c() == fusion::invoke(& members::nullary_c, fusion::join(sv_ref_ctx,seq))); + BOOST_TEST(that.nullary_c() == fusion::invoke(& members::nullary_c, fusion::join(sv_ptr_ctx,seq))); + BOOST_TEST(that.nullary_c() == fusion::invoke(& members::nullary_c, fusion::join(sv_spt_ctx,seq))); + BOOST_TEST(that.nullary_c() == fusion::invoke(& members::nullary_c, fusion::join(sv_obj_c_ctx,seq))); + BOOST_TEST(that.nullary_c() == fusion::invoke(& members::nullary_c, fusion::join(sv_ref_c_ctx,seq))); + BOOST_TEST(that.nullary_c() == fusion::invoke(& members::nullary_c, fusion::join(sv_ptr_c_ctx,seq))); + BOOST_TEST(that.nullary_c() == fusion::invoke(& members::nullary_c, fusion::join(sv_spt_c_ctx,seq))); + + // Pointer to data member + + BOOST_TEST(that.data == (fusion::invoke(& members::data, fusion::join(sv_obj_ctx,seq)) = that.data)); + BOOST_TEST(that.data == (fusion::invoke(& members::data, fusion::join(sv_ref_ctx,seq)) = that.data)); + BOOST_TEST(that.data == (fusion::invoke(& members::data, fusion::join(sv_ptr_ctx,seq)) = that.data)); + BOOST_TEST(that.data == (fusion::invoke(& members::data, fusion::join(sv_spt_ctx,seq)) = that.data)); + BOOST_TEST(that.data == fusion::invoke(& members::data, fusion::join(sv_obj_c_ctx,seq))); + BOOST_TEST(that.data == fusion::invoke(& members::data, fusion::join(sv_ref_c_ctx,seq))); + BOOST_TEST(that.data == fusion::invoke(& members::data, fusion::join(sv_ptr_c_ctx,seq))); + BOOST_TEST(that.data == fusion::invoke(& members::data, fusion::join(sv_spt_c_ctx,seq))); + + BOOST_TEST(that.data == (fusion::invoke(& members::data, fusion::join(sv_obj_d_ctx,seq)) = that.data)); + BOOST_TEST(that.data == (fusion::invoke(& members::data, fusion::join(sv_ref_d_ctx,seq)) = that.data)); + BOOST_TEST(that.data == (fusion::invoke(& members::data, fusion::join(sv_ptr_d_ctx,seq)) = that.data)); + BOOST_TEST(that.data == (fusion::invoke(& members::data, fusion::join(sv_spt_d_ctx,seq)) = that.data)); + BOOST_TEST(that.data == fusion::invoke(& members::data, fusion::join(sv_obj_c_d_ctx,seq))); + BOOST_TEST(that.data == fusion::invoke(& members::data, fusion::join(sv_ref_c_d_ctx,seq))); + BOOST_TEST(that.data == fusion::invoke(& members::data, fusion::join(sv_ptr_c_d_ctx,seq))); + BOOST_TEST(that.data == fusion::invoke(& members::data, fusion::join(sv_spt_c_d_ctx,seq))); +} + +template <class Sequence> +void test_sequence_n(Sequence & seq, mpl::int_<1>) +{ + fobj f; + BOOST_TEST(f(element1) == fusion::invoke(f , seq )); + BOOST_TEST(f(element1) == fusion::invoke(f , const_(seq))); + BOOST_TEST(const_(f)(element1) == fusion::invoke<fobj const >(const_(f), seq )); + BOOST_TEST(const_(f)(element1) == fusion::invoke<fobj const &>(const_(f), const_(seq))); + + fobj_nc nc_f; + BOOST_TEST(nc_f(element1) == fusion::invoke<fobj_nc &>(nc_f, seq )); + BOOST_TEST(nc_f(element1) == fusion::invoke<fobj_nc &>(nc_f, const_(seq))); + BOOST_TEST(const_(nc_f)(element1) == fusion::invoke<fobj_nc const &>(const_(nc_f), seq )); + BOOST_TEST(const_(nc_f)(element1) == fusion::invoke<fobj_nc const &>(const_(nc_f), const_(seq))); + + BOOST_TEST(unary(element1) == fusion::invoke<int (&)(int)>(unary, seq)); + BOOST_TEST(func_ptr1(element1) == fusion::invoke(func_ptr1, seq)); + BOOST_TEST(func_ptr2(element1) == fusion::invoke(func_ptr2, seq)); + BOOST_TEST(func_ptr3(element1) == fusion::invoke(func_ptr3, seq)); + BOOST_TEST(func_ptr4(element1) == fusion::invoke(func_ptr4, seq)); + + BOOST_TEST(that.unary(element1) == fusion::invoke(& members::unary, fusion::join(sv_ref_ctx,seq))); + BOOST_TEST(that.unary(element1) == fusion::invoke(& members::unary, fusion::join(sv_ptr_ctx,seq))); + BOOST_TEST(that.unary(element1) == fusion::invoke(& members::unary, fusion::join(sv_spt_ctx,seq))); + BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_obj_ctx,seq))); + BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_ref_ctx,seq))); + BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_ptr_ctx,seq))); + BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_spt_ctx,seq))); + BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_obj_c_ctx,seq))); + BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_ref_c_ctx,seq))); + BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_ptr_c_ctx,seq))); + BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_spt_c_ctx,seq))); + + BOOST_TEST(that.unary(element1) == fusion::invoke(& members::unary, fusion::join(sv_ref_d_ctx,seq))); + BOOST_TEST(that.unary(element1) == fusion::invoke(& members::unary, fusion::join(sv_ptr_d_ctx,seq))); + BOOST_TEST(that.unary(element1) == fusion::invoke(& members::unary, fusion::join(sv_spt_d_ctx,seq))); + BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_obj_d_ctx,seq))); + BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_ref_d_ctx,seq))); + BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_ptr_d_ctx,seq))); + BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_spt_d_ctx,seq))); + BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_obj_c_d_ctx,seq))); + BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_ref_c_d_ctx,seq))); + BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_ptr_c_d_ctx,seq))); + BOOST_TEST(that.unary_c(element1) == fusion::invoke(& members::unary_c, fusion::join(sv_spt_c_d_ctx,seq))); + +} + +template <class Sequence> +void test_sequence_n(Sequence & seq, mpl::int_<2>) +{ + fobj f; + BOOST_TEST(f (element1, element2) == fusion::invoke(f , seq)); + BOOST_TEST(f (element1, const_(element2)) == fusion::invoke(f , const_(seq))); + BOOST_TEST(const_(f)(element1, element2) == fusion::invoke<fobj const>(const_(f), seq)); + BOOST_TEST(const_(f)(element1, const_(element2)) == fusion::invoke<fobj const>(const_(f), const_(seq))); + + BOOST_TEST(binary1(element1, element2) == fusion::invoke(binary1, seq)); + BOOST_TEST(binary2(element1, element2) == fusion::invoke(binary2, seq)); + + BOOST_TEST(that.binary(element1,element2) == fusion::invoke(& members::binary, fusion::join(sv_ref_ctx,seq))); + BOOST_TEST(that.binary(element1,element2) == fusion::invoke(& members::binary, fusion::join(sv_ptr_ctx,seq))); + BOOST_TEST(that.binary(element1,element2) == fusion::invoke(& members::binary, fusion::join(sv_spt_ctx,seq))); + BOOST_TEST(that.binary_c(element1,element2) == fusion::invoke(& members::binary_c, fusion::join(sv_obj_ctx,seq))); + BOOST_TEST(that.binary_c(element1,element2) == fusion::invoke(& members::binary_c, fusion::join(sv_ref_ctx,seq))); + BOOST_TEST(that.binary_c(element1,element2) == fusion::invoke(& members::binary_c, fusion::join(sv_ptr_ctx,seq))); + BOOST_TEST(that.binary_c(element1,element2) == fusion::invoke(& members::binary_c, fusion::join(sv_spt_ctx,seq))); + BOOST_TEST(that.binary_c(element1,element2) == fusion::invoke(& members::binary_c, fusion::join(sv_obj_c_ctx,seq))); + BOOST_TEST(that.binary_c(element1,element2) == fusion::invoke(& members::binary_c, fusion::join(sv_ref_c_ctx,seq))); + BOOST_TEST(that.binary_c(element1,element2) == fusion::invoke(& members::binary_c, fusion::join(sv_ptr_c_ctx,seq))); + BOOST_TEST(that.binary_c(element1,element2) == fusion::invoke(& members::binary_c, fusion::join(sv_spt_c_ctx,seq))); +} + +template <class Sequence> +void test_sequence_n(Sequence & seq, mpl::int_<3>) +{ + fobj f; + + BOOST_TEST(f(element1, element2, element3) == fusion::invoke(f, seq)); + BOOST_TEST(const_(f)(element1, element2, element3) == fusion::invoke<fobj const>(const_(f), seq)); +} + +template <class Sequence> +void test_sequence(Sequence & seq) +{ + test_sequence_n(seq, mpl::int_<boost::fusion::result_of::size<Sequence>::value>()); +} + + +void result_type_tests() +{ + using boost::is_same; + + BOOST_TEST(( is_same< + boost::fusion::result_of::invoke<int (*)(), fusion::vector0<> >::type, int + >::value )); +// disabled until boost::result_of supports it +// BOOST_TEST(( is_same< +// boost::fusion::result_of::invoke<int (*)(...), fusion::vector1<int> >::type, int +// >::value )); + BOOST_TEST(( is_same< + boost::fusion::result_of::invoke<int (members::*)(), fusion::vector1<members*> >::type, int + >::value )); +// disabled until boost::result_of supports it +// BOOST_TEST(( is_same< +// boost::fusion::result_of::invoke<int (members::*)(...), fusion::vector2<members*,int> >::type, int +// >::value )); +} + +int main() +{ + result_type_tests(); + + 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); + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/functional/invoke_function_object.cpp b/libs/fusion/test/functional/invoke_function_object.cpp new file mode 100644 index 000000000..31357aa8c --- /dev/null +++ b/libs/fusion/test/functional/invoke_function_object.cpp @@ -0,0 +1,234 @@ +/*============================================================================= + Copyright (c) 2005-2006 Joao Abecasis + Copyright (c) 2006-2007 Tobias Schwinger + + Use modification and distribution are 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/functional/invocation/invoke_function_object.hpp> +#include <boost/detail/lightweight_test.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include <memory> +#include <boost/noncopyable.hpp> + +#include <boost/mpl/int.hpp> + +#include <boost/fusion/container/vector.hpp> +#include <boost/fusion/container/list.hpp> +#include <boost/fusion/sequence/intrinsic/size.hpp> +#include <boost/fusion/sequence/intrinsic/begin.hpp> +#include <boost/fusion/view/single_view.hpp> +#include <boost/fusion/view/iterator_range.hpp> +#include <boost/fusion/iterator/advance.hpp> +#include <boost/fusion/algorithm/transformation/join.hpp> + +namespace mpl = boost::mpl; +namespace fusion = boost::fusion; + +template <typename T> +inline T const & const_(T const & t) +{ + return t; +} + +struct object {}; +struct object_nc : boost::noncopyable {}; + +struct fobj +{ + // Handle nullary separately to exercise result_of support + template <typename Sig> + struct result; + + template <class Self, typename T0> + struct result< Self(T0) > + { + typedef int type; + }; + + template <class Self, typename T0, typename T1> + struct result< Self(T0, T1) > + { + typedef int type; + }; + + template <class Self, typename T0, typename T1, typename T2> + struct result< Self(T0, T1, T2) > + { + typedef int 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 &, object_nc &) { return 10 + i; } + int operator()(int i, object &, object_nc &) const { return 11 + i; } +}; + +struct nullary_fobj +{ + typedef int result_type; + + int operator()() { return 0; } + int operator()() const { return 1; } +}; + +struct fobj_nc + : boost::noncopyable +{ + // Handle nullary separately to exercise result_of support + template <typename T> + struct result; + + template <class Self, typename T0> + struct result< Self(T0) > + { + typedef int type; + }; + + int operator()(int i) { return 14 + i; } + int operator()(int i) const { return 15 + i; } +}; + +struct nullary_fobj_nc + : boost::noncopyable +{ + typedef int result_type; + + int operator()() { return 12; } + int operator()() const { return 13; } +}; + + +typedef int element1_type; +typedef object element2_type; +typedef object_nc & element3_type; + +int element1 = 100; +object element2 = object(); +object_nc element3; + +template <class Sequence> +void test_sequence_n(Sequence & seq, mpl::int_<0>) +{ + // Function Objects + + nullary_fobj f; + BOOST_TEST(f () == fusion::invoke_function_object(f , seq )); + BOOST_TEST(f () == fusion::invoke_function_object(f , const_(seq))); + + // Note: The function object is taken by value, so we request the copy + // to be const with an explicit template argument. We can also request + // the function object to be pased by reference... + BOOST_TEST(const_(f)() == fusion::invoke_function_object<nullary_fobj const >(const_(f), seq )); + BOOST_TEST(const_(f)() == fusion::invoke_function_object<nullary_fobj const &>(const_(f), const_(seq))); + + nullary_fobj_nc nc_f; + // ...and we further ensure there is no copying in this case, using a + // noncopyable function object. + BOOST_TEST(nc_f () == fusion::invoke_function_object<nullary_fobj_nc &>(nc_f , seq )); + BOOST_TEST(nc_f () == fusion::invoke_function_object<nullary_fobj_nc &>(nc_f , const_(seq))); + BOOST_TEST(const_(nc_f)() == fusion::invoke_function_object<nullary_fobj_nc const &>(const_(nc_f), seq )); + BOOST_TEST(const_(nc_f)() == fusion::invoke_function_object<nullary_fobj_nc const &>(const_(nc_f), const_(seq))); +} + +template <class Sequence> +void test_sequence_n(Sequence & seq, mpl::int_<1>) +{ + fobj f; + BOOST_TEST(f(element1) == fusion::invoke_function_object(f , seq )); + BOOST_TEST(f(element1) == fusion::invoke_function_object(f , const_(seq))); + BOOST_TEST(const_(f)(element1) == fusion::invoke_function_object<fobj const >(const_(f), seq )); + BOOST_TEST(const_(f)(element1) == fusion::invoke_function_object<fobj const &>(const_(f), const_(seq))); + + fobj_nc nc_f; + BOOST_TEST(nc_f(element1) == fusion::invoke_function_object<fobj_nc &>(nc_f, seq )); + BOOST_TEST(nc_f(element1) == fusion::invoke_function_object<fobj_nc &>(nc_f, const_(seq))); + BOOST_TEST(const_(nc_f)(element1) == fusion::invoke_function_object<fobj_nc const &>(const_(nc_f), seq )); + BOOST_TEST(const_(nc_f)(element1) == fusion::invoke_function_object<fobj_nc const &>(const_(nc_f), const_(seq))); +} + +template <class Sequence> +void test_sequence_n(Sequence & seq, mpl::int_<2>) +{ + fobj f; + BOOST_TEST(f (element1, element2) == fusion::invoke_function_object(f , seq)); + BOOST_TEST(f (element1, const_(element2)) == fusion::invoke_function_object(f , const_(seq))); + BOOST_TEST(const_(f)(element1, element2) == fusion::invoke_function_object<fobj const>(const_(f), seq)); + BOOST_TEST(const_(f)(element1, const_(element2)) == fusion::invoke_function_object<fobj const>(const_(f), const_(seq))); +} + +template <class Sequence> +void test_sequence_n(Sequence & seq, mpl::int_<3>) +{ + fobj f; + + BOOST_TEST(f(element1, element2, element3) == fusion::invoke_function_object(f, seq)); + BOOST_TEST(const_(f)(element1, element2, element3) == fusion::invoke_function_object<fobj const>(const_(f), seq)); +} + +template <class Sequence> +void test_sequence(Sequence & seq) +{ + test_sequence_n(seq, mpl::int_<boost::fusion::result_of::size<Sequence>::value>()); +} + +void result_type_tests() +{ + using boost::is_same; + + BOOST_TEST(( is_same< boost::fusion::result_of::invoke_function_object< nullary_fobj, fusion::vector<> >::type, int >::value )); + BOOST_TEST(( is_same< boost::fusion::result_of::invoke_function_object< fobj, fusion::vector<element1_type> >::type, int >::value )); + BOOST_TEST(( is_same< boost::fusion::result_of::invoke_function_object< fobj, fusion::vector<element1_type,element2_type> >::type, int >::value )); +} + + +int main() +{ + result_type_tests(); + + 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); + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/functional/invoke_procedure.cpp b/libs/fusion/test/functional/invoke_procedure.cpp new file mode 100644 index 000000000..f8db06cc9 --- /dev/null +++ b/libs/fusion/test/functional/invoke_procedure.cpp @@ -0,0 +1,284 @@ +/*============================================================================= + Copyright (c) 2005-2006 Joao Abecasis + Copyright (c) 2006-2007 Tobias Schwinger + + Use modification and distribution are 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/functional/invocation/invoke_procedure.hpp> +#include <boost/detail/lightweight_test.hpp> + +#include <memory> +#include <boost/noncopyable.hpp> + +#include <boost/mpl/int.hpp> + +#include <boost/fusion/container/vector.hpp> +#include <boost/fusion/container/list.hpp> +#include <boost/fusion/sequence/intrinsic/size.hpp> +#include <boost/fusion/sequence/intrinsic/begin.hpp> +#include <boost/fusion/view/single_view.hpp> +#include <boost/fusion/view/iterator_range.hpp> +#include <boost/fusion/iterator/advance.hpp> +#include <boost/fusion/algorithm/transformation/join.hpp> + +namespace mpl = boost::mpl; +namespace fusion = boost::fusion; + +template <typename T> +inline T const & const_(T const & t) +{ + return t; +} + +struct object {}; +struct object_nc : boost::noncopyable {}; + +typedef int element1_type; +typedef object element2_type; +typedef object_nc & element3_type; + +int element1 = 100; +object element2 = object(); +object_nc element3; + +class members +{ + public: + int data; + + members() + : data(20) + { } + + int nullary() { return element1 = data + 1; } + int nullary_c() const { return element1 = data + 2; } + int unary(int & i) { return i = data + 3; } + int unary_c(int & i) const { return i = data + 4; } + int binary(int & i, object) { return i = data + 5; } + int binary_c(int & i, object) const { return i = data + 6; } +}; + +members that; +std::auto_ptr<members> spt_that(new members); +std::auto_ptr<members const> spt_that_c(new members); + +fusion::single_view<members > sv_obj_ctx( that); +fusion::single_view<members &> sv_ref_ctx( that); +fusion::single_view<members *> sv_ptr_ctx(& that); +fusion::single_view<members const > sv_obj_c_ctx( that); +fusion::single_view<members const &> sv_ref_c_ctx( that); +fusion::single_view<members const *> sv_ptr_c_ctx(& that); +fusion::single_view<std::auto_ptr<members> const &> sv_spt_ctx(spt_that); +fusion::single_view< std::auto_ptr<members const> const &> sv_spt_c_ctx(spt_that_c); + +struct fobj +{ + int operator()() { return element1 = 0; } + int operator()() const { return element1 = 1; } + + int operator()(int & i) { return i = 2 ; } + int operator()(int & i) const { return i = 3; } + + int operator()(int & i, object &) { return i = 4; } + int operator()(int & i, object &) const { return i = 5; } + int operator()(int & i, object const &) { return i = 6; } + int operator()(int & i, object const &) const { return i = 7; } + + int operator()(int & i, object &, object_nc &) { return i = 10; } + int operator()(int & i, object &, object_nc &) const { return i = 11; } +}; + +struct fobj_nc + : boost::noncopyable +{ + int operator()() { return element1 = 12; } + int operator()() const { return element1 = 13; } + + int operator()(int & i) { return i = 14; } + int operator()(int & i) const { return i = 15; } +}; + +int nullary() { return element1 = 16; } +int unary(int & i) { return i = 17; } +int binary1(int & i, object &) { return i = 18; } +int binary2(int & i, object const &) { return i = 19; } + +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 = &unary; + c_func_ptr func_ptr2 = &unary; + v_func_ptr func_ptr3 = &unary; +cv_func_ptr func_ptr4 = &unary; + + + +#define COMPARE_EFFECT(e,t) \ + { \ + element1 = 1234567; e; \ + int expected = element1; \ + element1 = 1234567; t; \ + BOOST_TEST(expected == element1 ); \ + } + + +template <class Sequence> +void test_sequence_n(Sequence & seq, mpl::int_<0>) +{ + // Function Objects + + fobj f; + + COMPARE_EFFECT(f (), fusion::invoke_procedure(f , seq )); + COMPARE_EFFECT(f (), fusion::invoke_procedure(f , const_(seq))); + + // Note: The function object is taken by value, so we request the copy + // to be const with an explicit template argument. We can also request + // the function object to be pased by reference... + COMPARE_EFFECT(const_(f)(), fusion::invoke_procedure<fobj const >(const_(f), seq )); + COMPARE_EFFECT(const_(f)(), fusion::invoke_procedure<fobj const &>(const_(f), const_(seq))); + + fobj_nc nc_f; + // ...and we further ensure there is no copying in this case, using a + // noncopyable function object. + COMPARE_EFFECT(nc_f (), fusion::invoke_procedure<fobj_nc &>(nc_f , seq )); + COMPARE_EFFECT(nc_f (), fusion::invoke_procedure<fobj_nc &>(nc_f , const_(seq))); + COMPARE_EFFECT(const_(nc_f)(), fusion::invoke_procedure<fobj_nc const &>(const_(nc_f), seq )); + COMPARE_EFFECT(const_(nc_f)(), fusion::invoke_procedure<fobj_nc const &>(const_(nc_f), const_(seq))); + + // Builtin Functions + + // Call through ref/ptr to function + COMPARE_EFFECT(nullary(), fusion::invoke_procedure<int (&)()>(nullary, seq)); + COMPARE_EFFECT(nullary(), fusion::invoke_procedure(& nullary, seq)); + + // Call through ptr to member function + // Note: The non-const function members::nullary can't be invoked with + // fusion::join(sv_obj_ctx,seq)), which is const and so is its first element + COMPARE_EFFECT(that.nullary(), fusion::invoke_procedure(& members::nullary, fusion::join(sv_ref_ctx,seq))); + COMPARE_EFFECT(that.nullary(), fusion::invoke_procedure(& members::nullary, fusion::join(sv_ptr_ctx,seq))); + COMPARE_EFFECT(that.nullary(), fusion::invoke_procedure(& members::nullary, fusion::join(sv_spt_ctx,seq))); + COMPARE_EFFECT(that.nullary_c(), fusion::invoke_procedure(& members::nullary_c, fusion::join(sv_obj_ctx,seq))); + COMPARE_EFFECT(that.nullary_c(), fusion::invoke_procedure(& members::nullary_c, fusion::join(sv_ref_ctx,seq))); + COMPARE_EFFECT(that.nullary_c(), fusion::invoke_procedure(& members::nullary_c, fusion::join(sv_ptr_ctx,seq))); + COMPARE_EFFECT(that.nullary_c(), fusion::invoke_procedure(& members::nullary_c, fusion::join(sv_spt_ctx,seq))); + COMPARE_EFFECT(that.nullary_c(), fusion::invoke_procedure(& members::nullary_c, fusion::join(sv_obj_c_ctx,seq))); + COMPARE_EFFECT(that.nullary_c(), fusion::invoke_procedure(& members::nullary_c, fusion::join(sv_ref_c_ctx,seq))); + COMPARE_EFFECT(that.nullary_c(), fusion::invoke_procedure(& members::nullary_c, fusion::join(sv_ptr_c_ctx,seq))); + COMPARE_EFFECT(that.nullary_c(), fusion::invoke_procedure(& members::nullary_c, fusion::join(sv_spt_c_ctx,seq))); +} + +template <class Sequence> +void test_sequence_n(Sequence & seq, mpl::int_<1>) +{ + fobj f; + COMPARE_EFFECT(f(element1), fusion::invoke_procedure(f , seq )); + COMPARE_EFFECT(f(element1), fusion::invoke_procedure(f , const_(seq))); + COMPARE_EFFECT(const_(f)(element1), fusion::invoke_procedure<fobj const >(const_(f), seq )); + COMPARE_EFFECT(const_(f)(element1), fusion::invoke_procedure<fobj const &>(const_(f), const_(seq))); + + fobj_nc nc_f; + COMPARE_EFFECT(nc_f(element1), fusion::invoke_procedure<fobj_nc &>(nc_f, seq )); + COMPARE_EFFECT(nc_f(element1), fusion::invoke_procedure<fobj_nc &>(nc_f, const_(seq))); + COMPARE_EFFECT(const_(nc_f)(element1), fusion::invoke_procedure<fobj_nc const &>(const_(nc_f), seq )); + COMPARE_EFFECT(const_(nc_f)(element1), fusion::invoke_procedure<fobj_nc const &>(const_(nc_f), const_(seq))); + + COMPARE_EFFECT(unary(element1), fusion::invoke_procedure<int (&)(int &)>(unary, seq)); + COMPARE_EFFECT(func_ptr1(element1), fusion::invoke_procedure(func_ptr1, seq)); + COMPARE_EFFECT(func_ptr2(element1), fusion::invoke_procedure(func_ptr2, seq)); + COMPARE_EFFECT(func_ptr3(element1), fusion::invoke_procedure(func_ptr3, seq)); + COMPARE_EFFECT(func_ptr4(element1), fusion::invoke_procedure(func_ptr4, seq)); + + COMPARE_EFFECT(that.unary(element1), fusion::invoke_procedure(& members::unary, fusion::join(sv_ref_ctx,seq))); + COMPARE_EFFECT(that.unary(element1), fusion::invoke_procedure(& members::unary, fusion::join(sv_ptr_ctx,seq))); + COMPARE_EFFECT(that.unary(element1), fusion::invoke_procedure(& members::unary, fusion::join(sv_spt_ctx,seq))); + COMPARE_EFFECT(that.unary_c(element1), fusion::invoke_procedure(& members::unary_c, fusion::join(sv_obj_ctx,seq))); + COMPARE_EFFECT(that.unary_c(element1), fusion::invoke_procedure(& members::unary_c, fusion::join(sv_ref_ctx,seq))); + COMPARE_EFFECT(that.unary_c(element1), fusion::invoke_procedure(& members::unary_c, fusion::join(sv_ptr_ctx,seq))); + COMPARE_EFFECT(that.unary_c(element1), fusion::invoke_procedure(& members::unary_c, fusion::join(sv_spt_ctx,seq))); + COMPARE_EFFECT(that.unary_c(element1), fusion::invoke_procedure(& members::unary_c, fusion::join(sv_obj_c_ctx,seq))); + COMPARE_EFFECT(that.unary_c(element1), fusion::invoke_procedure(& members::unary_c, fusion::join(sv_ref_c_ctx,seq))); + COMPARE_EFFECT(that.unary_c(element1), fusion::invoke_procedure(& members::unary_c, fusion::join(sv_ptr_c_ctx,seq))); + COMPARE_EFFECT(that.unary_c(element1), fusion::invoke_procedure(& members::unary_c, fusion::join(sv_spt_c_ctx,seq))); +} + +template <class Sequence> +void test_sequence_n(Sequence & seq, mpl::int_<2>) +{ + fobj f; + COMPARE_EFFECT(f (element1, element2), fusion::invoke_procedure(f , seq)); + COMPARE_EFFECT(f (element1, const_(element2)), fusion::invoke_procedure(f , const_(seq))); + COMPARE_EFFECT(const_(f)(element1, element2), fusion::invoke_procedure<fobj const>(const_(f), seq)); + COMPARE_EFFECT(const_(f)(element1, const_(element2)), fusion::invoke_procedure<fobj const>(const_(f), const_(seq))); + + COMPARE_EFFECT(binary1(element1, element2), fusion::invoke_procedure(binary1, seq)); + COMPARE_EFFECT(binary2(element1, element2), fusion::invoke_procedure(binary2, seq)); + + COMPARE_EFFECT(that.binary(element1,element2), fusion::invoke_procedure(& members::binary, fusion::join(sv_ref_ctx,seq))); + COMPARE_EFFECT(that.binary(element1,element2), fusion::invoke_procedure(& members::binary, fusion::join(sv_ptr_ctx,seq))); + COMPARE_EFFECT(that.binary(element1,element2), fusion::invoke_procedure(& members::binary, fusion::join(sv_spt_ctx,seq))); + COMPARE_EFFECT(that.binary_c(element1,element2), fusion::invoke_procedure(& members::binary_c, fusion::join(sv_obj_ctx,seq))); + COMPARE_EFFECT(that.binary_c(element1,element2), fusion::invoke_procedure(& members::binary_c, fusion::join(sv_ref_ctx,seq))); + COMPARE_EFFECT(that.binary_c(element1,element2), fusion::invoke_procedure(& members::binary_c, fusion::join(sv_ptr_ctx,seq))); + COMPARE_EFFECT(that.binary_c(element1,element2), fusion::invoke_procedure(& members::binary_c, fusion::join(sv_spt_ctx,seq))); + COMPARE_EFFECT(that.binary_c(element1,element2), fusion::invoke_procedure(& members::binary_c, fusion::join(sv_obj_c_ctx,seq))); + COMPARE_EFFECT(that.binary_c(element1,element2), fusion::invoke_procedure(& members::binary_c, fusion::join(sv_ref_c_ctx,seq))); + COMPARE_EFFECT(that.binary_c(element1,element2), fusion::invoke_procedure(& members::binary_c, fusion::join(sv_ptr_c_ctx,seq))); + COMPARE_EFFECT(that.binary_c(element1,element2), fusion::invoke_procedure(& members::binary_c, fusion::join(sv_spt_c_ctx,seq))); +} + +template <class Sequence> +void test_sequence_n(Sequence & seq, mpl::int_<3>) +{ + fobj f; + + COMPARE_EFFECT(f(element1, element2, element3), fusion::invoke_procedure(f, seq)); + COMPARE_EFFECT(const_(f)(element1, element2, element3), fusion::invoke_procedure<fobj const>(const_(f), seq)); +} + +template <class Sequence> +void test_sequence(Sequence & seq) +{ + test_sequence_n(seq, mpl::int_<boost::fusion::result_of::size<Sequence>::value>()); +} + +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); + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/functional/make_fused.cpp b/libs/fusion/test/functional/make_fused.cpp new file mode 100644 index 000000000..a207359c7 --- /dev/null +++ b/libs/fusion/test/functional/make_fused.cpp @@ -0,0 +1,85 @@ +/*============================================================================= + Copyright (c) 2006-2007 Tobias Schwinger + + Use modification and distribution are 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/functional/generation/make_fused.hpp> +#include <boost/detail/lightweight_test.hpp> + +#include <boost/noncopyable.hpp> +#include <boost/blank.hpp> + +#include <boost/fusion/container/generation/make_vector.hpp> +#include <boost/fusion/container/vector.hpp> + +namespace fusion = boost::fusion; +using boost::noncopyable; +using boost::cref; +using boost::ref; + +template <class Base = boost::blank> +struct test_func + : Base +{ + typedef int result_type; + + template <typename T0, typename T1> + int operator()(T0 const & x, T1 const & y) const + { + return 1+x-y; + } + + template <typename T0, typename T1> + int operator()(T0 const & x, T1 const & y) + { + return 2+x-y; + } + + template <typename T0, typename T1> + int operator()(T0 & x, T1 & y) const + { + return 3+x-y; + } + + template <typename T0, typename T1> + int operator()(T0 & x, T1 & y) + { + return 4+x-y; + } +}; + +template <typename T> +inline T const & const_(T const & t) +{ + return t; +} + +int main() +{ + fusion::vector<int,char> lv_vec(1,'\004'); + test_func<> f; + test_func<noncopyable> f_nc; + + boost::fusion::result_of::make_fused< test_func<> >::type fused_func + = fusion::make_fused(f); + + BOOST_TEST(fused_func(lv_vec) == 1); + BOOST_TEST(const_(fused_func)(lv_vec) == 0); + BOOST_TEST(fusion::make_fused(const_(f))(lv_vec) == 1); + BOOST_TEST(fusion::make_fused(ref(f_nc))(lv_vec) == 1); + BOOST_TEST(fusion::make_fused(cref(f_nc))(lv_vec) == 0); + + BOOST_TEST(fused_func(fusion::make_vector(2,'\003')) == 1); + BOOST_TEST(const_(fused_func)(fusion::make_vector(2,'\003')) == 0); + BOOST_TEST(fusion::make_fused(const_(f))(fusion::make_vector(2,'\003')) == 1); + BOOST_TEST(fusion::make_fused(ref(f_nc))(fusion::make_vector(2,'\003')) == 1); + BOOST_TEST(fusion::make_fused(cref(f_nc))(fusion::make_vector(2,'\003')) == 0); + + return boost::report_errors(); +} + + + diff --git a/libs/fusion/test/functional/make_fused_function_object.cpp b/libs/fusion/test/functional/make_fused_function_object.cpp new file mode 100644 index 000000000..87ee8e233 --- /dev/null +++ b/libs/fusion/test/functional/make_fused_function_object.cpp @@ -0,0 +1,95 @@ +/*============================================================================= + Copyright (c) 2006-2007 Tobias Schwinger + + Use modification and distribution are 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/functional/generation/make_fused_function_object.hpp> +#include <boost/detail/lightweight_test.hpp> + +#include <boost/noncopyable.hpp> +#include <boost/blank.hpp> + +#include <boost/fusion/container/generation/make_vector.hpp> +#include <boost/fusion/container/vector.hpp> + +namespace fusion = boost::fusion; +using boost::noncopyable; +using boost::cref; +using boost::ref; + +template <class Base = boost::blank> +struct test_func + : Base +{ + template<typename T> + struct result + { + }; + + + template<class Self, typename T0, typename T1> + struct result< Self(T0, T1) > + { + typedef int type; + }; + + template <typename T0, typename T1> + int operator()(T0 const & x, T1 const & y) const + { + return 1+x-y; + } + + template <typename T0, typename T1> + int operator()(T0 const & x, T1 const & y) + { + return 2+x-y; + } + + template <typename T0, typename T1> + int operator()(T0 & x, T1 & y) const + { + return 3+x-y; + } + + template <typename T0, typename T1> + int operator()(T0 & x, T1 & y) + { + return 4+x-y; + } +}; + +template <typename T> +inline T const & const_(T const & t) +{ + return t; +} + +int main() +{ + fusion::vector<int,char> lv_vec(1,'\004'); + test_func<> f; + test_func<noncopyable> f_nc; + + boost::fusion::result_of::make_fused_function_object< test_func<> >::type fused_func + = fusion::make_fused_function_object(f); + + BOOST_TEST(fused_func(lv_vec) == 1); + BOOST_TEST(const_(fused_func)(lv_vec) == 0); + BOOST_TEST(fusion::make_fused_function_object(const_(f))(lv_vec) == 1); + BOOST_TEST(fusion::make_fused_function_object(ref(f_nc))(lv_vec) == 1); + BOOST_TEST(fusion::make_fused_function_object(cref(f_nc))(lv_vec) == 0); + + BOOST_TEST(fused_func(fusion::make_vector(2,'\003')) == 1); + BOOST_TEST(const_(fused_func)(fusion::make_vector(2,'\003')) == 0); + BOOST_TEST(fusion::make_fused_function_object(const_(f))(fusion::make_vector(2,'\003')) == 1); + BOOST_TEST(fusion::make_fused_function_object(ref(f_nc))(fusion::make_vector(2,'\003')) == 1); + BOOST_TEST(fusion::make_fused_function_object(cref(f_nc))(fusion::make_vector(2,'\003')) == 0); + + return boost::report_errors(); +} + + + diff --git a/libs/fusion/test/functional/make_fused_procedure.cpp b/libs/fusion/test/functional/make_fused_procedure.cpp new file mode 100644 index 000000000..ce7e267c8 --- /dev/null +++ b/libs/fusion/test/functional/make_fused_procedure.cpp @@ -0,0 +1,91 @@ +/*============================================================================= + Copyright (c) 2006-2007 Tobias Schwinger + + Use modification and distribution are 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/functional/generation/make_fused_procedure.hpp> +#include <boost/detail/lightweight_test.hpp> + +#include <boost/noncopyable.hpp> +#include <boost/blank.hpp> + +#include <boost/fusion/container/generation/make_vector.hpp> +#include <boost/fusion/container/vector.hpp> + +namespace fusion = boost::fusion; +using boost::noncopyable; +using boost::cref; +using boost::ref; + +int effect; + +#define CHECK_EFFECT(t,e) \ + { \ + effect = 1234567; t; \ + BOOST_TEST(effect == e); \ + } + +template <class Base = boost::blank> +struct test_func + : Base +{ + template <typename T0, typename T1> + int operator()(T0 const & x, T1 const & y) const + { + return effect = 1+x-y; + } + + template <typename T0, typename T1> + int operator()(T0 const & x, T1 const & y) + { + return effect = 2+x-y; + } + + template <typename T0, typename T1> + int operator()(T0 & x, T1 & y) const + { + return effect = 3+x-y; + } + + template <typename T0, typename T1> + int operator()(T0 & x, T1 & y) + { + return effect = 4+x-y; + } +}; + +template <typename T> +inline T const & const_(T const & t) +{ + return t; +} + +int main() +{ + fusion::vector<int,char> lv_vec(1,'\004'); + test_func<> f; + test_func<noncopyable> f_nc; + + boost::fusion::result_of::make_fused_procedure< test_func<> >::type fused_func + = fusion::make_fused_procedure(f); + + CHECK_EFFECT(fused_func(lv_vec), 1); + CHECK_EFFECT(const_(fused_func)(lv_vec), 0); + CHECK_EFFECT(fusion::make_fused_procedure(const_(f))(lv_vec), 1); + CHECK_EFFECT(fusion::make_fused_procedure(ref(f_nc))(lv_vec), 1); + CHECK_EFFECT(fusion::make_fused_procedure(cref(f_nc))(lv_vec), 0); + + CHECK_EFFECT(fused_func(fusion::make_vector(2,'\003')), 1); + CHECK_EFFECT(const_(fused_func)(fusion::make_vector(2,'\003')), 0); + CHECK_EFFECT(fusion::make_fused_procedure(const_(f))(fusion::make_vector(2,'\003')), 1); + CHECK_EFFECT(fusion::make_fused_procedure(ref(f_nc))(fusion::make_vector(2,'\003')), 1); + CHECK_EFFECT(fusion::make_fused_procedure(cref(f_nc))(fusion::make_vector(2,'\003')), 0); + + return boost::report_errors(); +} + + + diff --git a/libs/fusion/test/functional/make_unfused.cpp b/libs/fusion/test/functional/make_unfused.cpp new file mode 100644 index 000000000..1e2869183 --- /dev/null +++ b/libs/fusion/test/functional/make_unfused.cpp @@ -0,0 +1,126 @@ +/*============================================================================= + Copyright (c) 2006-2007 Tobias Schwinger + + Use modification and distribution are 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/functional/generation/make_unfused.hpp> +#include <boost/detail/lightweight_test.hpp> + +#include <boost/noncopyable.hpp> +#include <boost/blank.hpp> + +#include <boost/mpl/if.hpp> +#include <boost/mpl/and.hpp> +#include <boost/mpl/bool.hpp> +#include <boost/mpl/identity.hpp> + +#include <boost/utility/result_of.hpp> + +#include <boost/fusion/sequence/intrinsic/empty.hpp> +#include <boost/fusion/algorithm/iteration/fold.hpp> + +#include <boost/ref.hpp> + +namespace fusion = boost::fusion; +namespace mpl = boost::mpl; + +using boost::noncopyable; +typedef mpl::true_ no_nullary_call; + +using boost::ref; +using boost::cref; + +template <class Base = boost::blank, class RemoveNullary = mpl::false_> +struct test_func + : Base +{ + template <typename Sig> + struct result; + + template <class Self, class Seq> + struct result< Self(Seq &) > + : mpl::if_< mpl::and_< boost::fusion::result_of::empty<Seq>, RemoveNullary >, + boost::blank, mpl::identity<long> >::type + { }; + + template <typename Seq> + long operator()(Seq const & seq) const + { + long state = 0; + return fusion::fold(seq, state, fold_op()); + } + + template < typename Seq > + long operator()(Seq const & seq) + { + long state = 100; + return fusion::fold(seq, state, fold_op()); + } + + private: + + struct fold_op + { + typedef long result_type; + + template <typename T> + long operator()(long value, T & elem) const + { + elem += sizeof(T); + return value + elem; + } + }; +}; + +template <typename T> +inline T const & const_(T const & t) +{ + return t; +} + +int main() +{ + test_func<> f; + test_func<noncopyable> f_nc; + + boost::fusion::result_of::make_unfused< test_func<> >::type unfused_func = + fusion::make_unfused(f); + + boost::fusion::result_of::make_unfused< boost::reference_wrapper< + test_func<noncopyable> > >::type unfused_func_ref = + fusion::make_unfused(ref(f_nc)); + + boost::fusion::result_of::make_unfused< boost::reference_wrapper< + test_func<noncopyable> const> >::type unfused_func_c_ref = + fusion::make_unfused(cref(f_nc)); + + BOOST_TEST(unfused_func() == 100); + BOOST_TEST(const_(unfused_func)() == 0); + BOOST_TEST(unfused_func_ref() == 100); + BOOST_TEST(unfused_func_c_ref() == 0); + + long lv1 = 2; int lv2 = 3l; char lv3 = '\007'; + long expected; + + expected = lv1+sizeof(lv1) + lv2+sizeof(lv2) + lv3+sizeof(lv3); + BOOST_TEST(unfused_func(lv1,lv2,lv3) == 100 + expected); + BOOST_TEST(lv1 == 2+1*sizeof(lv1) && lv2 == 3+1*sizeof(lv2) && lv3 == 7+1*sizeof(lv3)); + + expected = lv1+sizeof(lv1) + lv2+sizeof(lv2) + lv3+sizeof(lv3); + BOOST_TEST(const_(unfused_func)(lv1,lv2,lv3) == 0 + expected); + BOOST_TEST(lv1 == 2+2*sizeof(lv1) && lv2 == 3+2*sizeof(lv2) && lv3 == 7+2*sizeof(lv3)); + + expected = lv1+sizeof(lv1) + lv2+sizeof(lv2) + lv3+sizeof(lv3); + BOOST_TEST(unfused_func_ref(lv1,lv2,lv3) == 100 + expected); + BOOST_TEST(lv1 == 2+3*sizeof(lv1) && lv2 == 3+3*sizeof(lv2) && lv3 == 7+3*sizeof(lv3)); + + expected = lv1+sizeof(lv1) + lv2+sizeof(lv2) + lv3+sizeof(lv3); + BOOST_TEST(unfused_func_c_ref(lv1,lv2,lv3) == 0 + expected); + BOOST_TEST(lv1 == 2+4*sizeof(lv1) && lv2 == 3+4*sizeof(lv2) && lv3 == 7+4*sizeof(lv3)); + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/functional/unfused.cpp b/libs/fusion/test/functional/unfused.cpp new file mode 100644 index 000000000..27a242a60 --- /dev/null +++ b/libs/fusion/test/functional/unfused.cpp @@ -0,0 +1,119 @@ +/*============================================================================= + Copyright (c) 2006-2007 Tobias Schwinger + + Use modification and distribution are 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/functional/adapter/unfused.hpp> +#include <boost/detail/lightweight_test.hpp> + +#include <boost/noncopyable.hpp> +#include <boost/blank.hpp> + +#include <boost/mpl/identity.hpp> + +#include <boost/utility/result_of.hpp> + +#include <boost/fusion/sequence/intrinsic/empty.hpp> +#include <boost/fusion/algorithm/iteration/fold.hpp> + +namespace fusion = boost::fusion; +namespace mpl = boost::mpl; + +using boost::noncopyable; + +template <class Base = boost::blank> +struct test_func + : Base +{ + template <typename Sig> + struct result; + + template <class Self, class Seq> + struct result< Self(Seq) > + : mpl::identity<long> + { }; + + template <typename Seq> + long operator()(Seq const & seq) const + { + long state = 0; + return fusion::fold(seq, state, fold_op()); + } + + template <typename Seq> + long operator()(Seq const & seq) + { + long state = 100; + return fusion::fold(seq, state, fold_op()); + } + + private: + + struct fold_op + { + typedef long result_type; + + template <typename T> + long operator()(long value, T & elem) const + { + elem += sizeof(T); + return value + elem; + } + }; +}; + +void result_type_tests() +{ + using boost::is_same; + + typedef fusion::unfused< test_func<> > t; + BOOST_TEST(( is_same< boost::result_of< t () >::type, long >::value )); + BOOST_TEST(( is_same< boost::result_of< t (int) >::type, long >::value )); +} + +int main() +{ + result_type_tests(); + + test_func<noncopyable> f; + fusion::unfused< test_func<> > unfused_func; + fusion::unfused< test_func<noncopyable> & > unfused_func_ref(f); + fusion::unfused< test_func<> const > unfused_func_c; + fusion::unfused< test_func<> > const unfused_func_c2; + fusion::unfused< test_func<noncopyable> const & > unfused_func_c_ref(f); + + BOOST_TEST(unfused_func() == 100); + BOOST_TEST(unfused_func_ref() == 100); + BOOST_TEST(unfused_func_c() == 0); + BOOST_TEST(unfused_func_c2() == 0); + BOOST_TEST(unfused_func_c_ref() == 0); + + long lv1 = 2; int lv2 = 3l; char lv3 = '\007'; + long expected; + + expected = lv1+sizeof(lv1) + lv2+sizeof(lv2) + lv3+sizeof(lv3); + BOOST_TEST(unfused_func(lv1,lv2,lv3) == 100 + expected); + BOOST_TEST(lv1 == 2+1*sizeof(lv1) && lv2 == 3+1*sizeof(lv2) && lv3 == 7+1*sizeof(lv3)); + + expected = lv1+sizeof(lv1) + lv2+sizeof(lv2) + lv3+sizeof(lv3); + BOOST_TEST(unfused_func_ref(lv1,lv2,lv3) == 100 + expected); + BOOST_TEST(lv1 == 2+2*sizeof(lv1) && lv2 == 3+2*sizeof(lv2) && lv3 == 7+2*sizeof(lv3)); + + expected = lv1+sizeof(lv1) + lv2+sizeof(lv2) + lv3+sizeof(lv3); + BOOST_TEST(unfused_func_c(lv1,lv2,lv3) == 0 + expected); + BOOST_TEST(lv1 == 2+3*sizeof(lv1) && lv2 == 3+3*sizeof(lv2) && lv3 == 7+3*sizeof(lv3)); + + expected = lv1+sizeof(lv1) + lv2+sizeof(lv2) + lv3+sizeof(lv3); + BOOST_TEST(unfused_func_c2(lv1,lv2,lv3) == 0 + expected); + BOOST_TEST(lv1 == 2+4*sizeof(lv1) && lv2 == 3+4*sizeof(lv2) && lv3 == 7+4*sizeof(lv3)); + + expected = lv1+sizeof(lv1) + lv2+sizeof(lv2) + lv3+sizeof(lv3); + BOOST_TEST(unfused_func_c_ref(lv1,lv2,lv3) == 0 + expected); + BOOST_TEST(lv1 == 2+5*sizeof(lv1) && lv2 == 3+5*sizeof(lv2) && lv3 == 7+5*sizeof(lv3)); + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/functional/unfused_typed.cpp b/libs/fusion/test/functional/unfused_typed.cpp new file mode 100644 index 000000000..85783c866 --- /dev/null +++ b/libs/fusion/test/functional/unfused_typed.cpp @@ -0,0 +1,167 @@ +/*============================================================================= + Copyright (c) 2006-2007 Tobias Schwinger + + Use modification and distribution are 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/functional/adapter/unfused_typed.hpp> +#include <boost/detail/lightweight_test.hpp> + +#include <boost/blank.hpp> +#include <boost/noncopyable.hpp> + +#include <boost/utility/result_of.hpp> + +#include <boost/mpl/identity.hpp> +#include <boost/mpl/placeholders.hpp> + +#include <boost/utility/result_of.hpp> + +#include <boost/fusion/algorithm/iteration/fold.hpp> + +namespace fusion = boost::fusion; +namespace mpl = boost::mpl; +using mpl::placeholders::_; + +using boost::noncopyable; + +typedef fusion::vector<> types0; +typedef fusion::vector<long &> types1; +typedef fusion::vector<long &,int,char> types3; + +template <class Base = boost::blank> +struct test_func + : Base +{ + template<typename T> + struct result; + + template <class Self, class Seq> + struct result< Self(Seq) > + : mpl::identity<long> + { }; + + template <typename Seq> + long operator()(Seq const & seq) const + { + long state = 0; + return fusion::fold(seq, state, fold_op()); + } + + template < typename Seq > + long operator()(Seq const & seq) + { + long state = 100; + return fusion::fold(seq, state, fold_op()); + } + + private: + + struct fold_op + { + typedef long result_type; + + template <typename T> + long operator()(long value, T const & elem) const + { + return value + sizeof(T) * elem; + } + + template <typename T> + long operator()(long value, T & elem) const + { + elem += sizeof(T); + return value; + } + }; +}; + +void result_type_tests() +{ + using boost::is_same; + + typedef fusion::unfused_typed< test_func<>, types0 > t0; + BOOST_TEST(( is_same< boost::result_of< t0 () >::type, long >::value )); + typedef fusion::unfused_typed< test_func<>, types1 > t1; + BOOST_TEST(( is_same< boost::result_of< t1 (int) >::type, long >::value )); +} + +#if defined(BOOST_MSVC) && BOOST_MSVC < 1400 +# define BOOST_TEST_NO_VC71(cond) (void)((cond)?0:1) +#else +# define BOOST_TEST_NO_VC71(cond) BOOST_TEST(cond) +#endif + +void nullary_tests() +{ + test_func<noncopyable> f; + fusion::unfused_typed< test_func<>, types0 > unfused_func; + fusion::unfused_typed< test_func<noncopyable> &, types0 > unfused_func_ref(f); + fusion::unfused_typed< test_func<> const, types0 > unfused_func_c; + fusion::unfused_typed< test_func<>, types0 > const unfused_func_c2; + fusion::unfused_typed< test_func<noncopyable> const &, types0 > unfused_func_c_ref(f); + + BOOST_TEST(unfused_func() == 100); + BOOST_TEST(unfused_func_ref() == 100); + BOOST_TEST(unfused_func_c() == 0); + BOOST_TEST(unfused_func_c2() == 0); + BOOST_TEST(unfused_func_c_ref() == 0); +} + +void unary_tests() +{ + test_func<noncopyable> f; + fusion::unfused_typed< test_func<>, types1 > unfused_func; + fusion::unfused_typed< test_func<noncopyable> &, types1 > unfused_func_ref(f); + fusion::unfused_typed< test_func<> const, types1 > unfused_func_c; + fusion::unfused_typed< test_func<>, types1 > const unfused_func_c2; + fusion::unfused_typed< test_func<noncopyable> const &, types1 > unfused_func_c_ref(f); + + long lvalue = 1; + BOOST_TEST_NO_VC71(unfused_func(lvalue) == 100); + BOOST_TEST(lvalue == 1 + 1*sizeof(lvalue)); + BOOST_TEST(unfused_func_ref(lvalue) == 100); + BOOST_TEST(lvalue == 1 + 2*sizeof(lvalue)); + BOOST_TEST(unfused_func_c(lvalue) == 0); + BOOST_TEST(lvalue == 1 + 3*sizeof(lvalue)); + BOOST_TEST(unfused_func_c2(lvalue) == 0); + BOOST_TEST(lvalue == 1 + 4*sizeof(lvalue)); + BOOST_TEST(unfused_func_c_ref(lvalue) == 0); + BOOST_TEST(lvalue == 1 + 5*sizeof(lvalue)); +} + +void ternary_tests() +{ + test_func<noncopyable> f; + fusion::unfused_typed< test_func<>, types3 > unfused_func; + fusion::unfused_typed< test_func<noncopyable> &, types3 > unfused_func_ref(f); + fusion::unfused_typed< test_func<> const, types3 > unfused_func_c; + fusion::unfused_typed< test_func<>, types3 > const unfused_func_c2; + fusion::unfused_typed< test_func<noncopyable> const &, types3 > unfused_func_c_ref(f); + + long lvalue = 1; + static const long expected = 2*sizeof(int) + 7*sizeof(char); + BOOST_TEST_NO_VC71(unfused_func(lvalue,2,'\007') == 100 + expected); + BOOST_TEST(lvalue == 1 + 1*sizeof(lvalue)); + BOOST_TEST(unfused_func_ref(lvalue,2,'\007') == 100 + expected); + BOOST_TEST(lvalue == 1 + 2*sizeof(lvalue)); + BOOST_TEST(unfused_func_c(lvalue,2,'\007') == 0 + expected); + BOOST_TEST(lvalue == 1 + 3*sizeof(lvalue)); + BOOST_TEST(unfused_func_c2(lvalue,2,'\007') == 0 + expected); + BOOST_TEST(lvalue == 1 + 4*sizeof(lvalue)); + BOOST_TEST(unfused_func_c_ref(lvalue,2,'\007') == 0 + expected); + BOOST_TEST(lvalue == 1 + 5*sizeof(lvalue)); +} + +int main() +{ + result_type_tests(); + nullary_tests(); + unary_tests(); + ternary_tests(); + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/adapt_adt.cpp b/libs/fusion/test/sequence/adapt_adt.cpp new file mode 100644 index 000000000..f8762b038 --- /dev/null +++ b/libs/fusion/test/sequence/adapt_adt.cpp @@ -0,0 +1,240 @@ +/*============================================================================= + Copyright (c) 2001-2009 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/adapted/adt/adapt_adt.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/intrinsic/value_at.hpp> +#include <boost/fusion/sequence/io/out.hpp> +#include <boost/fusion/container/vector/vector.hpp> +#include <boost/fusion/container/list/list.hpp> +#include <boost/fusion/container/generation/make_vector.hpp> +#include <boost/fusion/container/vector/convert.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/mpl.hpp> +#include <boost/fusion/support/is_view.hpp> +#include <boost/mpl/front.hpp> +#include <boost/mpl/is_sequence.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/type_traits/is_same.hpp> +#include <iostream> +#include <string> + +namespace ns +{ + class point + { + public: + + point() : x(0), y(0) {} + point(int in_x, int in_y) : x(in_x), y(in_y) {} + + int get_x() const { return x; } + int get_y() const { return y; } + void set_x(int x_) { x = x_; } + void set_y(int y_) { y = y_; } + + private: + + int x; + int y; + }; + +#if !BOOST_WORKAROUND(__GNUC__,<4) + class point_with_private_members + { + friend struct boost::fusion::extension::access; + + public: + point_with_private_members() : x(0), y(0) {} + point_with_private_members(int x, int y) : x(x), y(y) {} + + private: + int get_x() const { return x; } + int get_y() const { return y; } + void set_x(int x_) { x = x_; } + void set_y(int y_) { y = y_; } + + int x; + int y; + }; +#endif + + // A sequence that has data members defined in an unrelated namespace + // (std, in this case). This allows testing ADL issues. + class name + { + public: + name() {} + name(const std::string& last, const std::string& first) + : last(last), first(first) {} + + const std::string& get_last() const { return last; } + const std::string& get_first() const { return first; } + void set_last(const std::string& last_) { last = last_; } + void set_first(const std::string& first_) { first = first_; } + private: + std::string last; + std::string first; + }; +} + +BOOST_FUSION_ADAPT_ADT( + ns::point, + (int, int, obj.get_x(), obj.set_x(val)) + (int, int, obj.get_y(), obj.set_y(val)) +) + +#if !BOOST_WORKAROUND(__GNUC__,<4) +BOOST_FUSION_ADAPT_ADT( + ns::point_with_private_members, + (int, int, obj.get_x(), obj.set_x(val)) + (int, int, obj.get_y(), obj.set_y(val)) +) +#endif + +BOOST_FUSION_ADAPT_ADT( + ns::name, + (const std::string&, const std::string&, obj.get_last(), obj.set_last(val)) + (const std::string&, const std::string&, obj.get_first(), obj.set_first(val)) +) + +int +main() +{ + using namespace boost::fusion; + using namespace boost; + + std::cout << tuple_open('['); + std::cout << tuple_close(']'); + std::cout << tuple_delimiter(", "); + + { + BOOST_MPL_ASSERT_NOT((traits::is_view<ns::point>)); + ns::point p(123, 456); + + 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, 456)); + + at_c<0>(p) = 6; + at_c<1>(p) = 9; + BOOST_TEST(p == make_vector(6, 9)); + + BOOST_STATIC_ASSERT(boost::fusion::result_of::size<ns::point>::value == 2); + BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<ns::point>::value); + + BOOST_TEST(front(p) == 6); + BOOST_TEST(back(p) == 9); + } + + { + fusion::vector<int, float> v1(4, 2); + ns::point v2(5, 3); + fusion::vector<long, double> v3(5, 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); + } + + { + fusion::vector<std::string, std::string> v1("Lincoln", "Abraham"); + ns::name v2("Roosevelt", "Franklin"); + ns::name v3("Roosevelt", "Theodore"); + 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 ns::point to vector + ns::point p(5, 3); + fusion::vector<int, long> v(p); + v = p; + } + + { + // conversion from ns::point to list + ns::point p(5, 3); + fusion::list<int, long> l(p); + l = p; + } + + { + BOOST_MPL_ASSERT((mpl::is_sequence<ns::point>)); + BOOST_MPL_ASSERT((boost::is_same< + boost::fusion::result_of::value_at_c<ns::point,0>::type + , mpl::front<ns::point>::type>)); + } + +#if !BOOST_WORKAROUND(__GNUC__,<4) + { + BOOST_MPL_ASSERT_NOT((traits::is_view<ns::point_with_private_members>)); + ns::point_with_private_members p(123, 456); + + 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, 456)); + + at_c<0>(p) = 6; + at_c<1>(p) = 9; + BOOST_TEST(p == make_vector(6, 9)); + + BOOST_STATIC_ASSERT(boost::fusion::result_of::size<ns::point_with_private_members>::value == 2); + BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<ns::point_with_private_members>::value); + + BOOST_TEST(front(p) == 6); + BOOST_TEST(back(p) == 9); + } +#endif + + { + BOOST_MPL_ASSERT(( + boost::is_same< + boost::fusion::result_of::front<ns::point>::type, + boost::fusion::extension::adt_attribute_proxy<ns::point,0,false> + >)); + BOOST_MPL_ASSERT(( + boost::is_same< + boost::fusion::result_of::front<ns::point>::type::type, + int + >)); + BOOST_MPL_ASSERT(( + boost::is_same< + boost::fusion::result_of::front<ns::point const>::type, + boost::fusion::extension::adt_attribute_proxy<ns::point,0,true> + >)); + BOOST_MPL_ASSERT(( + boost::is_same< + boost::fusion::result_of::front<ns::point const>::type::type, + int + >)); + } + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/adapt_adt_named.cpp b/libs/fusion/test/sequence/adapt_adt_named.cpp new file mode 100644 index 000000000..384156337 --- /dev/null +++ b/libs/fusion/test/sequence/adapt_adt_named.cpp @@ -0,0 +1,136 @@ +/*============================================================================= + Copyright (c) 2001-2009 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/adapted/adt/adapt_adt_named.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/intrinsic/value_at.hpp> +#include <boost/fusion/sequence/io/out.hpp> +#include <boost/fusion/container/vector/vector.hpp> +#include <boost/fusion/container/list/list.hpp> +#include <boost/fusion/container/generation/make_vector.hpp> +#include <boost/fusion/container/vector/convert.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/mpl.hpp> +#include <boost/fusion/support/is_view.hpp> +#include <boost/mpl/front.hpp> +#include <boost/mpl/is_sequence.hpp> +#include <boost/mpl/assert.hpp> +#include <iostream> +#include <string> + +namespace ns +{ + class point + { + public: + + point() : x(0), y(0) {} + point(int in_x, int in_y) : x(in_x), y(in_y) {} + + int get_x() const { return x; } + int get_y() const { return y; } + void set_x(int x_) { x = x_; } + void set_y(int y_) { y = y_; } + + private: + + int x; + int y; + }; +} + +// this creates a fusion view: boost::fusion::adapted::point +BOOST_FUSION_ADAPT_ADT_NAMED( + ns::point, point, + (int, int, obj.obj.get_x(), obj.obj.set_x(val)) + (int, int, obj.obj.get_y(), obj.obj.set_y(val)) +) + +int +main() +{ + using namespace boost::fusion; + using namespace boost; + + std::cout << tuple_open('['); + std::cout << tuple_close(']'); + std::cout << tuple_delimiter(", "); + + { + BOOST_MPL_ASSERT((traits::is_view<adapted::point>)); + ns::point basep(123, 456); + adapted::point p(basep); + + 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, 456)); + + at_c<0>(p) = 6; + at_c<1>(p) = 9; + BOOST_TEST(p == make_vector(6, 9)); + + BOOST_STATIC_ASSERT(boost::fusion::result_of::size<adapted::point>::value == 2); + BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<adapted::point>::value); + + BOOST_TEST(front(p) == 6); + BOOST_TEST(back(p) == 9); + } + + { + fusion::vector<int, float> v1(4, 2); + ns::point basep(5, 3); + adapted::point v2(basep); + + fusion::vector<long, double> v3(5, 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 ns::point to vector + ns::point basep(5, 3); + adapted::point p(basep); + + fusion::vector<int, long> v(p); + v = p; + } + + { + // conversion from ns::point to list + ns::point basep(5, 3); + adapted::point p(basep); + + fusion::list<int, long> l(p); + l = p; + } + + { + BOOST_MPL_ASSERT((mpl::is_sequence<adapted::point>)); + BOOST_MPL_ASSERT((boost::is_same< + boost::fusion::result_of::value_at_c<adapted::point,0>::type + , mpl::front<adapted::point>::type>)); + } + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/adapt_assoc_adt.cpp b/libs/fusion/test/sequence/adapt_assoc_adt.cpp new file mode 100644 index 000000000..c97e84b0a --- /dev/null +++ b/libs/fusion/test/sequence/adapt_assoc_adt.cpp @@ -0,0 +1,135 @@ +/*============================================================================= + Copyright (c) 2010 Christopher Schmidt + + 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/sequence.hpp> +#include <boost/fusion/support.hpp> +#include <boost/fusion/container/list.hpp> +#include <boost/fusion/container/vector.hpp> +#include <boost/fusion/container/generation/make_vector.hpp> +#include <boost/fusion/adapted/adt/adapt_assoc_adt.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/mpl/not.hpp> +#include <boost/mpl/front.hpp> +#include <boost/mpl/is_sequence.hpp> +#include <boost/type_traits/is_same.hpp> +#include <boost/static_assert.hpp> +#include <iostream> +#include <string> + +namespace ns +{ + struct x_member; + struct y_member; + struct z_member; + + class point + { + public: + + point() : x(0), y(0) {} + point(int in_x, int in_y) : x(in_x), y(in_y) {} + + int get_x() const { return x; } + int get_y() const { return y; } + void set_x(int x_) { x = x_; } + void set_y(int y_) { y = y_; } + + private: + + int x; + int y; + }; +} + +BOOST_FUSION_ADAPT_ASSOC_ADT( + ns::point, + (int, int, obj.get_x(), obj.set_x(val), ns::x_member) + (int, int, obj.get_y(), obj.set_y(val), ns::y_member) +) + +int +main() +{ + using namespace boost::fusion; + + std::cout << tuple_open('['); + std::cout << tuple_close(']'); + std::cout << tuple_delimiter(", "); + + { + BOOST_MPL_ASSERT_NOT((traits::is_view<ns::point>)); + ns::point p(123, 456); + + 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, 456)); + + at_c<0>(p) = 6; + at_c<1>(p) = 9; + BOOST_TEST(p == make_vector(6, 9)); + + BOOST_STATIC_ASSERT(boost::fusion::result_of::size<ns::point>::value == 2); + BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<ns::point>::value); + + BOOST_TEST(front(p) == 6); + BOOST_TEST(back(p) == 9); + } + + { + boost::fusion::vector<int, float> v1(4, 2); + ns::point v2(5, 3); + boost::fusion::vector<long, double> v3(5, 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 ns::point to vector + ns::point p(5, 3); + boost::fusion::vector<int, long> v(p); + v = p; + } + + { + // conversion from ns::point to list + ns::point p(5, 3); + boost::fusion::list<int, long> l(p); + l = p; + } + + { + BOOST_MPL_ASSERT((boost::mpl::is_sequence<ns::point>)); + BOOST_MPL_ASSERT((boost::is_same< + boost::fusion::result_of::value_at_c<ns::point,0>::type + , boost::mpl::front<ns::point>::type>)); + } + + { + // assoc stuff + BOOST_MPL_ASSERT((boost::fusion::result_of::has_key<ns::point, ns::x_member>)); + BOOST_MPL_ASSERT((boost::fusion::result_of::has_key<ns::point, ns::y_member>)); + BOOST_MPL_ASSERT((boost::mpl::not_<boost::fusion::result_of::has_key<ns::point, ns::z_member> >)); + + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_at_key<ns::point, ns::x_member>::type, int>)); + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_at_key<ns::point, ns::y_member>::type, int>)); + + ns::point p(5, 3); + + BOOST_TEST(at_key<ns::x_member>(p) == 5); + BOOST_TEST(at_key<ns::y_member>(p) == 3); + } + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/adapt_assoc_adt_named.cpp b/libs/fusion/test/sequence/adapt_assoc_adt_named.cpp new file mode 100644 index 000000000..d68d99040 --- /dev/null +++ b/libs/fusion/test/sequence/adapt_assoc_adt_named.cpp @@ -0,0 +1,141 @@ +/*============================================================================= + Copyright (c) 2010 Christopher Schmidt + + 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/sequence.hpp> +#include <boost/fusion/support.hpp> +#include <boost/fusion/container/list.hpp> +#include <boost/fusion/container/vector.hpp> +#include <boost/fusion/container/generation/make_vector.hpp> +#include <boost/fusion/adapted/adt/adapt_assoc_adt_named.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/mpl/not.hpp> +#include <boost/mpl/front.hpp> +#include <boost/mpl/is_sequence.hpp> +#include <boost/type_traits/is_same.hpp> +#include <boost/static_assert.hpp> +#include <iostream> +#include <string> + +namespace ns +{ + struct x_member; + struct y_member; + struct z_member; + + class point + { + public: + + point() : x(0), y(0) {} + point(int in_x, int in_y) : x(in_x), y(in_y) {} + + int get_x() const { return x; } + int get_y() const { return y; } + void set_x(int x_) { x = x_; } + void set_y(int y_) { y = y_; } + + private: + + int x; + int y; + }; +} + +BOOST_FUSION_ADAPT_ASSOC_ADT_NAMED( + ns::point, + point, + (int, int, obj.obj.get_x(), obj.obj.set_x(val), ns::x_member) + (int, int, obj.obj.get_y(), obj.obj.set_y(val), ns::y_member) +) + +int +main() +{ + using namespace boost::fusion; + + std::cout << tuple_open('['); + std::cout << tuple_close(']'); + std::cout << tuple_delimiter(", "); + + { + BOOST_MPL_ASSERT((traits::is_view<adapted::point>)); + ns::point basep(123, 456); + adapted::point p(basep); + + 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, 456)); + + at_c<0>(p) = 6; + at_c<1>(p) = 9; + BOOST_TEST(p == make_vector(6, 9)); + + BOOST_STATIC_ASSERT(boost::fusion::result_of::size<adapted::point>::value == 2); + BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<adapted::point>::value); + + BOOST_TEST(front(p) == 6); + BOOST_TEST(back(p) == 9); + } + + { + boost::fusion::vector<int, float> v1(4, 2); + ns::point basev2(5, 3); + adapted::point v2(basev2); + boost::fusion::vector<long, double> v3(5, 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 adapted::point to vector + ns::point basep(5, 3); + adapted::point p(basep); + boost::fusion::vector<int, long> v(p); + v = p; + } + + { + // conversion from adated::point to list + ns::point basep(5, 3); + adapted::point p(basep); + boost::fusion::list<int, long> l(p); + l = p; + } + + { + BOOST_MPL_ASSERT((boost::mpl::is_sequence<adapted::point>)); + BOOST_MPL_ASSERT((boost::is_same< + boost::fusion::result_of::value_at_c<adapted::point,0>::type + , boost::mpl::front<adapted::point>::type>)); + } + + { + // assoc stuff + BOOST_MPL_ASSERT((boost::fusion::result_of::has_key<adapted::point, ns::x_member>)); + BOOST_MPL_ASSERT((boost::fusion::result_of::has_key<adapted::point, ns::y_member>)); + BOOST_MPL_ASSERT((boost::mpl::not_<boost::fusion::result_of::has_key<adapted::point, ns::z_member> >)); + + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_at_key<adapted::point, ns::x_member>::type, int>)); + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_at_key<adapted::point, ns::y_member>::type, int>)); + + ns::point basep(5, 3); + adapted::point p(basep); + + BOOST_TEST(at_key<ns::x_member>(p) == 5); + BOOST_TEST(at_key<ns::y_member>(p) == 3); + } + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/adapt_assoc_struct.cpp b/libs/fusion/test/sequence/adapt_assoc_struct.cpp new file mode 100644 index 000000000..62574a7ec --- /dev/null +++ b/libs/fusion/test/sequence/adapt_assoc_struct.cpp @@ -0,0 +1,141 @@ +/*============================================================================= + Copyright (c) 2001-2007 Joel de Guzman + Copyright (c) 2005-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/adapted/struct/adapt_assoc_struct.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/intrinsic/has_key.hpp> +#include <boost/fusion/sequence/intrinsic/at_key.hpp> +#include <boost/fusion/sequence/intrinsic/value_at.hpp> +#include <boost/fusion/sequence/intrinsic/value_at_key.hpp> +#include <boost/fusion/sequence/io/out.hpp> +#include <boost/fusion/container/vector/vector.hpp> +#include <boost/fusion/container/list/list.hpp> +#include <boost/fusion/container/generation/make_vector.hpp> +#include <boost/fusion/container/vector/convert.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/mpl.hpp> +#include <boost/fusion/support/is_view.hpp> +#include <boost/mpl/front.hpp> +#include <boost/mpl/is_sequence.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/mpl/not.hpp> +#include <boost/type_traits/is_same.hpp> +#include <iostream> +#include <string> + +namespace ns +{ + struct x_member; + struct y_member; + struct z_member; + + struct point + { + int x; + int y; + }; +} + +BOOST_FUSION_ADAPT_ASSOC_STRUCT( + ns::point, + (int, x, ns::x_member) + (int, y, ns::y_member) +) + +int +main() +{ + using namespace boost::fusion; + using namespace boost; + + std::cout << tuple_open('['); + std::cout << tuple_close(']'); + std::cout << tuple_delimiter(", "); + + { + BOOST_MPL_ASSERT_NOT((traits::is_view<ns::point>)); + ns::point p = {123, 456}; + + 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, 456)); + + at_c<0>(p) = 6; + at_c<1>(p) = 9; + BOOST_TEST(p == make_vector(6, 9)); + + BOOST_STATIC_ASSERT(boost::fusion::result_of::size<ns::point>::value == 2); + BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<ns::point>::value); + + BOOST_TEST(front(p) == 6); + BOOST_TEST(back(p) == 9); + } + + { + fusion::vector<int, float> v1(4, 2); + ns::point v2 = {5, 3}; + fusion::vector<long, double> v3(5, 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 ns::point to vector + ns::point p = {5, 3}; + fusion::vector<int, long> v(p); + v = p; + } + + { + // conversion from ns::point to list + ns::point p = {5, 3}; + fusion::list<int, long> l(p); + l = p; + } + + { + // assoc stuff + BOOST_MPL_ASSERT((boost::fusion::result_of::has_key<ns::point, ns::x_member>)); + BOOST_MPL_ASSERT((boost::fusion::result_of::has_key<ns::point, ns::y_member>)); + BOOST_MPL_ASSERT((mpl::not_<boost::fusion::result_of::has_key<ns::point, ns::z_member> >)); + + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_at_key<ns::point, ns::x_member>::type, int>)); + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_at_key<ns::point, ns::y_member>::type, int>)); + + ns::point p = {5, 3}; + + BOOST_TEST(at_key<ns::x_member>(p) == 5); + BOOST_TEST(at_key<ns::y_member>(p) == 3); + } + + { + BOOST_MPL_ASSERT((mpl::is_sequence<ns::point>)); + BOOST_MPL_ASSERT((boost::is_same< + boost::fusion::result_of::value_at_c<ns::point,0>::type + , mpl::front<ns::point>::type>)); + } + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/adapt_assoc_struct_named.cpp b/libs/fusion/test/sequence/adapt_assoc_struct_named.cpp new file mode 100644 index 000000000..f24dadd95 --- /dev/null +++ b/libs/fusion/test/sequence/adapt_assoc_struct_named.cpp @@ -0,0 +1,121 @@ +/*============================================================================= + Copyright (c) 2010 Christopher Schmidt + + 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/sequence.hpp> +#include <boost/fusion/support.hpp> +#include <boost/fusion/container/list.hpp> +#include <boost/fusion/container/vector.hpp> +#include <boost/fusion/container/generation/make_vector.hpp> +#include <boost/fusion/adapted/struct/adapt_assoc_struct_named.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/mpl/not.hpp> +#include <boost/type_traits/is_same.hpp> +#include <boost/static_assert.hpp> +#include <iostream> +#include <string> + +namespace ns +{ + struct x_member; + struct y_member; + struct z_member; + + struct point + { + int x; + int y; + }; +} + +BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED( + ns::point, + point, + (int, x, ns::x_member) + (int, y, ns::y_member) +) + +int +main() +{ + using namespace boost::fusion; + + std::cout << tuple_open('['); + std::cout << tuple_close(']'); + std::cout << tuple_delimiter(", "); + + { + BOOST_MPL_ASSERT((traits::is_view<adapted::point>)); + ns::point basep = {123, 456}; + adapted::point p(basep); + + 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, 456)); + + at_c<0>(p) = 6; + at_c<1>(p) = 9; + BOOST_TEST(p == make_vector(6, 9)); + + BOOST_STATIC_ASSERT(boost::fusion::result_of::size<adapted::point>::value == 2); + BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<adapted::point>::value); + + BOOST_TEST(front(p) == 6); + BOOST_TEST(back(p) == 9); + } + + { + vector<int, float> v1(4, 2); + ns::point basev2 = {5, 3}; + adapted::point v2(basev2); + + vector<long, double> v3(5, 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 adapted::point to vector + ns::point basep = {5, 3}; + adapted::point p(basep); + vector<int, long> v(p); + v = p; + } + + { + // conversion from adapted::point to list + ns::point basep = {5, 3}; + adapted::point p(basep); + list<int, long> l(p); + l = p; + } + + { + // assoc stuff + BOOST_MPL_ASSERT((boost::fusion::result_of::has_key<adapted::point, ns::x_member>)); + BOOST_MPL_ASSERT((boost::fusion::result_of::has_key<adapted::point, ns::y_member>)); + BOOST_MPL_ASSERT((boost::mpl::not_<boost::fusion::result_of::has_key<adapted::point, ns::z_member> >)); + + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_at_key<adapted::point, ns::x_member>::type, int>)); + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_at_key<adapted::point, ns::y_member>::type, int>)); + + ns::point basep = {5, 3}; + adapted::point p(basep); + + BOOST_TEST(at_key<ns::x_member>(p) == 5); + BOOST_TEST(at_key<ns::y_member>(p) == 3); + } + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/adapt_assoc_tpl_adt.cpp b/libs/fusion/test/sequence/adapt_assoc_tpl_adt.cpp new file mode 100644 index 000000000..15e2124cb --- /dev/null +++ b/libs/fusion/test/sequence/adapt_assoc_tpl_adt.cpp @@ -0,0 +1,139 @@ +/*============================================================================= + Copyright (c) 2010 Christopher Schmidt + + 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/sequence.hpp> +#include <boost/fusion/support.hpp> +#include <boost/fusion/container/list.hpp> +#include <boost/fusion/container/vector.hpp> +#include <boost/fusion/container/generation/make_vector.hpp> +#include <boost/fusion/adapted/adt/adapt_assoc_adt.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/mpl/not.hpp> +#include <boost/mpl/front.hpp> +#include <boost/mpl/is_sequence.hpp> +#include <boost/type_traits/is_same.hpp> +#include <boost/static_assert.hpp> +#include <iostream> +#include <string> + +namespace ns +{ + struct x_member; + struct y_member; + struct z_member; + + template<typename X, typename Y> + class point + { + public: + + point() : x(0), y(0) {} + point(X in_x, Y in_y) : x(in_x), y(in_y) {} + + X get_x() const { return x; } + Y get_y() const { return y; } + void set_x(X x_) { x = x_; } + void set_y(Y y_) { y = y_; } + + private: + + X x; + Y y; + }; +} + +BOOST_FUSION_ADAPT_ASSOC_TPL_ADT( + (X)(Y), + (ns::point)(X)(Y), + (X, X, obj.get_x(), obj.set_x(val), ns::x_member) + (Y, Y, obj.get_y(), obj.set_y(val), ns::y_member) +) + +int +main() +{ + using namespace boost::fusion; + + typedef ns::point<int,int> point; + + std::cout << tuple_open('['); + std::cout << tuple_close(']'); + std::cout << tuple_delimiter(", "); + + { + BOOST_MPL_ASSERT_NOT((traits::is_view<point>)); + point p(123, 456); + + 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, 456)); + + at_c<0>(p) = 6; + at_c<1>(p) = 9; + BOOST_TEST(p == make_vector(6, 9)); + + BOOST_STATIC_ASSERT(boost::fusion::result_of::size<point>::value == 2); + BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<point>::value); + + BOOST_TEST(front(p) == 6); + BOOST_TEST(back(p) == 9); + } + + { + boost::fusion::vector<int, float> v1(4, 2); + point v2(5, 3); + boost::fusion::vector<long, double> v3(5, 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 point to vector + point p(5, 3); + boost::fusion::vector<int, long> v(p); + v = p; + } + + { + // conversion from point to list + point p(5, 3); + boost::fusion::list<int, long> l(p); + l = p; + } + + { + BOOST_MPL_ASSERT((boost::mpl::is_sequence<point>)); + BOOST_MPL_ASSERT((boost::is_same< + boost::fusion::result_of::value_at_c<point,0>::type + , boost::mpl::front<point>::type>)); + } + + { + // assoc stuff + BOOST_MPL_ASSERT((boost::fusion::result_of::has_key<point, ns::x_member>)); + BOOST_MPL_ASSERT((boost::fusion::result_of::has_key<point, ns::y_member>)); + BOOST_MPL_ASSERT((boost::mpl::not_<boost::fusion::result_of::has_key<point, ns::z_member> >)); + + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_at_key<point, ns::x_member>::type, int>)); + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_at_key<point, ns::y_member>::type, int>)); + + point p(5, 3); + + BOOST_TEST(at_key<ns::x_member>(p) == 5); + BOOST_TEST(at_key<ns::y_member>(p) == 3); + } + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/adapt_assoc_tpl_struct.cpp b/libs/fusion/test/sequence/adapt_assoc_tpl_struct.cpp new file mode 100644 index 000000000..a327f9e87 --- /dev/null +++ b/libs/fusion/test/sequence/adapt_assoc_tpl_struct.cpp @@ -0,0 +1,133 @@ +/*============================================================================= + Copyright (c) 2010 Christopher Schmidt + + 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/adapted/struct/adapt_assoc_struct.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/intrinsic/has_key.hpp> +#include <boost/fusion/sequence/intrinsic/at_key.hpp> +#include <boost/fusion/sequence/intrinsic/value_at_key.hpp> +#include <boost/fusion/sequence/io/out.hpp> +#include <boost/fusion/container/vector/vector.hpp> +#include <boost/fusion/container/list/list.hpp> +#include <boost/fusion/container/generation/make_vector.hpp> +#include <boost/fusion/container/vector/convert.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 <boost/mpl/not.hpp> +#include <boost/type_traits/is_same.hpp> +#include <boost/static_assert.hpp> +#include <iostream> +#include <string> + +namespace ns +{ + struct x_member; + struct y_member; + struct z_member; + + template<typename X, typename Y> + struct point + { + X x; + Y y; + }; +} + +BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT( + (X)(Y), + (ns::point)(X)(Y), + (int, x, ns::x_member) + (int, y, ns::y_member) +) + +int +main() +{ + using namespace boost::fusion; + + typedef ns::point<int,int> point; + + std::cout << tuple_open('['); + std::cout << tuple_close(']'); + std::cout << tuple_delimiter(", "); + + { + BOOST_MPL_ASSERT_NOT((traits::is_view<point>)); + point p = {123, 456}; + + 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, 456)); + + at_c<0>(p) = 6; + at_c<1>(p) = 9; + BOOST_TEST(p == make_vector(6, 9)); + + BOOST_STATIC_ASSERT(boost::fusion::result_of::size<point>::value == 2); + BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<point>::value); + + BOOST_TEST(front(p) == 6); + BOOST_TEST(back(p) == 9); + } + + { + vector<int, float> v1(4, 2); + point v2 = {5, 3}; + vector<long, double> v3(5, 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 point to vector + point p = {5, 3}; + vector<int, long> v(p); + v = p; + } + + { + // conversion from point to list + point p = {5, 3}; + list<int, long> l(p); + l = p; + } + + { + // assoc stuff + BOOST_MPL_ASSERT((boost::fusion::result_of::has_key<point, ns::x_member>)); + BOOST_MPL_ASSERT((boost::fusion::result_of::has_key<point, ns::y_member>)); + BOOST_MPL_ASSERT((boost::mpl::not_<boost::fusion::result_of::has_key<point, ns::z_member> >)); + + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_at_key<point, ns::x_member>::type, int>)); + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_at_key<point, ns::y_member>::type, int>)); + + point p = {5, 3}; + + BOOST_TEST(at_key<ns::x_member>(p) == 5); + BOOST_TEST(at_key<ns::y_member>(p) == 3); + } + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/adapt_struct.cpp b/libs/fusion/test/sequence/adapt_struct.cpp new file mode 100644 index 000000000..68240463c --- /dev/null +++ b/libs/fusion/test/sequence/adapt_struct.cpp @@ -0,0 +1,164 @@ +/*============================================================================= + Copyright (c) 2001-2007 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/adapted/struct/adapt_struct.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/intrinsic/value_at.hpp> +#include <boost/fusion/sequence/io/out.hpp> +#include <boost/fusion/container/vector/vector.hpp> +#include <boost/fusion/container/list/list.hpp> +#include <boost/fusion/container/generation/make_vector.hpp> +#include <boost/fusion/container/vector/convert.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/mpl.hpp> +#include <boost/fusion/support/is_view.hpp> +#include <boost/mpl/front.hpp> +#include <boost/mpl/is_sequence.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/static_assert.hpp> +#include <iostream> +#include <string> + +namespace ns +{ + struct point + { + int x; + int y; + }; + +#if !BOOST_WORKAROUND(__GNUC__,<4) + struct point_with_private_attributes + { + friend struct boost::fusion::extension::access; + + private: + int x; + int y; + + public: + point_with_private_attributes(int x, int y):x(x),y(y) + {} + }; +#endif +} + +BOOST_FUSION_ADAPT_STRUCT( + ns::point, + (int, x) + (int, y) +) + +#if !BOOST_WORKAROUND(__GNUC__,<4) +BOOST_FUSION_ADAPT_STRUCT( + ns::point_with_private_attributes, + (int, x) + (int, y) +) +#endif + +struct s { int m; }; +BOOST_FUSION_ADAPT_STRUCT(s, (int, m)) + +int +main() +{ + using namespace boost::fusion; + using namespace boost; + + std::cout << tuple_open('['); + std::cout << tuple_close(']'); + std::cout << tuple_delimiter(", "); + + { + BOOST_MPL_ASSERT_NOT((traits::is_view<ns::point>)); + ns::point p = {123, 456}; + + 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, 456)); + + at_c<0>(p) = 6; + at_c<1>(p) = 9; + BOOST_TEST(p == make_vector(6, 9)); + + BOOST_STATIC_ASSERT(boost::fusion::result_of::size<ns::point>::value == 2); + BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<ns::point>::value); + + BOOST_TEST(front(p) == 6); + BOOST_TEST(back(p) == 9); + } + + { + fusion::vector<int, float> v1(4, 2); + ns::point v2 = {5, 3}; + fusion::vector<long, double> v3(5, 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 ns::point to vector + ns::point p = {5, 3}; + fusion::vector<int, long> v(p); + v = p; + } + + { + // conversion from ns::point to list + ns::point p = {5, 3}; + fusion::list<int, long> l(p); + l = p; + } + + { // begin/end + using namespace boost::fusion; + using boost::is_same; + + typedef boost::fusion::result_of::begin<s>::type b; + typedef boost::fusion::result_of::end<s>::type e; + // this fails + BOOST_MPL_ASSERT((is_same<boost::fusion::result_of::next<b>::type, e>)); + } + + { + BOOST_MPL_ASSERT((mpl::is_sequence<ns::point>)); + BOOST_MPL_ASSERT((boost::is_same< + boost::fusion::result_of::value_at_c<ns::point,0>::type + , mpl::front<ns::point>::type>)); + } + +#if !BOOST_WORKAROUND(__GNUC__,<4) + { + ns::point_with_private_attributes p(123, 456); + + 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, 456)); + } +#endif + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/adapt_struct_named.cpp b/libs/fusion/test/sequence/adapt_struct_named.cpp new file mode 100644 index 000000000..ef859655b --- /dev/null +++ b/libs/fusion/test/sequence/adapt_struct_named.cpp @@ -0,0 +1,137 @@ +/*============================================================================= + Copyright (c) 2001-2007 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/adapted/struct/adapt_struct_named.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/intrinsic/value_at.hpp> +#include <boost/fusion/sequence/io/out.hpp> +#include <boost/fusion/container/vector/vector.hpp> +#include <boost/fusion/container/list/list.hpp> +#include <boost/fusion/container/generation/make_vector.hpp> +#include <boost/fusion/container/vector/convert.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/mpl.hpp> +#include <boost/fusion/support/is_view.hpp> +#include <boost/mpl/front.hpp> +#include <boost/mpl/is_sequence.hpp> +#include <boost/mpl/assert.hpp> +#include <iostream> +#include <string> + +namespace ns +{ + struct point + { + int x; + int y; + }; +} + +// this creates a fusion view: boost::fusion::adapted::point +BOOST_FUSION_ADAPT_STRUCT_NAMED( + ns::point, point, + (int, x) + (int, y) +) + +// this creates a fusion view: ns1::s1 +struct s { int m; }; +BOOST_FUSION_ADAPT_STRUCT_NAMED_NS(s, (ns1), s1, (int, m)) + +int +main() +{ + using namespace boost::fusion; + using namespace boost; + + std::cout << tuple_open('['); + std::cout << tuple_close(']'); + std::cout << tuple_delimiter(", "); + + { + BOOST_MPL_ASSERT((traits::is_view<adapted::point>)); + ns::point basep = {123, 456}; + adapted::point p(basep); + + 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, 456)); + + at_c<0>(p) = 6; + at_c<1>(p) = 9; + BOOST_TEST(p == make_vector(6, 9)); + + BOOST_STATIC_ASSERT(boost::fusion::result_of::size<adapted::point>::value == 2); + BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<adapted::point>::value); + + BOOST_TEST(front(p) == 6); + BOOST_TEST(back(p) == 9); + } + + { + fusion::vector<int, float> v1(4, 2); + ns::point p = {5, 3}; + adapted::point v2(p); + + fusion::vector<long, double> v3(5, 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 adapted::point to vector + ns::point basep = {5, 3}; + adapted::point p(basep); + fusion::vector<int, long> v(p); + v = p; + } + + { + // conversion from adapted::point to list + ns::point basep = {5, 3}; + adapted::point p(basep); + fusion::list<int, long> l(p); + l = p; + } + + { // begin/end + using namespace boost::fusion; + using boost::is_same; + + typedef boost::fusion::result_of::begin<ns1::s1>::type b; + typedef boost::fusion::result_of::end<ns1::s1>::type e; + // this fails + BOOST_MPL_ASSERT((is_same<boost::fusion::result_of::next<b>::type, e>)); + } + + + { + BOOST_MPL_ASSERT((mpl::is_sequence<adapted::point>)); + BOOST_MPL_ASSERT((boost::is_same< + boost::fusion::result_of::value_at_c<adapted::point,0>::type + , mpl::front<adapted::point>::type>)); + } + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/adapt_tpl_adt.cpp b/libs/fusion/test/sequence/adapt_tpl_adt.cpp new file mode 100644 index 000000000..aeb0f7215 --- /dev/null +++ b/libs/fusion/test/sequence/adapt_tpl_adt.cpp @@ -0,0 +1,147 @@ +/*============================================================================= + Copyright (c) 2010 Christopher Schmidt + + 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/adapted/adt/adapt_adt.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/intrinsic/value_at.hpp> +#include <boost/fusion/sequence/io/out.hpp> +#include <boost/fusion/container/vector/vector.hpp> +#include <boost/fusion/container/list/list.hpp> +#include <boost/fusion/container/generation/make_vector.hpp> +#include <boost/fusion/container/vector/convert.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/mpl.hpp> +#include <boost/fusion/support/is_view.hpp> +#include <boost/mpl/front.hpp> +#include <boost/mpl/is_sequence.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/static_assert.hpp> +#include <iostream> +#include <string> + +namespace ns +{ + template<typename X, typename Y> + class point + { + public: + + point() : x(0), y(0) {} + point(X x_, Y y_) : x(x_), y(y_) {} + + X get_x() const { return x; } + Y get_y() const { return y; } + void set_x(X x_) { x = x_; } + void set_y(Y y_) { y = y_; } + + private: + + X x; + Y y; + }; +} + +BOOST_FUSION_ADAPT_TPL_ADT( + (X)(Y), + (ns::point)(X)(Y), + (X, X, obj.get_x(), obj.set_x(val)) + (Y, Y, obj.get_y(), obj.set_y(val)) +) + +int +main() +{ + using namespace boost::fusion; + + typedef ns::point<int, int> point; + typedef ns::point<std::string, std::string> name; + + std::cout << tuple_open('['); + std::cout << tuple_close(']'); + std::cout << tuple_delimiter(", "); + + { + BOOST_MPL_ASSERT_NOT((traits::is_view<point>)); + point p(123, 456); + + 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, 456)); + + at_c<0>(p) = 6; + at_c<1>(p) = 9; + BOOST_TEST(p == make_vector(6, 9)); + + BOOST_STATIC_ASSERT(boost::fusion::result_of::size<point>::value == 2); + BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<point>::value); + + BOOST_TEST(front(p) == 6); + BOOST_TEST(back(p) == 9); + } + + { + boost::fusion::vector<int, float> v1(4, 2); + point v2(5, 3); + boost::fusion::vector<long, double> v3(5, 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); + } + + { + boost::fusion::vector<std::string, std::string> v1("Lincoln", "Abraham"); + name v2("Roosevelt", "Franklin"); + name v3("Roosevelt", "Theodore"); + 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 point to vector + point p(5, 3); + boost::fusion::vector<int, long> v(p); + v = p; + } + + { + // conversion from point to list + point p(5, 3); + boost::fusion::list<int, long> l(p); + l = p; + } + + { + BOOST_MPL_ASSERT((boost::mpl::is_sequence<point>)); + BOOST_MPL_ASSERT((boost::is_same< + boost::fusion::result_of::value_at_c<point,0>::type + , boost::mpl::front<point>::type>)); + } + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/adapt_tpl_struct.cpp b/libs/fusion/test/sequence/adapt_tpl_struct.cpp new file mode 100644 index 000000000..352cf9957 --- /dev/null +++ b/libs/fusion/test/sequence/adapt_tpl_struct.cpp @@ -0,0 +1,122 @@ +/*============================================================================= + Copyright (c) 2010 Christopher Schmidt + + 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/adapted/struct/adapt_struct.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/container/vector/vector.hpp> +#include <boost/fusion/container/list/list.hpp> +#include <boost/fusion/container/generation/make_vector.hpp> +#include <boost/fusion/container/vector/convert.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 <boost/static_assert.hpp> +#include <iostream> +#include <string> + +namespace ns +{ + template<typename X, typename Y> + struct point + { + X x; + Y y; + }; +} + +BOOST_FUSION_ADAPT_TPL_STRUCT( + (X)(Y), + (ns::point)(X)(Y), + (X, x) + (Y, y) +) + +template<typename M> +struct s { M m; }; +BOOST_FUSION_ADAPT_TPL_STRUCT((M), (s)(M), (M, m)) + +int +main() +{ + using namespace boost::fusion; + + typedef ns::point<int, int> point; + + std::cout << tuple_open('['); + std::cout << tuple_close(']'); + std::cout << tuple_delimiter(", "); + + { + BOOST_MPL_ASSERT_NOT((traits::is_view<point>)); + point p = {123, 456}; + + 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, 456)); + + at_c<0>(p) = 6; + at_c<1>(p) = 9; + BOOST_TEST(p == make_vector(6, 9)); + + BOOST_STATIC_ASSERT(boost::fusion::result_of::size<point>::value == 2); + BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<point>::value); + + BOOST_TEST(front(p) == 6); + BOOST_TEST(back(p) == 9); + } + + { + vector<int, float> v1(4, 2); + point v2 = {5, 3}; + vector<long, double> v3(5, 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 point to vector + point p = {5, 3}; + vector<int, long> v(p); + v = p; + } + + { + // conversion from point to list + point p = {5, 3}; + list<int, long> l(p); + l = p; + } + + { // begin/end + using namespace boost::fusion; + + typedef boost::fusion::result_of::begin<s<int> >::type b; + typedef boost::fusion::result_of::end<s<int> >::type e; + // this fails + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::next<b>::type, e>)); + } + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/adt_attribute_proxy.cpp b/libs/fusion/test/sequence/adt_attribute_proxy.cpp new file mode 100644 index 000000000..d5a947afb --- /dev/null +++ b/libs/fusion/test/sequence/adt_attribute_proxy.cpp @@ -0,0 +1,188 @@ +/*============================================================================= + Copyright (c) 2010 Christopher Schmidt + + 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/adapted/adt/adapt_assoc_adt.hpp> +#include <boost/fusion/sequence.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/type_traits/is_same.hpp> +#include <iostream> +#include <string> + +namespace fusion=boost::fusion; + +template<typename Name, typename Age> +struct employee +{ +private: + Name name; + Age age; + +public: + template<typename OtherName> + void + set_name(OtherName const& n) + { + name=n; + } + + template<typename OtherAge> + void + set_age(OtherAge const& a) + { + age=a; + } + + Name& get_name() + { + return name; + } + + Name const& get_name()const + { + return name; + } + + Age& get_age() + { + return age; + } + + Age const& get_age()const + { + return age; + } +}; + +namespace keys +{ + struct name; + struct age; +} + +BOOST_FUSION_ADAPT_ASSOC_TPL_ADT( + (Name)(Age), + (employee) (Name)(Age), + (Name&, Name const&, obj.get_name(), obj.template set_name<Val>(val), keys::name) + (Age&, Age const&, obj.get_age(), obj.template set_age<Val>(val), keys::age)) + +int main() +{ + typedef employee<std::string, int> et; + typedef et const etc; + et e; + etc& ec=e; + + fusion::at_key<keys::name>(e)="marshall mathers"; + fusion::at_key<keys::age>(e)=37; + + BOOST_MPL_ASSERT(( + boost::is_same< + boost::fusion::result_of::value_at_key<et, keys::name>::type, + std::string + >)); + BOOST_MPL_ASSERT(( + boost::is_same< + boost::fusion::result_of::value_at_key<et, keys::name>::type, + boost::fusion::result_of::value_at_c<et, 0>::type + >)); + BOOST_MPL_ASSERT(( + boost::is_same< + boost::fusion::result_of::value_at_key<et, keys::age>::type, + int + >)); + BOOST_MPL_ASSERT(( + boost::is_same< + boost::fusion::result_of::value_at_key<et, keys::age>::type, + boost::fusion::result_of::value_at_c<et, 1>::type + >)); + + BOOST_MPL_ASSERT(( + boost::is_same< + boost::fusion::result_of::at_key<et, keys::name>::type, + fusion::extension::adt_attribute_proxy<et, 0, false> + >)); + BOOST_MPL_ASSERT(( + boost::is_same< + boost::fusion::result_of::at_key<et, keys::age>::type, + fusion::extension::adt_attribute_proxy<et, 1, false> + >)); + BOOST_MPL_ASSERT(( + boost::is_same< + boost::fusion::result_of::at_key<et, keys::name>::type, + boost::fusion::result_of::front<et>::type + >)); + BOOST_MPL_ASSERT(( + boost::is_same< + boost::fusion::result_of::at_key<et, keys::age>::type, + boost::fusion::result_of::back<et>::type + >)); + + BOOST_MPL_ASSERT(( + boost::is_same< + boost::fusion::result_of::at_key<etc, keys::name>::type, + fusion::extension::adt_attribute_proxy<et, 0, true> + >)); + BOOST_MPL_ASSERT(( + boost::is_same< + boost::fusion::result_of::at_key<etc, keys::age>::type, + fusion::extension::adt_attribute_proxy<et, 1, true> + >)); + BOOST_MPL_ASSERT(( + boost::is_same< + boost::fusion::result_of::at_key<etc, keys::name>::type, + boost::fusion::result_of::front<etc>::type + >)); + BOOST_MPL_ASSERT(( + boost::is_same< + boost::fusion::result_of::at_key<etc, keys::age>::type, + boost::fusion::result_of::back<etc>::type + >)); + + BOOST_MPL_ASSERT(( + boost::is_same< + fusion::extension::adt_attribute_proxy<et, 0, false>::type, + std::string& + >)); + BOOST_MPL_ASSERT(( + boost::is_same< + fusion::extension::adt_attribute_proxy<et, 0, true>::type, + std::string const& + >)); + BOOST_MPL_ASSERT(( + boost::is_same< + fusion::extension::adt_attribute_proxy<et, 1, false>::type, + int& + >)); + BOOST_MPL_ASSERT(( + boost::is_same< + fusion::extension::adt_attribute_proxy<et, 1, true>::type, + int const& + >)); + + { + std::string& name=fusion::at_key<keys::name>(e); + int& age=fusion::at_key<keys::age>(e); + BOOST_TEST(name=="marshall mathers"); + BOOST_TEST(age==37); + BOOST_TEST(fusion::at_key<keys::name>(e).get()=="marshall mathers"); + BOOST_TEST(fusion::at_key<keys::age>(e).get()==37); + BOOST_TEST(fusion::front(e).get()=="marshall mathers"); + BOOST_TEST(fusion::back(e).get()==37); + } + + { + std::string const& name=fusion::at_key<keys::name>(ec); + int const& age=fusion::at_key<keys::age>(ec); + BOOST_TEST(name=="marshall mathers"); + BOOST_TEST(age==37); + BOOST_TEST(fusion::at_key<keys::name>(ec).get()=="marshall mathers"); + BOOST_TEST(fusion::at_key<keys::age>(ec).get()==37); + BOOST_TEST(fusion::front(ec).get()=="marshall mathers"); + BOOST_TEST(fusion::back(ec).get()==37); + } +} diff --git a/libs/fusion/test/sequence/array.cpp b/libs/fusion/test/sequence/array.cpp new file mode 100644 index 000000000..15b4ed89e --- /dev/null +++ b/libs/fusion/test/sequence/array.cpp @@ -0,0 +1,39 @@ +/*============================================================================= + Copyright (c) 2010 Christopher Schmidt + + 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/adapted/array.hpp> +#include <boost/fusion/sequence/intrinsic.hpp> +#include <boost/fusion/iterator.hpp> +#include <boost/fusion/support/is_sequence.hpp> +#include <boost/fusion/support/is_view.hpp> + +#include <boost/mpl/assert.hpp> + +int main() +{ + using namespace boost::fusion; + typedef int array_type[3]; + + 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(); +} + diff --git a/libs/fusion/test/sequence/as_list.cpp b/libs/fusion/test/sequence/as_list.cpp new file mode 100644 index 000000000..8ee8bf128 --- /dev/null +++ b/libs/fusion/test/sequence/as_list.cpp @@ -0,0 +1,53 @@ +/*============================================================================= + Copyright (c) 2001-2011 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/generation/make_vector.hpp> +#include <boost/fusion/container/generation/make_list.hpp> +#include <boost/fusion/container/list/convert.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(); +} + diff --git a/libs/fusion/test/sequence/as_map.cpp b/libs/fusion/test/sequence/as_map.cpp new file mode 100644 index 000000000..d2a89cc6c --- /dev/null +++ b/libs/fusion/test/sequence/as_map.cpp @@ -0,0 +1,61 @@ +/*============================================================================= + Copyright (c) 2001-2011 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/generation/make_vector.hpp> +#include <boost/fusion/container/generation/make_list.hpp> +#include <boost/fusion/container/map/convert.hpp> +#include <boost/fusion/container/vector/convert.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; + boost::fusion::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(); +} + diff --git a/libs/fusion/test/sequence/as_set.cpp b/libs/fusion/test/sequence/as_set.cpp new file mode 100644 index 000000000..97dd89e87 --- /dev/null +++ b/libs/fusion/test/sequence/as_set.cpp @@ -0,0 +1,64 @@ +/*============================================================================= + Copyright (c) 2001-2011 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/generation/make_vector.hpp> +#include <boost/fusion/container/generation/make_list.hpp> +#include <boost/fusion/container/set/convert.hpp> +#include <boost/fusion/container/list/convert.hpp> +#include <boost/fusion/container/vector/convert.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)); + } + + { + boost::fusion::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(); +} + diff --git a/libs/fusion/test/sequence/as_vector.cpp b/libs/fusion/test/sequence/as_vector.cpp new file mode 100644 index 000000000..af1aaffb8 --- /dev/null +++ b/libs/fusion/test/sequence/as_vector.cpp @@ -0,0 +1,54 @@ +/*============================================================================= + Copyright (c) 2001-2011 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/generation/make_vector.hpp> +#include <boost/fusion/container/generation/make_list.hpp> +#include <boost/fusion/container/vector/convert.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(); +} + diff --git a/libs/fusion/test/sequence/back_extended_deque.cpp b/libs/fusion/test/sequence/back_extended_deque.cpp new file mode 100644 index 000000000..edae9276c --- /dev/null +++ b/libs/fusion/test/sequence/back_extended_deque.cpp @@ -0,0 +1,75 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/container/deque/deque.hpp> +#include <boost/fusion/container/deque/back_extended_deque.hpp> +#include <boost/fusion/sequence/comparison.hpp> +#include <boost/fusion/container/generation/make_vector.hpp> +#include <boost/fusion/mpl.hpp> + +#include <boost/fusion/sequence/intrinsic.hpp> +#include <boost/fusion/iterator.hpp> + +#include <boost/mpl/assert.hpp> +#include <boost/type_traits/is_same.hpp> + +int main() +{ + using namespace boost::fusion; + { + typedef deque<int, char> initial_deque_type; + initial_deque_type initial_deque(1, 'a'); + typedef back_extended_deque<initial_deque_type, long> extended_type; + extended_type extended(initial_deque, 101L); + + BOOST_TEST(size(extended) == 3); + BOOST_TEST(extended == make_vector(1, 'a', 101L)); + BOOST_TEST(*begin(extended) == 1); + BOOST_TEST(*next(begin(extended)) == 'a'); + BOOST_TEST(*prior(end(extended)) == 101L); + BOOST_TEST(distance(begin(extended), end(extended)) == 3); + BOOST_TEST(*advance_c<2>(begin(extended)) == 101L); + } + { + namespace mpl = boost::mpl; + typedef deque<int, char> initial_deque_type; + typedef back_extended_deque<initial_deque_type, long> extended_type; + + BOOST_MPL_ASSERT((boost::is_same<mpl::at_c<extended_type, 0>::type, int>)); + BOOST_MPL_ASSERT((boost::is_same<mpl::at_c<extended_type, 1>::type, char>)); + BOOST_MPL_ASSERT((boost::is_same<mpl::at_c<extended_type, 2>::type, long>)); + BOOST_MPL_ASSERT((boost::is_same<mpl::deref<mpl::begin<extended_type>::type>::type, int>)); + BOOST_MPL_ASSERT((mpl::equal_to<mpl::size<extended_type>::type, mpl::int_<3> >)); + } + { + char ch('a'); + long l(101L); + int i(1); + typedef deque<int&, char&> initial_deque_type; + initial_deque_type initial_deque(i, ch); + typedef back_extended_deque<initial_deque_type, long&> extended_type; + extended_type extended(initial_deque, l); + BOOST_TEST(extended == make_vector(1, 'a', 101L)); + + char ch2('b'); + long l2(202L); + int i2(2); + extended_type extended2(initial_deque_type(i2, ch2), l2); + + extended = extended2; + + BOOST_TEST(extended == make_vector(2, 'b', 202L)); + + BOOST_TEST(i == i2); + BOOST_TEST(ch == ch2); + BOOST_TEST(l == l2); + } + return boost::report_errors(); +} diff --git a/libs/fusion/test/sequence/boost_array.cpp b/libs/fusion/test/sequence/boost_array.cpp new file mode 100644 index 000000000..a1bb65421 --- /dev/null +++ b/libs/fusion/test/sequence/boost_array.cpp @@ -0,0 +1,42 @@ +/*============================================================================= + Copyright (c) 2001-2011 Joel de Guzman + Copyright (c) 2005-2006 Dan Marsden + Copyright (c) 2010 Christopher Schmidt + + 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/adapted/boost_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(); +} diff --git a/libs/fusion/test/sequence/boost_tuple.cpp b/libs/fusion/test/sequence/boost_tuple.cpp new file mode 100644 index 000000000..c16c08940 --- /dev/null +++ b/libs/fusion/test/sequence/boost_tuple.cpp @@ -0,0 +1,109 @@ +/*============================================================================= + Copyright (c) 2001-2011 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/adapted/boost_tuple.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/iterator/distance.hpp> +#include <boost/fusion/container/vector/vector.hpp> +#include <boost/fusion/container/list/list.hpp> +#include <boost/fusion/container/generation/make_vector.hpp> +#include <boost/fusion/container/vector/convert.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/mpl.hpp> +#include <boost/fusion/support/is_view.hpp> +#include <boost/tuple/tuple.hpp> +#include <boost/mpl/is_sequence.hpp> +#include <boost/mpl/front.hpp> +#include <boost/mpl/assert.hpp> +#include <iostream> +#include <string> + +int +main() +{ + using namespace boost::fusion; + using namespace boost; + + std::cout << tuple_open('['); + std::cout << tuple_close(']'); + std::cout << tuple_delimiter(", "); + + { + typedef boost::tuple<int, std::string> tuple_type; + BOOST_MPL_ASSERT_NOT((traits::is_view<tuple_type>)); + tuple_type t(123, "Hola!!!"); + + std::cout << at_c<0>(t) << std::endl; + std::cout << at_c<1>(t) << std::endl; + std::cout << t << std::endl; + BOOST_TEST(t == make_vector(123, "Hola!!!")); + + at_c<0>(t) = 6; + at_c<1>(t) = "mama mia"; + BOOST_TEST(t == make_vector(6, "mama mia")); + + BOOST_STATIC_ASSERT(boost::fusion::result_of::size<tuple_type>::value == 2); + BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<tuple_type>::value); + + BOOST_TEST(front(t) == 6); + } + + { + fusion::vector<int, float> v1(4, 3.3f); + boost::tuple<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 boost tuple to vector + fusion::vector<int, std::string> v(tuples::make_tuple(123, "Hola!!!")); + v = tuples::make_tuple(123, "Hola!!!"); + } + + { + // conversion from boost tuple to list + fusion::list<int, std::string> l(tuples::make_tuple(123, "Hola!!!")); + l = tuples::make_tuple(123, "Hola!!!"); + } + + { + // test from Ticket #1601, submitted by Shunsuke Sogame + // expanded by Stjepan Rajko + boost::tuple<int, char> t(3, 'a'); + + BOOST_TEST(0u == fusion::distance(fusion::begin(t), fusion::begin(t))); + BOOST_TEST(1u == fusion::distance(fusion::begin(t), fusion::next(fusion::begin(t)))); + BOOST_TEST(2u == fusion::distance(fusion::begin(t), fusion::end(t))); + } + + { + typedef boost::tuple<int, std::string> tuple_type; + BOOST_MPL_ASSERT((mpl::is_sequence<tuple_type>)); + BOOST_MPL_ASSERT((boost::is_same<int, mpl::front<tuple_type>::type>)); + } + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/comparison.hpp b/libs/fusion/test/sequence/comparison.hpp new file mode 100644 index 000000000..2dfe65503 --- /dev/null +++ b/libs/fusion/test/sequence/comparison.hpp @@ -0,0 +1,57 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/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 +} + + + diff --git a/libs/fusion/test/sequence/cons.cpp b/libs/fusion/test/sequence/cons.cpp new file mode 100644 index 000000000..cb74af619 --- /dev/null +++ b/libs/fusion/test/sequence/cons.cpp @@ -0,0 +1,88 @@ +/*============================================================================= + Copyright (c) 2001-2011 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 <string> +#include <boost/detail/lightweight_test.hpp> +#include <boost/fusion/container/list/cons.hpp> +#include <boost/fusion/container/generation/make_cons.hpp> +#include <boost/fusion/container/generation/cons_tie.hpp> +#include <boost/fusion/container/vector/vector.hpp> +#include <boost/fusion/container/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; + namespace fusion = boost::fusion; + + 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((*fusion::next(begin(ns)) == hello)); + + *begin(ns) += 1; + *fusion::next(begin(ns)) += ' '; + + BOOST_TEST((*begin(ns) == 2)); + BOOST_TEST((*fusion::next(begin(ns)) == hello + ' ')); + + for_each(ns, boost::lambda::_1 += ' '); + + BOOST_TEST((*begin(ns) == 2 + ' ')); + BOOST_TEST((*fusion::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(); +} + diff --git a/libs/fusion/test/sequence/construction.hpp b/libs/fusion/test/sequence/construction.hpp new file mode 100644 index 000000000..57ba53013 --- /dev/null +++ b/libs/fusion/test/sequence/construction.hpp @@ -0,0 +1,119 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/sequence/intrinsic/at.hpp> +#include <boost/fusion/container/list/cons.hpp> + +#if !defined(FUSION_AT) +#define FUSION_AT at_c +#endif + +namespace test_detail +{ + // 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; + using namespace test_detail; + + nil empty; + + FUSION_SEQUENCE<> empty0; + +#ifndef NO_CONSTRUCT_FROM_NIL + FUSION_SEQUENCE<> empty1(empty); +#endif + + 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 +} diff --git a/libs/fusion/test/sequence/copy.hpp b/libs/fusion/test/sequence/copy.hpp new file mode 100644 index 000000000..cb9384abc --- /dev/null +++ b/libs/fusion/test/sequence/copy.hpp @@ -0,0 +1,98 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/sequence/intrinsic/at.hpp> +#include <boost/fusion/mpl.hpp> +#include <boost/preprocessor/cat.hpp> +#include <boost/mpl/insert_range.hpp> +#include <boost/mpl/vector.hpp> +#include <boost/mpl/begin.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/static_assert.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 test_detail +{ + // 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(); }; }; +} + +boost::fusion::FUSION_SEQUENCE<double, double, double, double> +foo(int i) +{ + return boost::fusion::FUSION_MAKE(i, i+1, i+2, i+3); +} + +void test_mpl() +{ + using namespace boost::fusion; + + typedef FUSION_SEQUENCE<int, char> seq; + + typedef + boost::mpl::insert_range< + boost::mpl::vector<> + , boost::mpl::end< boost::mpl::vector<> >::type + , seq + >::type + sequence; + + typedef boost::mpl::equal<sequence, boost::mpl::vector<int, char> > equal; + BOOST_STATIC_ASSERT(equal::value); +} + +void +test() +{ + using namespace boost::fusion; + using namespace test_detail; + + 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); + + // returning a tuple with conversion + foo(2); + + test_mpl(); +} diff --git a/libs/fusion/test/sequence/deduce_sequence.cpp b/libs/fusion/test/sequence/deduce_sequence.cpp new file mode 100644 index 000000000..ea6616627 --- /dev/null +++ b/libs/fusion/test/sequence/deduce_sequence.cpp @@ -0,0 +1,80 @@ +/*============================================================================= + Copyright (c) 2007 Tobias Schwinger + + Use modification and distribution are 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/support/deduce_sequence.hpp> +#include <boost/fusion/mpl.hpp> +#include <boost/detail/lightweight_test.hpp> + +#include <boost/mpl/equal.hpp> + +#include <boost/ref.hpp> + +using boost::is_same; +using boost::reference_wrapper; +using boost::fusion::traits::deduce; +using boost::fusion::traits::deduce_sequence; + +namespace fusion = boost::fusion; + +template <class Args> +struct test_seq_ctor +{ + typename deduce_sequence<Args>::type fsq_args; + + test_seq_ctor(Args const & args) + : fsq_args(args) + { } +}; + +#define TEST_SAME_TYPE(a,b) BOOST_TEST(( is_same< a, b >::value )) +#define TEST_SAME_ELEMENTS(a,b) BOOST_TEST(( boost::mpl::equal< a, b >::type::value )) + +typedef fusion::vector<int, int const, int &, int const &> args1; +typedef fusion::vector<int, int, int &, int> storable1; +template struct test_seq_ctor<args1>; + +typedef fusion::vector< reference_wrapper<int> &, reference_wrapper<int const> &, + reference_wrapper<int> const &, reference_wrapper<int const> const & > args2; +typedef fusion::vector<int &, int const &, int &, int const &> storable2; +template struct test_seq_ctor<args2>; + + +typedef fusion::vector<int *, int const *, int const * const, int const * &, int const * const &> args3; +typedef fusion::vector<int *, int const *, int const *, int const * &, int const * > storable3; +template struct test_seq_ctor<args3>; + +typedef fusion::vector<int(&)[2], int const(&)[2]> args4; +typedef args4 storable4; +template struct test_seq_ctor<args4>; + +int main() +{ + TEST_SAME_TYPE(deduce<int &>::type, int &); + TEST_SAME_TYPE(deduce<int volatile &>::type, int volatile &); + + TEST_SAME_TYPE(deduce<int>::type, int); + TEST_SAME_TYPE(deduce<int const &>::type, int); + TEST_SAME_TYPE(deduce<int const volatile &>::type, int); + + TEST_SAME_TYPE(deduce< reference_wrapper<int> & >::type, int &); + TEST_SAME_TYPE(deduce< reference_wrapper<int const> & >::type, int const &); + TEST_SAME_TYPE(deduce< reference_wrapper<int> const & >::type, int &); + TEST_SAME_TYPE(deduce< reference_wrapper<int const> const & >::type, int const &); + + TEST_SAME_TYPE(deduce< int(&)[2] >::type, int(&)[2]); + TEST_SAME_TYPE(deduce< int const (&)[2] >::type, int const (&)[2]); + TEST_SAME_TYPE(deduce< int volatile (&)[2] >::type, int volatile (&)[2]); + TEST_SAME_TYPE(deduce< int const volatile (&)[2] >::type, int const volatile (&)[2]); + + TEST_SAME_ELEMENTS(deduce_sequence<args1>::type,storable1); + TEST_SAME_ELEMENTS(deduce_sequence<args2>::type,storable2); + TEST_SAME_ELEMENTS(deduce_sequence<args3>::type,storable3); + TEST_SAME_ELEMENTS(deduce_sequence<args4>::type,storable4); + + return boost::report_errors(); +} diff --git a/libs/fusion/test/sequence/define_assoc_struct.cpp b/libs/fusion/test/sequence/define_assoc_struct.cpp new file mode 100644 index 000000000..ed8dfbe05 --- /dev/null +++ b/libs/fusion/test/sequence/define_assoc_struct.cpp @@ -0,0 +1,114 @@ +/*============================================================================= + Copyright (c) 2010 Christopher Schmidt + + 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/sequence.hpp> +#include <boost/fusion/container.hpp> +#include <boost/fusion/support.hpp> +#include <boost/fusion/adapted/struct/define_assoc_struct.hpp> +#include <boost/preprocessor/empty.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/static_assert.hpp> +#include <iostream> + +namespace ns +{ + struct x_member; + struct y_member; + struct z_member; +} + +BOOST_FUSION_DEFINE_ASSOC_STRUCT( + (ns), + point, + (int, x, ns::x_member) + (int, y, ns::y_member) +) + +int +main() +{ + using namespace boost::fusion; + + std::cout << tuple_open('['); + std::cout << tuple_close(']'); + std::cout << tuple_delimiter(", "); + + { + BOOST_MPL_ASSERT_NOT((traits::is_view<ns::point>)); + ns::point p(123, 456); + + 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, 456)); + + at_c<0>(p) = 6; + at_c<1>(p) = 9; + BOOST_TEST(p == make_vector(6, 9)); + + BOOST_STATIC_ASSERT(boost::fusion::result_of::size<ns::point>::value == 2); + BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<ns::point>::value); + + BOOST_TEST(front(p) == 6); + BOOST_TEST(back(p) == 9); + } + + { + vector<int, float> v1(4, 2); + ns::point v2(5, 3); + vector<long, double> v3(5, 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 ns::point to vector + ns::point p(5, 3); + vector<int, long> v(p); + v = p; + } + + { + // conversion from ns::point to list + ns::point p(5, 3); + list<int, long> l(p); + l = p; + } + + { + // assoc stuff + BOOST_MPL_ASSERT((boost::fusion::result_of::has_key<ns::point, ns::x_member>)); + BOOST_MPL_ASSERT((boost::fusion::result_of::has_key<ns::point, ns::y_member>)); + BOOST_MPL_ASSERT((boost::mpl::not_<boost::fusion::result_of::has_key<ns::point, ns::z_member> >)); + + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_at_key<ns::point, ns::x_member>::type, int>)); + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_at_key<ns::point, ns::y_member>::type, int>)); + + ns::point p(5, 3); + + BOOST_TEST(at_key<ns::x_member>(p) == 5); + BOOST_TEST(at_key<ns::y_member>(p) == 3); + } + + { + ns::point p = make_list(5,3); + BOOST_TEST(p == make_vector(5,3)); + + p = make_list(3,5); + BOOST_TEST(p == make_vector(3,5)); + } + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/define_assoc_tpl_struct.cpp b/libs/fusion/test/sequence/define_assoc_tpl_struct.cpp new file mode 100644 index 000000000..6d0b5bdbf --- /dev/null +++ b/libs/fusion/test/sequence/define_assoc_tpl_struct.cpp @@ -0,0 +1,118 @@ +/*============================================================================= + Copyright (c) 2010 Christopher Schmidt + + 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/sequence.hpp> +#include <boost/fusion/container.hpp> +#include <boost/fusion/support.hpp> +#include <boost/fusion/sequence/io/out.hpp> +#include <boost/fusion/adapted/struct/define_assoc_struct.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/static_assert.hpp> +#include <iostream> +#include <string> + +namespace ns +{ + struct x_member; + struct y_member; + struct z_member; +} + +BOOST_FUSION_DEFINE_ASSOC_TPL_STRUCT( + (X)(Y), + (ns), + point, + (int, x, ns::x_member) + (int, y, ns::y_member) +) + +int +main() +{ + using namespace boost::fusion; + + typedef ns::point<int,int> point; + + std::cout << tuple_open('['); + std::cout << tuple_close(']'); + std::cout << tuple_delimiter(", "); + + { + BOOST_MPL_ASSERT_NOT((traits::is_view<point>)); + point p(123, 456); + + 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, 456)); + + at_c<0>(p) = 6; + at_c<1>(p) = 9; + BOOST_TEST(p == make_vector(6, 9)); + + BOOST_STATIC_ASSERT(boost::fusion::result_of::size<point>::value == 2); + BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<point>::value); + + BOOST_TEST(front(p) == 6); + BOOST_TEST(back(p) == 9); + } + + { + vector<int, float> v1(4, 2); + point v2(5, 3); + vector<long, double> v3(5, 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 point to vector + point p(5, 3); + vector<int, long> v(p); + v = p; + } + + { + // conversion from point to list + point p(5, 3); + list<int, long> l(p); + l = p; + } + + { + // assoc stuff + BOOST_MPL_ASSERT((boost::fusion::result_of::has_key<point, ns::x_member>)); + BOOST_MPL_ASSERT((boost::fusion::result_of::has_key<point, ns::y_member>)); + BOOST_MPL_ASSERT((boost::mpl::not_<boost::fusion::result_of::has_key<point, ns::z_member> >)); + + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_at_key<point, ns::x_member>::type, int>)); + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_at_key<point, ns::y_member>::type, int>)); + + point p(5, 3); + + BOOST_TEST(at_key<ns::x_member>(p) == 5); + BOOST_TEST(at_key<ns::y_member>(p) == 3); + } + + { + point p = make_list(5,3); + BOOST_TEST(p == make_vector(5,3)); + + p = make_list(3,5); + BOOST_TEST(p == make_vector(3,5)); + } + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/define_struct.cpp b/libs/fusion/test/sequence/define_struct.cpp new file mode 100644 index 000000000..795fdf6e7 --- /dev/null +++ b/libs/fusion/test/sequence/define_struct.cpp @@ -0,0 +1,105 @@ +/*============================================================================= + Copyright (c) 2010 Christopher Schmidt + + 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/sequence.hpp> +#include <boost/fusion/container.hpp> +#include <boost/fusion/support.hpp> +#include <boost/fusion/sequence/io/out.hpp> +#include <boost/fusion/adapted/struct/define_struct.hpp> +#include <boost/preprocessor/empty.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/static_assert.hpp> +#include <iostream> +#include <string> + +BOOST_FUSION_DEFINE_STRUCT( + (ns), + point, + (int, x) + (int, y) +) + +BOOST_FUSION_DEFINE_STRUCT(BOOST_PP_EMPTY(), s, (int, m)) + +int +main() +{ + using namespace boost::fusion; + + std::cout << tuple_open('['); + std::cout << tuple_close(']'); + std::cout << tuple_delimiter(", "); + + { + BOOST_MPL_ASSERT_NOT((traits::is_view<ns::point>)); + ns::point p(123, 456); + + 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, 456)); + + at_c<0>(p) = 6; + at_c<1>(p) = 9; + BOOST_TEST(p == make_vector(6, 9)); + + BOOST_STATIC_ASSERT(boost::fusion::result_of::size<ns::point>::value == 2); + BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<ns::point>::value); + + BOOST_TEST(front(p) == 6); + BOOST_TEST(back(p) == 9); + } + + { + vector<int, float> v1(4, 2); + ns::point v2(5, 3); + vector<long, double> v3(5, 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 ns::point to vector + ns::point p(5, 3); + vector<int, long> v(p); + v = p; + } + + { + // conversion from ns::point to list + ns::point p(5, 3); + list<int, long> l(p); + l = p; + } + + { // begin/end + using namespace boost::fusion; + + typedef boost::fusion::result_of::begin<s>::type b; + typedef boost::fusion::result_of::end<s>::type e; + // this fails + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::next<b>::type, e>)); + } + + { + ns::point p = make_list(5,3); + BOOST_TEST(p == make_vector(5,3)); + + p = make_list(3,5); + BOOST_TEST(p == make_vector(3,5)); + } + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/define_tpl_struct.cpp b/libs/fusion/test/sequence/define_tpl_struct.cpp new file mode 100644 index 000000000..9896493cc --- /dev/null +++ b/libs/fusion/test/sequence/define_tpl_struct.cpp @@ -0,0 +1,109 @@ +/*============================================================================= + Copyright (c) 2010 Christopher Schmidt + + 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/sequence.hpp> +#include <boost/fusion/container.hpp> +#include <boost/fusion/support.hpp> +#include <boost/fusion/sequence/io/out.hpp> +#include <boost/fusion/adapted/struct/define_struct.hpp> +#include <boost/preprocessor/empty.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/static_assert.hpp> +#include <iostream> +#include <string> + +BOOST_FUSION_DEFINE_TPL_STRUCT( + (X)(Y), + (ns), + point, + (X, x) + (Y, y) +) + +BOOST_FUSION_DEFINE_TPL_STRUCT((M), BOOST_PP_EMPTY(), s, (M, m)) + +int +main() +{ + using namespace boost::fusion; + + typedef ns::point<int, int> point; + + std::cout << tuple_open('['); + std::cout << tuple_close(']'); + std::cout << tuple_delimiter(", "); + + { + BOOST_MPL_ASSERT_NOT((traits::is_view<point>)); + point p(123, 456); + + 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, 456)); + + at_c<0>(p) = 6; + at_c<1>(p) = 9; + BOOST_TEST(p == make_vector(6, 9)); + + BOOST_STATIC_ASSERT(boost::fusion::result_of::size<point>::value == 2); + BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<point>::value); + + BOOST_TEST(front(p) == 6); + BOOST_TEST(back(p) == 9); + } + + { + vector<int, float> v1(4, 2); + point v2(5, 3); + vector<long, double> v3(5, 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 point to vector + point p(5, 3); + vector<int, long> v(p); + v = p; + } + + { + // conversion from point to list + point p(5, 3); + list<int, long> l(p); + l = p; + } + + { // begin/end + using namespace boost::fusion; + + typedef boost::fusion::result_of::begin<s<int> >::type b; + typedef boost::fusion::result_of::end<s<int> >::type e; + // this fails + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::next<b>::type, e>)); + } + + + { + point p = make_list(5,3); + BOOST_TEST(p == make_vector(5,3)); + + p = make_list(3,5); + BOOST_TEST(p == make_vector(3,5)); + } + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/deque_comparison.cpp b/libs/fusion/test/sequence/deque_comparison.cpp new file mode 100644 index 000000000..9bbf4fd95 --- /dev/null +++ b/libs/fusion/test/sequence/deque_comparison.cpp @@ -0,0 +1,20 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/container/deque/deque.hpp> + +#define FUSION_SEQUENCE deque +#include "comparison.hpp" + +int +main() +{ + equality_test(); + ordering_test(); + return boost::report_errors(); +} diff --git a/libs/fusion/test/sequence/deque_construction.cpp b/libs/fusion/test/sequence/deque_construction.cpp new file mode 100644 index 000000000..4fc8c8830 --- /dev/null +++ b/libs/fusion/test/sequence/deque_construction.cpp @@ -0,0 +1,19 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/container/deque/deque.hpp> + +#define FUSION_SEQUENCE deque +#include "construction.hpp" + +int +main() +{ + test(); + return boost::report_errors(); +} diff --git a/libs/fusion/test/sequence/deque_copy.cpp b/libs/fusion/test/sequence/deque_copy.cpp new file mode 100644 index 000000000..2cf4a8eb3 --- /dev/null +++ b/libs/fusion/test/sequence/deque_copy.cpp @@ -0,0 +1,22 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/container/deque/deque.hpp> +#include <boost/fusion/container/generation/make_deque.hpp> +#include <boost/fusion/container/generation/deque_tie.hpp> + +#define FUSION_SEQUENCE deque +#include "copy.hpp" + +int +main() +{ + test(); + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/deque_iterator.cpp b/libs/fusion/test/sequence/deque_iterator.cpp new file mode 100644 index 000000000..f10f9b9e3 --- /dev/null +++ b/libs/fusion/test/sequence/deque_iterator.cpp @@ -0,0 +1,19 @@ +/*============================================================================= + Copyright (c) 2001-2011 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/fusion/container/deque/deque.hpp> + +#define FUSION_SEQUENCE deque +#define FUSION_TRAVERSAL_TAG bidirectional_traversal_tag +#include "./iterator.hpp" + +int +main() +{ + test(); + return boost::report_errors(); +} diff --git a/libs/fusion/test/sequence/deque_make.cpp b/libs/fusion/test/sequence/deque_make.cpp new file mode 100644 index 000000000..fe5705335 --- /dev/null +++ b/libs/fusion/test/sequence/deque_make.cpp @@ -0,0 +1,20 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/container/deque/deque.hpp> +#include <boost/fusion/container/generation/make_deque.hpp> + +#define FUSION_SEQUENCE deque +#include "make.hpp" + +int +main() +{ + test(); + return boost::report_errors(); +} diff --git a/libs/fusion/test/sequence/deque_misc.cpp b/libs/fusion/test/sequence/deque_misc.cpp new file mode 100644 index 000000000..c9b880ea3 --- /dev/null +++ b/libs/fusion/test/sequence/deque_misc.cpp @@ -0,0 +1,22 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/container/deque/deque.hpp> +#include <boost/fusion/container/deque/convert.hpp> +#include <boost/fusion/adapted/mpl.hpp> + +#define FUSION_SEQUENCE deque +#include "misc.hpp" + +int +main() +{ + test(); + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/deque_move.cpp b/libs/fusion/test/sequence/deque_move.cpp new file mode 100644 index 000000000..42fda2d9c --- /dev/null +++ b/libs/fusion/test/sequence/deque_move.cpp @@ -0,0 +1,32 @@ +/*============================================================================= + Copyright (c) 2012 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) +==============================================================================*/ +#define BOOST_FUSION_DONT_USE_PREPROCESSED_FILES // $$$ JDG temp $$$ + + +#include <boost/config.hpp> + +#if !defined(BOOST_NO_RVALUE_REFERENCES) + +#include <boost/fusion/container/deque/deque.hpp> + +#define FUSION_SEQUENCE boost::fusion::deque +#include "move.hpp" + +#else +#include <boost/detail/lightweight_test.hpp> +#endif + +int +main() +{ +#if !defined(BOOST_NO_RVALUE_REFERENCES) + test(); +#endif + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/deque_mutate.cpp b/libs/fusion/test/sequence/deque_mutate.cpp new file mode 100644 index 000000000..1564ade9a --- /dev/null +++ b/libs/fusion/test/sequence/deque_mutate.cpp @@ -0,0 +1,20 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 Joel de Guzman + Copyright (c) 2006 + + 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/container/deque/deque.hpp> + +#define FUSION_SEQUENCE deque +#include "mutate.hpp" + +int +main() +{ + test(); + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/deque_tie.cpp b/libs/fusion/test/sequence/deque_tie.cpp new file mode 100644 index 000000000..f6ee91600 --- /dev/null +++ b/libs/fusion/test/sequence/deque_tie.cpp @@ -0,0 +1,23 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/container/deque/deque.hpp> +#include <boost/fusion/container/generation/deque_tie.hpp> +#include <boost/fusion/container/generation/ignore.hpp> +#include <boost/fusion/container/generation/make_deque.hpp> + +#define FUSION_SEQUENCE deque +#include "tie.hpp" + +int +main() +{ + test(); + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/deque_value_at.cpp b/libs/fusion/test/sequence/deque_value_at.cpp new file mode 100644 index 000000000..5b31504fb --- /dev/null +++ b/libs/fusion/test/sequence/deque_value_at.cpp @@ -0,0 +1,20 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/container/deque/deque.hpp> + +#define FUSION_SEQUENCE deque +#include "value_at.hpp" + +int +main() +{ + test(); + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/filter_view.cpp b/libs/fusion/test/sequence/filter_view.cpp new file mode 100644 index 000000000..8ebe14767 --- /dev/null +++ b/libs/fusion/test/sequence/filter_view.cpp @@ -0,0 +1,129 @@ +/*============================================================================= + Copyright (c) 2001-2011 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/vector/vector_iterator.hpp> +#include <boost/fusion/sequence/io/out.hpp> +#include <boost/fusion/sequence/comparison/equal_to.hpp> +#include <boost/fusion/view/filter_view/filter_view.hpp> +#include <boost/fusion/container/generation/make_vector.hpp> +#include <boost/fusion/sequence/intrinsic/size.hpp> +#include <boost/fusion/container/map.hpp> +#include <boost/fusion/sequence/intrinsic/has_key.hpp> +#include <boost/fusion/sequence/intrinsic/begin.hpp> +#include <boost/fusion/iterator/key_of.hpp> +#include <boost/fusion/iterator/value_of_data.hpp> +#include <boost/fusion/iterator/deref_data.hpp> +#include <boost/type_traits/is_class.hpp> +#include <boost/type_traits/is_same.hpp> +#include <boost/mpl/arg.hpp> +#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(", "); + + { + 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(boost::fusion::result_of::size<filter_view_type>::value == 4); + } + + //cschmidt: This is illegal C++. ADL instantiates less<_, int_<3> > - which + //leads to compile errors. + /*{ + // $$$ JDG $$$ For some obscure reason, EDG based compilers + // (e.g. comeau 4.3.3, intel) have problems with this. + // vc7.1 and g++ are ok. The errors from comeau are useless. + +#ifndef __EDG_VERSION__ + 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(boost::fusion::result_of::size<filter_view_type>::value == 4); +#endif + }*/ + + { + // 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((boost::fusion::result_of::equal_to<boost::fusion::result_of::begin<filter_view_type>::type, boost::fusion::result_of::end<filter_view_type>::type>)); + } + + { + typedef map<pair<void, int>, pair<double, std::string> > map_type; + map_type m(make_pair<void>(0), make_pair<double>("Bond")); + + typedef filter_view<map_type const, is_same<_, pair<double, std::string> > > filter_view_type; + filter_view_type f(m); + + BOOST_MPL_ASSERT((boost::fusion::result_of::has_key<filter_view_type, double>::type)); + BOOST_MPL_ASSERT_NOT((boost::fusion::result_of::has_key<filter_view_type, void>::type)); + + BOOST_MPL_ASSERT((is_same<boost::fusion::result_of::key_of<boost::fusion::result_of::begin<filter_view_type>::type>::type, double>)); + BOOST_MPL_ASSERT((is_same<boost::fusion::result_of::value_of_data<boost::fusion::result_of::begin<filter_view_type>::type>::type, std::string>)); + + std::cout << deref_data(begin(f)) << std::endl; + BOOST_TEST((deref_data(begin(f)) == "Bond")); + } + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/front_extended_deque.cpp b/libs/fusion/test/sequence/front_extended_deque.cpp new file mode 100644 index 000000000..d1c903432 --- /dev/null +++ b/libs/fusion/test/sequence/front_extended_deque.cpp @@ -0,0 +1,75 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/container/deque/deque.hpp> +#include <boost/fusion/container/deque/front_extended_deque.hpp> +#include <boost/fusion/sequence/comparison.hpp> +#include <boost/fusion/container/generation/make_vector.hpp> +#include <boost/fusion/mpl.hpp> + +#include <boost/fusion/sequence/intrinsic.hpp> +#include <boost/fusion/iterator.hpp> + +#include <boost/mpl/assert.hpp> +#include <boost/type_traits/is_same.hpp> + +int main() +{ + using namespace boost::fusion; + { + typedef deque<char, long> initial_deque_type; + initial_deque_type initial_deque('a', 101L); + typedef front_extended_deque<initial_deque_type, int> extended_type; + extended_type extended(initial_deque, 1); + + BOOST_TEST(size(extended) == 3); + BOOST_TEST(extended == make_vector(1, 'a', 101L)); + BOOST_TEST(*begin(extended) == 1); + BOOST_TEST(*next(begin(extended)) == 'a'); + BOOST_TEST(*prior(end(extended)) == 101L); + BOOST_TEST(distance(begin(extended), end(extended)) == 3); + BOOST_TEST(*advance_c<2>(begin(extended)) == 101L); + } + { + namespace mpl = boost::mpl; + typedef deque<char, long> initial_deque_type; + typedef front_extended_deque<initial_deque_type, int> extended_type; + + BOOST_MPL_ASSERT((boost::is_same<mpl::at_c<extended_type, 0>::type, int>)); + BOOST_MPL_ASSERT((boost::is_same<mpl::at_c<extended_type, 1>::type, char>)); + BOOST_MPL_ASSERT((boost::is_same<mpl::at_c<extended_type, 2>::type, long>)); + BOOST_MPL_ASSERT((boost::is_same<mpl::deref<mpl::begin<extended_type>::type>::type, int>)); + BOOST_MPL_ASSERT((mpl::equal_to<mpl::size<extended_type>::type, mpl::int_<3> >)); + } + { + char ch('a'); + long l(101L); + int i(1); + typedef deque<char&, long&> initial_deque_type; + initial_deque_type initial_deque(ch, l); + typedef front_extended_deque<initial_deque_type, int&> extended_type; + extended_type extended(initial_deque, i); + BOOST_TEST(extended == make_vector(1, 'a', 101L)); + + char ch2('b'); + long l2(202L); + int i2(2); + extended_type extended2(initial_deque_type(ch2, l2), i2); + + extended = extended2; + + BOOST_TEST(extended == make_vector(2, 'b', 202L)); + + BOOST_TEST(i == i2); + BOOST_TEST(ch == ch2); + BOOST_TEST(l == l2); + } + return boost::report_errors(); +} diff --git a/libs/fusion/test/sequence/io.cpp b/libs/fusion/test/sequence/io.cpp new file mode 100644 index 000000000..74e0f30ce --- /dev/null +++ b/libs/fusion/test/sequence/io.cpp @@ -0,0 +1,116 @@ +/*============================================================================= + Copyright (C) 1999-2003 Jaakko Jarvi + + 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/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(); +} + diff --git a/libs/fusion/test/sequence/iterator.hpp b/libs/fusion/test/sequence/iterator.hpp new file mode 100644 index 000000000..d88b7199f --- /dev/null +++ b/libs/fusion/test/sequence/iterator.hpp @@ -0,0 +1,197 @@ +/*============================================================================= + Copyright (c) 2001-2011 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 <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); + boost::fusion::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); + boost::fusion::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 boost::fusion::result_of::begin<seq_type>::type vi1; + typedef boost::fusion::result_of::begin<cseq_type>::type vi2; + BOOST_STATIC_ASSERT((boost::fusion::result_of::equal_to<vi1 const, vi1>::value)); + BOOST_STATIC_ASSERT((boost::fusion::result_of::equal_to<vi1, vi1 const>::value)); + BOOST_STATIC_ASSERT((boost::fusion::result_of::equal_to<vi1, vi2>::value)); + BOOST_STATIC_ASSERT((boost::fusion::result_of::equal_to<vi1 const, vi2>::value)); + BOOST_STATIC_ASSERT((boost::fusion::result_of::equal_to<vi1, vi2 const>::value)); + BOOST_STATIC_ASSERT((boost::fusion::result_of::equal_to<vi1 const, vi2 const>::value)); + } + + { + typedef FUSION_SEQUENCE<int, int> seq_type; + typedef boost::fusion::result_of::begin<seq_type>::type begin_type; + typedef boost::fusion::result_of::end<seq_type>::type end_type; + typedef boost::fusion::result_of::next<begin_type>::type i1; + typedef boost::fusion::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); + boost::fusion::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((boost::fusion::result_of::distance< + boost::fusion::result_of::begin<seq_type>::type + , boost::fusion::result_of::end<seq_type>::type >::value == 4)); + + BOOST_TEST(distance(begin(t), end(t)).value == 4); + } + + { // Testing tuple iterator boost::fusion::result_of::value_of, boost::fusion::result_of::deref, boost::fusion::result_of::value_at + + typedef FUSION_SEQUENCE<int, char&> seq_type; + typedef boost::fusion::result_of::begin<seq_type>::type i0; + typedef boost::fusion::result_of::next<i0>::type i1; + typedef boost::fusion::result_of::next<boost::fusion::result_of::begin<const seq_type>::type>::type i2; + + BOOST_STATIC_ASSERT(( + is_same<boost::fusion::result_of::value_at_c<seq_type, 0>::type, int>::value)); + + BOOST_STATIC_ASSERT(( + is_same<boost::fusion::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<boost::fusion::result_of::deref<i0>::type, int&>::value)); + BOOST_STATIC_ASSERT((is_same<boost::fusion::result_of::deref<i1>::type, char&>::value)); + + BOOST_STATIC_ASSERT((is_same<boost::fusion::result_of::value_of<i0>::type, int>::value)); + BOOST_STATIC_ASSERT((is_same<boost::fusion::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)); + } +} + + + + diff --git a/libs/fusion/test/sequence/iterator_range.cpp b/libs/fusion/test/sequence/iterator_range.cpp new file mode 100644 index 000000000..18f91af0a --- /dev/null +++ b/libs/fusion/test/sequence/iterator_range.cpp @@ -0,0 +1,115 @@ +/*============================================================================= + Copyright (c) 2001-2011 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/map.hpp> +#include <boost/fusion/container/vector/vector.hpp> +#include <boost/fusion/container/generation/make_vector.hpp> +#include <boost/fusion/view/iterator_range/iterator_range.hpp> +#include <boost/fusion/sequence/comparison/equal_to.hpp> +#include <boost/fusion/sequence/io/out.hpp> +#include <boost/fusion/sequence/intrinsic/size.hpp> +#include <boost/fusion/sequence/intrinsic/begin.hpp> +#include <boost/fusion/sequence/intrinsic/has_key.hpp> +#include <boost/fusion/iterator/advance.hpp> +#include <boost/fusion/iterator/key_of.hpp> +#include <boost/fusion/iterator/value_of_data.hpp> +#include <boost/fusion/iterator/deref_data.hpp> +#include <boost/mpl/vector_c.hpp> +#include <boost/mpl/begin.hpp> +#include <boost/mpl/next.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/static_assert.hpp> + +int +main() +{ + using namespace boost::fusion; + namespace fusion = 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(boost::fusion::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(boost::fusion::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(boost::fusion::result_of::size<slice_t>::value == 2); + } + + { + typedef map<pair<void,std::string>, pair<double,char>,pair<void*, int> > map_type; + map_type m(make_pair<void>("foo"), make_pair<double>('x'), make_pair<void*>(2)); + + typedef iterator_range< + boost::fusion::result_of::begin<map_type>::type + , boost::fusion::result_of::advance_c<boost::fusion::result_of::begin<map_type>::type,2>::type + > range_type; + range_type r(begin(m), advance_c<2>(begin(m))); + + BOOST_MPL_ASSERT((boost::fusion::result_of::has_key<range_type, void>::type)); + BOOST_MPL_ASSERT((boost::fusion::result_of::has_key<range_type, double>::type)); + + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::key_of<boost::fusion::result_of::begin<range_type>::type>::type, void>)); + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::key_of<boost::fusion::result_of::next<boost::fusion::result_of::begin<range_type>::type>::type>::type, double>)); + + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_of_data<boost::fusion::result_of::begin<range_type>::type>::type, std::string>)); + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_of_data<boost::fusion::result_of::next<boost::fusion::result_of::begin<range_type>::type>::type>::type, char>)); + + std::cout << deref_data(begin(r)) << std::endl; + std::cout << deref_data(fusion::next(begin(r))) << std::endl; + BOOST_TEST((deref_data(begin(r)) == "foo")); + BOOST_TEST((deref_data(fusion::next(begin(r))) == 'x')); + } + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/joint_view.cpp b/libs/fusion/test/sequence/joint_view.cpp new file mode 100644 index 000000000..ba5659b74 --- /dev/null +++ b/libs/fusion/test/sequence/joint_view.cpp @@ -0,0 +1,188 @@ +/*============================================================================= + Copyright (c) 2001-2011 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/map.hpp> +#include <boost/fusion/container/set.hpp> +#include <boost/fusion/container/vector/vector.hpp> +#include <boost/fusion/view/joint_view/joint_view.hpp> +#include <boost/fusion/sequence/io/out.hpp> +#include <boost/fusion/sequence/comparison/equal_to.hpp> +#include <boost/fusion/container/generation/make_vector.hpp> +#include <boost/fusion/sequence/intrinsic/at.hpp> +#include <boost/fusion/sequence/intrinsic/has_key.hpp> +#include <boost/fusion/sequence/intrinsic/begin.hpp> +#include <boost/fusion/iterator/next.hpp> +#include <boost/fusion/iterator/key_of.hpp> +#include <boost/fusion/iterator/value_of.hpp> +#include <boost/fusion/iterator/deref_data.hpp> +#include <boost/mpl/assert.hpp> +#include <string> + +struct X +{ + operator char const*() const + { + return "<X-object>"; + } +}; + +int +main() +{ + using namespace boost::fusion; + namespace fusion = 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()); + } + } + + { + typedef map<pair<void,int> > map_type; + map_type m(make_pair<void>(0)); + + typedef set<std::string, float> set_type; + set_type s("foo", 1.3f); + + typedef joint_view<map_type, set_type> joint_view_type; + joint_view_type j(m,s); + + BOOST_MPL_ASSERT((boost::fusion::result_of::has_key<joint_view_type, void>::type)); + BOOST_MPL_ASSERT((boost::fusion::result_of::has_key<joint_view_type, std::string>::type)); + BOOST_MPL_ASSERT((boost::fusion::result_of::has_key<joint_view_type, float>::type)); + + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::key_of<boost::fusion::result_of::begin<joint_view_type>::type>::type, void>)); + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::key_of<boost::fusion::result_of::next<boost::fusion::result_of::begin<joint_view_type>::type>::type>::type, std::string>)); + BOOST_MPL_ASSERT((boost::is_same< + boost::fusion::result_of::key_of<boost::fusion::result_of::next<boost::fusion::result_of::next<boost::fusion::result_of::begin<joint_view_type>::type>::type>::type>::type + , float>)); + + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_of_data<boost::fusion::result_of::begin<joint_view_type>::type>::type, int>)); + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_of_data<boost::fusion::result_of::next<boost::fusion::result_of::begin<joint_view_type>::type>::type>::type, std::string>)); + BOOST_MPL_ASSERT((boost::is_same< + boost::fusion::result_of::value_of_data<boost::fusion::result_of::next<boost::fusion::result_of::next<boost::fusion::result_of::begin<joint_view_type>::type>::type>::type>::type + , float>)); + + std::cout << deref_data(begin(j)) << std::endl; + std::cout << deref_data(fusion::next(begin(j))) << std::endl; + std::cout << deref_data(fusion::next(fusion::next(begin(j)))) << std::endl; + BOOST_TEST((deref_data(begin(j)) == 0)); + BOOST_TEST((deref_data(fusion::next(begin(j))) == "foo")); + BOOST_TEST((deref_data(fusion::next(fusion::next(begin(j)))) == 1.3f)); + } + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/list_comparison.cpp b/libs/fusion/test/sequence/list_comparison.cpp new file mode 100644 index 000000000..2a02eba01 --- /dev/null +++ b/libs/fusion/test/sequence/list_comparison.cpp @@ -0,0 +1,19 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/container/list/list.hpp> + +#define FUSION_SEQUENCE list +#include "comparison.hpp" + +int +main() +{ + equality_test(); + ordering_test(); + return boost::report_errors(); +} diff --git a/libs/fusion/test/sequence/list_construction.cpp b/libs/fusion/test/sequence/list_construction.cpp new file mode 100644 index 000000000..a10b1e1a9 --- /dev/null +++ b/libs/fusion/test/sequence/list_construction.cpp @@ -0,0 +1,18 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/container/list/list.hpp> + +#define FUSION_SEQUENCE list +#include "construction.hpp" + +int +main() +{ + test(); + return boost::report_errors(); +} diff --git a/libs/fusion/test/sequence/list_copy.cpp b/libs/fusion/test/sequence/list_copy.cpp new file mode 100644 index 000000000..adb588141 --- /dev/null +++ b/libs/fusion/test/sequence/list_copy.cpp @@ -0,0 +1,21 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/container/list/list.hpp> +#include <boost/fusion/container/generation/make_list.hpp> +#include <boost/fusion/container/generation/list_tie.hpp> + +#define FUSION_SEQUENCE list +#include "copy.hpp" + +int +main() +{ + test(); + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/list_iterator.cpp b/libs/fusion/test/sequence/list_iterator.cpp new file mode 100644 index 000000000..62d670878 --- /dev/null +++ b/libs/fusion/test/sequence/list_iterator.cpp @@ -0,0 +1,22 @@ +/*============================================================================= + Copyright (c) 2001-2011 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/fusion/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(); +} + + + diff --git a/libs/fusion/test/sequence/list_make.cpp b/libs/fusion/test/sequence/list_make.cpp new file mode 100644 index 000000000..296b6063e --- /dev/null +++ b/libs/fusion/test/sequence/list_make.cpp @@ -0,0 +1,20 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/container/list/list.hpp> +#include <boost/fusion/container/generation/make_list.hpp> + +#define FUSION_SEQUENCE list +#include "make.hpp" + +int +main() +{ + test(); + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/list_misc.cpp b/libs/fusion/test/sequence/list_misc.cpp new file mode 100644 index 000000000..28d84854b --- /dev/null +++ b/libs/fusion/test/sequence/list_misc.cpp @@ -0,0 +1,21 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/container/list/list.hpp> +#include <boost/fusion/container/list/convert.hpp> + +#define FUSION_SEQUENCE list +#define FUSION_FORWARD_ONLY +#include "misc.hpp" + +int +main() +{ + test(); + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/list_mutate.cpp b/libs/fusion/test/sequence/list_mutate.cpp new file mode 100644 index 000000000..b2736679c --- /dev/null +++ b/libs/fusion/test/sequence/list_mutate.cpp @@ -0,0 +1,19 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/container/list/list.hpp> + +#define FUSION_SEQUENCE list +#include "mutate.hpp" + +int +main() +{ + test(); + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/list_tie.cpp b/libs/fusion/test/sequence/list_tie.cpp new file mode 100644 index 000000000..30c8ed83d --- /dev/null +++ b/libs/fusion/test/sequence/list_tie.cpp @@ -0,0 +1,22 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/container/list/list.hpp> +#include <boost/fusion/container/generation/list_tie.hpp> +#include <boost/fusion/container/generation/ignore.hpp> +#include <boost/fusion/container/generation/make_list.hpp> + +#define FUSION_SEQUENCE list +#include "tie.hpp" + +int +main() +{ + test(); + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/list_value_at.cpp b/libs/fusion/test/sequence/list_value_at.cpp new file mode 100644 index 000000000..487968dae --- /dev/null +++ b/libs/fusion/test/sequence/list_value_at.cpp @@ -0,0 +1,19 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/container/list/list.hpp> + +#define FUSION_SEQUENCE list +#include "value_at.hpp" + +int +main() +{ + test(); + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/make.hpp b/libs/fusion/test/sequence/make.hpp new file mode 100644 index 000000000..00eaed2cd --- /dev/null +++ b/libs/fusion/test/sequence/make.hpp @@ -0,0 +1,88 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/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 test_detail +{ + // 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; + using namespace test_detail; + + { + 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); + } +} diff --git a/libs/fusion/test/sequence/make_list.cpp b/libs/fusion/test/sequence/make_list.cpp new file mode 100644 index 000000000..296b6063e --- /dev/null +++ b/libs/fusion/test/sequence/make_list.cpp @@ -0,0 +1,20 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/container/list/list.hpp> +#include <boost/fusion/container/generation/make_list.hpp> + +#define FUSION_SEQUENCE list +#include "make.hpp" + +int +main() +{ + test(); + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/make_vector.cpp b/libs/fusion/test/sequence/make_vector.cpp new file mode 100644 index 000000000..8a687354a --- /dev/null +++ b/libs/fusion/test/sequence/make_vector.cpp @@ -0,0 +1,20 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/container/vector/vector.hpp> +#include <boost/fusion/container/generation/make_vector.hpp> + +#define FUSION_SEQUENCE vector +#include "make.hpp" + +int +main() +{ + test(); + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/map.cpp b/libs/fusion/test/sequence/map.cpp new file mode 100644 index 000000000..b149d24e6 --- /dev/null +++ b/libs/fusion/test/sequence/map.cpp @@ -0,0 +1,88 @@ +/*============================================================================= + Copyright (c) 2001-2011 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/map/map.hpp> +#include <boost/fusion/container/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/intrinsic/begin.hpp> +#include <boost/fusion/sequence/io/out.hpp> +#include <boost/fusion/iterator/key_of.hpp> +#include <boost/fusion/iterator/deref_data.hpp> +#include <boost/fusion/iterator/value_of_data.hpp> +#include <boost/fusion/iterator/next.hpp> +#include <boost/fusion/support/pair.hpp> +#include <boost/fusion/support/category_of.hpp> +#include <boost/static_assert.hpp> +#include <boost/mpl/assert.hpp> +#include <iostream> +#include <string> + +int +main() +{ + using namespace boost::fusion; + using namespace boost; + namespace fusion = boost::fusion; + 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<boost::fusion::result_of::value_at_key<map_type, int>::type, char>::value)); + BOOST_STATIC_ASSERT(( + boost::is_same<boost::fusion::result_of::value_at_key<map_type, double>::type, std::string>::value)); + + std::cout << m << std::endl; + + BOOST_STATIC_ASSERT((boost::fusion::result_of::has_key<map_type, int>::value)); + BOOST_STATIC_ASSERT((boost::fusion::result_of::has_key<map_type, double>::value)); + BOOST_STATIC_ASSERT((!boost::fusion::result_of::has_key<map_type, std::string>::value)); + + std::cout << deref_data(begin(m)) << std::endl; + std::cout << deref_data(fusion::next(begin(m))) << std::endl; + + BOOST_TEST(deref_data(begin(m)) == 'X'); + BOOST_TEST(deref_data(fusion::next(begin(m))) == "Men"); + + BOOST_STATIC_ASSERT((boost::is_same<boost::fusion::result_of::key_of<boost::fusion::result_of::begin<map_type>::type>::type, int>::value)); + BOOST_STATIC_ASSERT((boost::is_same<boost::fusion::result_of::key_of<boost::fusion::result_of::next<boost::fusion::result_of::begin<map_type>::type>::type>::type, double>::value)); + BOOST_STATIC_ASSERT((boost::is_same<boost::fusion::result_of::value_of_data<boost::fusion::result_of::begin<map_type>::type>::type, char>::value)); + BOOST_STATIC_ASSERT((boost::is_same<boost::fusion::result_of::value_of_data<boost::fusion::result_of::next<boost::fusion::result_of::begin<map_type>::type>::type>::type, std::string>::value)); + } + + { + 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(); +} + diff --git a/libs/fusion/test/sequence/map_tie.cpp b/libs/fusion/test/sequence/map_tie.cpp new file mode 100644 index 000000000..a3547375f --- /dev/null +++ b/libs/fusion/test/sequence/map_tie.cpp @@ -0,0 +1,35 @@ +/*============================================================================= + Copyright (c) 2001-2011 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/container/generation/map_tie.hpp> +#include <boost/fusion/sequence/intrinsic/at_key.hpp> + +struct key_zero; +struct key_one; + +int main() +{ + using namespace boost::fusion; + { + int number = 101; + char letter = 'a'; + BOOST_TEST(at_key<key_zero>(map_tie<key_zero, key_one>(number, letter)) == 101); + BOOST_TEST(at_key<key_one>(map_tie<key_zero, key_one>(number, letter)) == 'a'); + + BOOST_TEST(&at_key<key_zero>(map_tie<key_zero, key_one>(number, letter)) == &number); + BOOST_TEST(&at_key<key_one>(map_tie<key_zero, key_one>(number, letter)) == &letter); + + at_key<key_zero>(map_tie<key_zero, key_one>(number, letter)) = 202; + at_key<key_one>(map_tie<key_zero, key_one>(number, letter)) = 'b'; + + BOOST_TEST(number == 202); + BOOST_TEST(letter == 'b'); + } + return boost::report_errors(); +} diff --git a/libs/fusion/test/sequence/misc.hpp b/libs/fusion/test/sequence/misc.hpp new file mode 100644 index 000000000..610b107a6 --- /dev/null +++ b/libs/fusion/test/sequence/misc.hpp @@ -0,0 +1,189 @@ +/*============================================================================= + Copyright (C) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/sequence/intrinsic.hpp> +#include <boost/fusion/support/is_sequence.hpp> +#include <boost/fusion/mpl.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 boost::fusion::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(!boost::fusion::result_of::empty<t1>::value); + BOOST_STATIC_ASSERT(boost::fusion::result_of::empty<t2>::value); + } + + { // testing front & back + + typedef FUSION_SEQUENCE<int, float, std::string> tup; + tup t(1, 2.2f, "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)); + + } +} diff --git a/libs/fusion/test/sequence/move.hpp b/libs/fusion/test/sequence/move.hpp new file mode 100644 index 000000000..b96a60e7e --- /dev/null +++ b/libs/fusion/test/sequence/move.hpp @@ -0,0 +1,120 @@ +/*============================================================================= + Copyright (c) 2012 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/config.hpp> + +#if defined(BOOST_NO_RVALUE_REFERENCES) +#error "Valid only on compilers that support rvalues" +#endif + +#include <boost/detail/lightweight_test.hpp> +#include <boost/static_assert.hpp> +#include <boost/assert.hpp> +#include <vector> + + +namespace test_detail +{ + int copies = 0; + + void incr_copy() + { + copies++; + } + + struct x + { + int i; + x() : i(123) {} + + x(x&& rhs) : i(rhs.i) {} + + x& operator=(x&& rhs) + { + i = rhs.i; + return *this; + } + + x(x const& rhs) + { + incr_copy(); + } + + x& operator=(x const& rhs) + { + incr_copy(); + return *this; + } + }; + + typedef std::vector<x> vector_type; + extern bool disable_rvo; // to disable RVO + + vector_type + generate_vec() + { + vector_type v; + v.push_back(x()); + if (disable_rvo) + return v; + return vector_type(); + } + + + template <typename T> + T move_me(T && val) + { + T r(std::move(val)); + if (disable_rvo) + return r; + return T(); + } + + typedef FUSION_SEQUENCE<std::vector<x>> return_type; + + return_type + generate() + { + return_type r(generate_vec()); + if (disable_rvo) + return r; + return return_type(); + } + + typedef FUSION_SEQUENCE<std::vector<x>, x> return_type2; + + return_type2 + generate2() + { + return_type2 r(generate_vec(), x()); + if (disable_rvo) + return r; + return return_type2(); + } +} + +void test() +{ + using namespace boost::fusion; + using namespace test_detail; + + return_type v = move_me(generate()); + BOOST_TEST(copies == 0); + + return_type2 v2 = move_me(generate2()); + BOOST_TEST(copies == 0); + + v2 = move_me(generate2()); + BOOST_TEST(copies == 0); + + std::cout << "Copies: " << copies << std::endl; +} + +namespace test_detail +{ + bool disable_rvo = true; +} + diff --git a/libs/fusion/test/sequence/mutate.hpp b/libs/fusion/test/sequence/mutate.hpp new file mode 100644 index 000000000..9bc9be8ac --- /dev/null +++ b/libs/fusion/test/sequence/mutate.hpp @@ -0,0 +1,52 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/sequence/intrinsic/at.hpp> + +#if !defined(FUSION_AT) +#define FUSION_AT at_c +#endif + +namespace test_detail +{ + // 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; + using namespace test_detail; + + 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)); +} diff --git a/libs/fusion/test/sequence/nview.cpp b/libs/fusion/test/sequence/nview.cpp new file mode 100644 index 000000000..dab982a52 --- /dev/null +++ b/libs/fusion/test/sequence/nview.cpp @@ -0,0 +1,139 @@ +/*============================================================================= + Copyright (c) 2009 Hartmut Kaiser + + 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/include/vector.hpp> +#include <boost/fusion/include/struct.hpp> +#include <boost/fusion/include/equal_to.hpp> +#include <boost/fusion/include/io.hpp> +#include <boost/fusion/include/nview.hpp> + +#include <string> +#include <iostream> + +struct test { + int int_; + std::string string_; + double double_; +}; + +BOOST_FUSION_ADAPT_STRUCT( + test, + (int, int_) + (std::string, string_) + (double, double_) +) + +namespace fusion = boost::fusion; + +template <typename Sequence> +bool check_size(Sequence const& s, int seqsize) +{ + return fusion::size(s) == seqsize; +} + +template <typename Sequence, typename T> +bool check_deref_begin(Sequence const& s, T val) +{ + return fusion::deref(fusion::begin(s)) == val; +} + +template <typename Sequence, typename T> +bool check_deref_next(Sequence const& s, T val) +{ + return fusion::deref(fusion::next(fusion::begin(s))) == val; +} + +template <int N, typename Sequence, typename T> +bool check_deref_advance(Sequence const& s, T val) +{ + return fusion::deref(fusion::advance_c<N>(fusion::begin(s))) == val; +} + +template <typename Sequence, typename T> +bool check_deref_prior(Sequence const& s, T val) +{ + return fusion::deref(fusion::prior(fusion::end(s))) == val; +} + +template <int N, typename Sequence, typename T> +bool check_at(Sequence const& s, T val) +{ + return fusion::at_c<N>(s) == val; +} + +template <typename Sequence> +bool check_distance(Sequence const& s, int val) +{ + return fusion::distance(fusion::begin(s), fusion::end(s)) == val; +} + +int main() +{ + test t; + t.int_ = 1; + t.string_ = "test"; + t.double_ = 2.0; + + using fusion::as_nview; + + // check size() + { + BOOST_TEST(check_size(as_nview<0>(t), 1)); + BOOST_TEST(check_size(as_nview<2, 1>(t), 2)); + BOOST_TEST(check_size(as_nview<2, 1, 0>(t), 3)); + BOOST_TEST(check_size(as_nview<2, 1, 0, 2, 0>(t), 5)); + } + + // check deref/begin + { + BOOST_TEST(check_deref_begin(as_nview<0>(t), 1)); + BOOST_TEST(check_deref_begin(as_nview<2, 1>(t), 2.0)); + BOOST_TEST(check_deref_begin(as_nview<1, 2, 0>(t), "test")); + BOOST_TEST(check_deref_begin(as_nview<2, 1, 0, 2, 0>(t), 2.0)); + } + + // check deref/next + { + BOOST_TEST(check_deref_next(as_nview<2, 1>(t), "test")); + BOOST_TEST(check_deref_next(as_nview<1, 2, 0>(t), 2.0)); + BOOST_TEST(check_deref_next(as_nview<2, 0, 1, 2, 0>(t), 1)); + } + + // check deref/advance + { + BOOST_TEST(check_deref_advance<0>(as_nview<2, 1>(t), 2.0)); + BOOST_TEST(check_deref_advance<2>(as_nview<1, 2, 0>(t), 1)); + BOOST_TEST(check_deref_advance<4>(as_nview<2, 0, 1, 2, 0>(t), 1)); + } + + // check deref/prior + { + BOOST_TEST(check_deref_prior(as_nview<2, 1>(t), "test")); + BOOST_TEST(check_deref_prior(as_nview<1, 2, 0>(t), 1)); + BOOST_TEST(check_deref_prior(as_nview<2, 0, 1, 2, 0>(t), 1)); + } + + // check at + { + BOOST_TEST(check_at<0>(as_nview<0>(t), 1)); + BOOST_TEST(check_at<1>(as_nview<2, 1>(t), "test")); + BOOST_TEST(check_at<2>(as_nview<1, 2, 0>(t), 1)); + BOOST_TEST(check_at<4>(as_nview<2, 1, 0, 2, 0>(t), 1)); + } + + // check distance + { + BOOST_TEST(check_distance(as_nview<0>(t), 1)); + BOOST_TEST(check_distance(as_nview<2, 1>(t), 2)); + BOOST_TEST(check_distance(as_nview<1, 2, 0>(t), 3)); + BOOST_TEST(check_distance(as_nview<2, 1, 0, 2, 0>(t), 5)); + } + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/repetitive_view.cpp b/libs/fusion/test/sequence/repetitive_view.cpp new file mode 100644 index 000000000..54da37bc8 --- /dev/null +++ b/libs/fusion/test/sequence/repetitive_view.cpp @@ -0,0 +1,53 @@ +/*============================================================================= + Copyright (c) 2007 Tobias Schwinger + + Use modification and distribution are 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/view/repetitive_view.hpp> + +#include <boost/fusion/container/vector.hpp> +#include <boost/fusion/view/joint_view.hpp> +#include <boost/fusion/algorithm/transformation/zip.hpp> +#include <boost/fusion/algorithm/iteration/for_each.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include <boost/fusion/sequence/intrinsic/begin.hpp> +#include <boost/fusion/iterator/next.hpp> + +#include <boost/fusion/functional/generation/make_fused_procedure.hpp> + +struct check_equal +{ + template<typename LHS, typename RHS> + void operator()(LHS const& lhs, RHS const& rhs) const + { + BOOST_TEST(( boost::is_same<LHS,RHS>::value )); + BOOST_TEST(( lhs == rhs )); + } +}; + +int main() +{ + using namespace boost::fusion; + + typedef boost::fusion::vector<int,long,float,double> seq_t; + seq_t seq(1,2l,3.0f,4.0); + + typedef repetitive_view<seq_t> view_t; + view_t view(seq); + + typedef joint_view<seq_t,seq_t> seq_twice_t; + typedef joint_view<seq_t,seq_twice_t> seq_repeated_t; + seq_twice_t seq_twice(seq,seq); + seq_repeated_t seq_repeated(seq,seq_twice); + + for_each(zip(view,seq_repeated), make_fused_procedure(check_equal())); + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/reverse_view.cpp b/libs/fusion/test/sequence/reverse_view.cpp new file mode 100644 index 000000000..36bda96c5 --- /dev/null +++ b/libs/fusion/test/sequence/reverse_view.cpp @@ -0,0 +1,87 @@ +/*============================================================================= + Copyright (c) 2001-2011 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/view/reverse_view/reverse_view.hpp> +#include <boost/fusion/sequence/intrinsic/begin.hpp> +#include <boost/fusion/sequence/intrinsic/at.hpp> +#include <boost/fusion/sequence/intrinsic/value_at.hpp> +#include <boost/fusion/iterator/next.hpp> +#include <boost/fusion/iterator/prior.hpp> +#include <boost/fusion/iterator/deref.hpp> +#include <boost/fusion/iterator/advance.hpp> +#include <boost/fusion/iterator/distance.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/mpl/range_c.hpp> +#include <boost/type_traits/is_same.hpp> + + +int +main() +{ + 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 boost::fusion::result_of::begin<view_type>::type first_type; + first_type first_it(begin(rev)); + typedef boost::fusion::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)); + + BOOST_TEST((at_c<0>(rev)==s)); + BOOST_TEST((at_c<1>(rev)==123456789)); + BOOST_TEST((at_c<2>(rev)=='x')); + BOOST_TEST((at_c<3>(rev)==123)); + + BOOST_MPL_ASSERT(( + boost::is_same<boost::fusion::result_of::value_at_c<view_type,0>::type,char const*> + )); + BOOST_MPL_ASSERT(( + boost::is_same<boost::fusion::result_of::value_at_c<view_type,1>::type,long> + )); + BOOST_MPL_ASSERT(( + boost::is_same<boost::fusion::result_of::value_at_c<view_type,2>::type,char> + )); + BOOST_MPL_ASSERT(( + boost::is_same<boost::fusion::result_of::value_at_c<view_type,3>::type,int> + )); + } + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/segmented_iterator_range.cpp b/libs/fusion/test/sequence/segmented_iterator_range.cpp new file mode 100644 index 000000000..df49407a6 --- /dev/null +++ b/libs/fusion/test/sequence/segmented_iterator_range.cpp @@ -0,0 +1,146 @@ +/*============================================================================= + Copyright (c) 2001-2011 Joel de Guzman + Copyright (c) 2011 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 <sstream> +#include <boost/detail/lightweight_test.hpp> +#include <boost/fusion/algorithm/iteration/for_each.hpp> +#include <boost/fusion/algorithm/query/find_if.hpp> +#include <boost/fusion/container/vector/vector.hpp> +#include <boost/fusion/container/generation/make_vector.hpp> +#include <boost/fusion/view/iterator_range/iterator_range.hpp> +#include <boost/fusion/sequence/comparison/equal_to.hpp> +#include <boost/fusion/sequence/io/out.hpp> +#include <boost/fusion/sequence/intrinsic/size.hpp> +#include <boost/mpl/vector_c.hpp> +#include <boost/mpl/begin.hpp> +#include <boost/mpl/next.hpp> +#include <boost/static_assert.hpp> +#include "tree.hpp" + +struct ostream_fun +{ + ostream_fun(std::ostream &sout) + : sout_(sout) + {} + template<typename T> + void operator ()(T const &t) const + { + sout_ << t << ' '; + } +private: + std::ostream & sout_; +}; + +template<typename Tree> +void +process_tree(Tree const &tree) +{ + using namespace boost; + using namespace fusion; + using mpl::_; + + typedef typename boost::fusion::result_of::find_if<Tree const, is_same<_,short> >::type short_iter; + typedef typename boost::fusion::result_of::find_if<Tree const, is_same<_,float> >::type float_iter; + + typedef iterator_range<short_iter, float_iter> slice_t; + BOOST_STATIC_ASSERT(traits::is_segmented<slice_t>::value); + + // find_if of a segmented data structure returns generic + // segmented iterators + short_iter si = find_if<is_same<_,short> >(tree); + float_iter fi = find_if<is_same<_,float> >(tree); + + // If you put them in an iterator range, the range + // is automatically a segmented data structure. + slice_t slice(si, fi); + + std::stringstream sout; + fusion::for_each(slice, ostream_fun(sout)); + BOOST_TEST((sout.str() == "100 e f 0 B ")); +} + +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(boost::fusion::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(boost::fusion::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(boost::fusion::result_of::size<slice_t>::value == 2); + } + + { + 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(); +} + diff --git a/libs/fusion/test/sequence/set.cpp b/libs/fusion/test/sequence/set.cpp new file mode 100644 index 000000000..1ea6ba241 --- /dev/null +++ b/libs/fusion/test/sequence/set.cpp @@ -0,0 +1,83 @@ +/*============================================================================= + Copyright (c) 2001-2011 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/sequence/intrinsic/at_key.hpp> +#include <boost/fusion/sequence/intrinsic/value_at_key.hpp> +#include <boost/fusion/sequence/intrinsic/has_key.hpp> +#include <boost/fusion/sequence/intrinsic/begin.hpp> +#include <boost/fusion/sequence/io/out.hpp> +#include <boost/fusion/iterator/key_of.hpp> +#include <boost/fusion/iterator/deref_data.hpp> +#include <boost/fusion/iterator/value_of_data.hpp> +#include <boost/fusion/iterator/next.hpp> +#include <boost/fusion/support/pair.hpp> +#include <boost/fusion/support/category_of.hpp> +#include <boost/static_assert.hpp> +#include <boost/mpl/assert.hpp> +#include <iostream> +#include <string> + +int +main() +{ + using namespace boost::fusion; + using namespace boost; + namespace fusion = boost::fusion; + 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<boost::fusion::result_of::value_at_key<set_type, int>::type, int>::value)); + BOOST_STATIC_ASSERT(( + boost::is_same<boost::fusion::result_of::value_at_key<set_type, std::string>::type, std::string>::value)); + + std::cout << m << std::endl; + + BOOST_STATIC_ASSERT((boost::fusion::result_of::has_key<set_type, int>::value)); + BOOST_STATIC_ASSERT((boost::fusion::result_of::has_key<set_type, std::string>::value)); + BOOST_STATIC_ASSERT((!boost::fusion::result_of::has_key<set_type, double>::value)); + + std::cout << deref_data(begin(m)) << std::endl; + std::cout << deref_data(fusion::next(begin(m))) << std::endl; + + BOOST_TEST(deref_data(begin(m)) == 123); + BOOST_TEST(deref_data(fusion::next(begin(m))) == "Hola"); + + BOOST_STATIC_ASSERT((boost::is_same<boost::fusion::result_of::key_of<boost::fusion::result_of::begin<set_type>::type>::type, int>::value)); + BOOST_STATIC_ASSERT((boost::is_same<boost::fusion::result_of::key_of<boost::fusion::result_of::next<boost::fusion::result_of::begin<set_type>::type>::type>::type, std::string>::value)); + BOOST_STATIC_ASSERT((boost::is_same<boost::fusion::result_of::value_of_data<boost::fusion::result_of::begin<set_type>::type>::type, int>::value)); + BOOST_STATIC_ASSERT((boost::is_same<boost::fusion::result_of::value_of_data<boost::fusion::result_of::next<boost::fusion::result_of::begin<set_type>::type>::type>::type, std::string>::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(); +} + diff --git a/libs/fusion/test/sequence/single_view.cpp b/libs/fusion/test/sequence/single_view.cpp new file mode 100644 index 000000000..6fa517551 --- /dev/null +++ b/libs/fusion/test/sequence/single_view.cpp @@ -0,0 +1,93 @@ +/*============================================================================= + Copyright (c) 2001-2011 Joel de Guzman + Copyright (c) 2011 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/sequence/io/out.hpp> +#include <boost/fusion/view/single_view/single_view.hpp> +#include <boost/fusion/sequence/intrinsic/at.hpp> +#include <boost/fusion/sequence/intrinsic/begin.hpp> +#include <boost/fusion/sequence/intrinsic/end.hpp> +#include <boost/fusion/sequence/intrinsic/size.hpp> +#include <boost/fusion/sequence/intrinsic/front.hpp> +#include <boost/fusion/sequence/intrinsic/back.hpp> +#include <boost/fusion/sequence/intrinsic/empty.hpp> +#include <boost/fusion/sequence/intrinsic/value_at.hpp> +#include <boost/fusion/iterator/next.hpp> +#include <boost/fusion/iterator/prior.hpp> +#include <boost/fusion/iterator/deref.hpp> +#include <boost/fusion/iterator/advance.hpp> +#include <boost/fusion/iterator/distance.hpp> +#include <boost/mpl/int.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/type_traits/is_same.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(at<boost::mpl::int_<0> >(view1) == 3); + BOOST_TEST(view1.val == 3); + BOOST_TEST(3 == front(view1)); + BOOST_TEST(3 == back(view1)); + BOOST_TEST(!empty(view1)); + BOOST_TEST(next(begin(view1)) == end(view1)); + BOOST_TEST(prior(end(view1)) == begin(view1)); + BOOST_TEST(!(next(begin(view1)) != end(view1))); + BOOST_TEST(!(prior(end(view1)) != begin(view1))); + BOOST_TEST(1 == distance(begin(view1), end(view1))); + BOOST_TEST(0 == distance(end(view1), end(view1))); + BOOST_TEST(0 == distance(begin(view1), begin(view1))); + BOOST_TEST(end(view1) == advance<boost::mpl::int_<1> >(begin(view1))); + BOOST_TEST(begin(view1) == advance<boost::mpl::int_<0> >(begin(view1))); + BOOST_TEST(end(view1) == advance<boost::mpl::int_<0> >(end(view1))); + BOOST_TEST(begin(view1) == advance<boost::mpl::int_<-1> >(end(view1))); + BOOST_TEST(end(view1) == advance_c<1>(begin(view1))); + BOOST_TEST(begin(view1) == advance_c<0>(begin(view1))); + BOOST_TEST(end(view1) == advance_c<0>(end(view1))); + BOOST_TEST(begin(view1) == advance_c<-1>(end(view1))); + BOOST_TEST(1 == size(view1)); + BOOST_MPL_ASSERT((boost::is_same<int, boost::fusion::result_of::value_at<single_view<int>, boost::mpl::int_<0> >::type>)); + + 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(); +} + diff --git a/libs/fusion/test/sequence/std_pair.cpp b/libs/fusion/test/sequence/std_pair.cpp new file mode 100644 index 000000000..19f8e2a33 --- /dev/null +++ b/libs/fusion/test/sequence/std_pair.cpp @@ -0,0 +1,99 @@ +/*============================================================================= + Copyright (c) 2001-2011 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/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/container/vector/vector.hpp> +#include <boost/fusion/container/list/list.hpp> +#include <boost/fusion/container/generation/make_vector.hpp> +#include <boost/fusion/container/vector/convert.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/mpl.hpp> +#include <boost/fusion/support/is_view.hpp> +#include <boost/mpl/is_sequence.hpp> +#include <boost/mpl/front.hpp> +#include <boost/mpl/assert.hpp> +#include <iostream> +#include <string> +#include <utility> + +int +main() +{ + using namespace boost::fusion; + using namespace boost; + + 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(boost::fusion::result_of::size<pair_type>::value == 2); + BOOST_STATIC_ASSERT(!boost::fusion::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!!!"); + } + + { + typedef std::pair<int, std::string> pair_type; + BOOST_MPL_ASSERT((mpl::is_sequence<pair_type>)); + BOOST_MPL_ASSERT((boost::is_same<int, mpl::front<pair_type>::type>)); + } + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/std_tuple_iterator.cpp b/libs/fusion/test/sequence/std_tuple_iterator.cpp new file mode 100644 index 000000000..1592eef5f --- /dev/null +++ b/libs/fusion/test/sequence/std_tuple_iterator.cpp @@ -0,0 +1,35 @@ +/*============================================================================= + Copyright (c) 2001-2011 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/config.hpp> + +// The std_tuple_iterator adaptor only supports implementations +// using variadic templates +#if !defined(BOOST_NO_VARIADIC_TEMPLATES) + +#include <boost/fusion/adapted/std_tuple.hpp> + +#define FUSION_SEQUENCE std::tuple +#define FUSION_TRAVERSAL_TAG random_access_traversal_tag +#include "./iterator.hpp" + +int +main() +{ + test(); + return boost::report_errors(); +} + +#else + +int +main() +{ + return 0; +} + +#endif + diff --git a/libs/fusion/test/sequence/swap.cpp b/libs/fusion/test/sequence/swap.cpp new file mode 100644 index 000000000..cac832b4b --- /dev/null +++ b/libs/fusion/test/sequence/swap.cpp @@ -0,0 +1,35 @@ +/*============================================================================= + Copyright (c) 2001-2011 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/fusion/sequence/intrinsic/swap.hpp> +#include <boost/fusion/container/vector.hpp> +#include <boost/fusion/container/generation/make_vector.hpp> +#include <boost/fusion/sequence/comparison/equal_to.hpp> +#include <boost/detail/lightweight_test.hpp> + +#include <boost/mpl/assert.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include <vector> + +int main() +{ + namespace fusion = boost::fusion; + { + typedef fusion::vector<std::vector<int>, char> test_vector; + BOOST_MPL_ASSERT((boost::is_same<void, boost::fusion::result_of::swap<test_vector, test_vector>::type>)); + + test_vector v1(std::vector<int>(1, 101), 'a'), v2(std::vector<int>(1, 202), 'b'); + + fusion::swap(v1, v2); + + BOOST_TEST(v1 == fusion::make_vector(std::vector<int>(1, 202), 'b')); + BOOST_TEST(v2 == fusion::make_vector(std::vector<int>(1, 101), 'a')); + } + return boost::report_errors(); +} diff --git a/libs/fusion/test/sequence/test_deduce_sequence.cpp b/libs/fusion/test/sequence/test_deduce_sequence.cpp new file mode 100644 index 000000000..d137cd307 --- /dev/null +++ b/libs/fusion/test/sequence/test_deduce_sequence.cpp @@ -0,0 +1,16 @@ + +#include <boost/mpl/vector.hpp> +#include <boost/fusion/support.hpp> + +typedef boost::fusion::traits::deduce_sequence < + +boost::mpl::vector<int, char> + +>::type seq1_t; + + +typedef boost::fusion::traits::deduce_sequence < + +boost::fusion::vector<int, char> + +>::type seq2_t; diff --git a/libs/fusion/test/sequence/tie.hpp b/libs/fusion/test/sequence/tie.hpp new file mode 100644 index 000000000..536af1e95 --- /dev/null +++ b/libs/fusion/test/sequence/tie.hpp @@ -0,0 +1,85 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/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 test_detail +{ + // 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; + using namespace test_detail; + + 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); +} diff --git a/libs/fusion/test/sequence/tr1_tuple_auto_conv.cpp b/libs/fusion/test/sequence/tr1_tuple_auto_conv.cpp new file mode 100644 index 000000000..010d4c710 --- /dev/null +++ b/libs/fusion/test/sequence/tr1_tuple_auto_conv.cpp @@ -0,0 +1,56 @@ +#include <boost/tr1/memory.hpp> +#include <boost/tr1/tuple.hpp> +#include <boost/any.hpp> +#include <iostream> + +namespace Core +{ + class AutoConverter + { + std::tr1::shared_ptr<boost::any> t_; + + public: + AutoConverter(std::tr1::shared_ptr<boost::any> const & t) + : t_(t) + {} + + template <typename C> + operator C () + { + try + { + boost::any & a = (*t_); + + return boost::any_cast<C>(a); + } + catch(boost::bad_any_cast & e) + { + std::cerr << "Internal conversion bug: " + << "Failed to convert data holder to " + << typeid(C).name() << "\n" + << e.what() + << std::endl; + + C c = C(); + return c; + } + } + }; + + + inline AutoConverter Demo() + { + std::tr1::shared_ptr<boost::any> p_result + (new boost::any(std::tr1::make_tuple(1, 2, 3, 4))); + return p_result; + } + +} // namespace Core + + +int main() +{ + std::tr1::tuple<int, int, int, int> test = Core::Demo(); + return 0; +} + diff --git a/libs/fusion/test/sequence/transform_view.cpp b/libs/fusion/test/sequence/transform_view.cpp new file mode 100644 index 000000000..b9e3f9432 --- /dev/null +++ b/libs/fusion/test/sequence/transform_view.cpp @@ -0,0 +1,115 @@ +/*============================================================================= + Copyright (c) 2001-2011 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/view/transform_view/transform_view.hpp> +#include <boost/fusion/sequence/intrinsic/begin.hpp> +#include <boost/fusion/sequence/intrinsic/at.hpp> +#include <boost/fusion/sequence/intrinsic/value_at.hpp> +#include <boost/fusion/iterator/next.hpp> +#include <boost/fusion/iterator/prior.hpp> +#include <boost/fusion/iterator/advance.hpp> +#include <boost/fusion/iterator/deref.hpp> +#include <boost/fusion/iterator/distance.hpp> + +#include <boost/mpl/range_c.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/type_traits/is_same.hpp> + +struct square +{ + template<typename T> + 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 T> + 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; + } +}; + +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)); + BOOST_TEST((boost::fusion::at_c<2>(xform) == 49)); + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_at_c<xform_type, 0>::type, int>)); + } + + { + 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))); + BOOST_TEST((boost::fusion::at_c<2>(xform) == 19)); + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_at_c<xform_type, 0>::type, int>)); + } + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/tree.hpp b/libs/fusion/test/sequence/tree.hpp new file mode 100644 index 000000000..a345a8f1d --- /dev/null +++ b/libs/fusion/test/sequence/tree.hpp @@ -0,0 +1,100 @@ +/*============================================================================= + Copyright (c) 2006 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) +==============================================================================*/ +#ifndef FUSION_BINARY_TREE_EAN_05032006_1027 +#define FUSION_BINARY_TREE_EAN_05032006_1027 + +#include <boost/mpl/if.hpp> +#include <boost/type_traits/is_const.hpp> +#include <boost/type_traits/add_const.hpp> +#include <boost/type_traits/add_reference.hpp> +#include <boost/fusion/support/is_sequence.hpp> +#include <boost/fusion/sequence/intrinsic/at.hpp> +#include <boost/fusion/view/single_view.hpp> +#include <boost/fusion/container/list/cons.hpp> // for nil +#include <boost/fusion/container/vector/vector10.hpp> +#include <boost/fusion/support/sequence_base.hpp> +#include <boost/fusion/support/category_of.hpp> +#include <boost/fusion/support/is_segmented.hpp> +#include <boost/fusion/sequence/intrinsic/segments.hpp> + +namespace boost { namespace fusion +{ + struct tree_tag; + + template <typename Data, typename Left = nil, typename Right = nil> + struct tree + : sequence_base<tree<Data, Left, Right> > + { + typedef Data data_type; + typedef Left left_type; + typedef Right right_type; + typedef tree_tag fusion_tag; + typedef forward_traversal_tag category; + typedef mpl::false_ is_view; + + typedef typename mpl::if_< + traits::is_sequence<Data> + , Data + , single_view<Data> + >::type data_view; + + explicit tree( + typename fusion::detail::call_param<Data>::type data_ + , typename fusion::detail::call_param<Left>::type left_ = Left() + , typename fusion::detail::call_param<Right>::type right_ = Right() + ) + : segments(left_, data_view(data_), right_) + {} + + typedef vector3<Left, data_view, Right> segments_type; + segments_type segments; + }; + + template <typename Data> + tree<Data> make_tree(Data const &data) + { + return tree<Data>(data); + } + + template <typename Data, typename Left, typename Right> + tree<Data, Left, Right> make_tree(Data const &data, Left const &left, Right const &right) + { + return tree<Data, Left, Right>(data, left, right); + } + + namespace extension + { + template <> + struct is_segmented_impl<tree_tag> + { + template <typename Sequence> + struct apply : mpl::true_ {}; + }; + + template <> + struct segments_impl<tree_tag> + { + template <typename Sequence> + struct apply + { + typedef typename mpl::if_< + is_const<Sequence> + , typename Sequence::segments_type const & + , typename Sequence::segments_type & + >::type type; + + static type call(Sequence &seq) + { + return seq.segments; + } + }; + }; + } +}} + +#endif diff --git a/libs/fusion/test/sequence/tuple_comparison.cpp b/libs/fusion/test/sequence/tuple_comparison.cpp new file mode 100644 index 000000000..2b4433068 --- /dev/null +++ b/libs/fusion/test/sequence/tuple_comparison.cpp @@ -0,0 +1,20 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/tuple/tuple.hpp> +#include <boost/fusion/adapted/mpl.hpp> + +#define FUSION_SEQUENCE tuple +#include "comparison.hpp" + +int +main() +{ + equality_test(); + ordering_test(); + return boost::report_errors(); +} diff --git a/libs/fusion/test/sequence/tuple_construction.cpp b/libs/fusion/test/sequence/tuple_construction.cpp new file mode 100644 index 000000000..044701c40 --- /dev/null +++ b/libs/fusion/test/sequence/tuple_construction.cpp @@ -0,0 +1,21 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/tuple/tuple.hpp> +#include <boost/fusion/adapted/mpl.hpp> + +#define NO_CONSTRUCT_FROM_NIL +#define FUSION_SEQUENCE tuple +#define FUSION_AT get +#include "construction.hpp" + +int +main() +{ + test(); + return boost::report_errors(); +} diff --git a/libs/fusion/test/sequence/tuple_copy.cpp b/libs/fusion/test/sequence/tuple_copy.cpp new file mode 100644 index 000000000..c41117e7a --- /dev/null +++ b/libs/fusion/test/sequence/tuple_copy.cpp @@ -0,0 +1,22 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/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(); +} + diff --git a/libs/fusion/test/sequence/tuple_element.cpp b/libs/fusion/test/sequence/tuple_element.cpp new file mode 100644 index 000000000..0932e627e --- /dev/null +++ b/libs/fusion/test/sequence/tuple_element.cpp @@ -0,0 +1,21 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/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(); +} + diff --git a/libs/fusion/test/sequence/tuple_make.cpp b/libs/fusion/test/sequence/tuple_make.cpp new file mode 100644 index 000000000..806a7f290 --- /dev/null +++ b/libs/fusion/test/sequence/tuple_make.cpp @@ -0,0 +1,21 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/tuple.hpp> + +#define FUSION_SEQUENCE boost::fusion::tuple +#define FUSION_AT get +#define FUSION_MAKE boost::fusion::make_tuple +#include "make.hpp" + +int +main() +{ + test(); + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/tuple_misc.cpp b/libs/fusion/test/sequence/tuple_misc.cpp new file mode 100644 index 000000000..473efb61c --- /dev/null +++ b/libs/fusion/test/sequence/tuple_misc.cpp @@ -0,0 +1,23 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/tuple.hpp> +#include <boost/fusion/container/vector/convert.hpp> +#include <boost/fusion/adapted/mpl.hpp> + +#define FUSION_SEQUENCE tuple +#define FUSION_AT get +#define FUSION_SIZE tuple_size +#include "misc.hpp" + +int +main() +{ + test(); + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/tuple_mutate.cpp b/libs/fusion/test/sequence/tuple_mutate.cpp new file mode 100644 index 000000000..b6e72a610 --- /dev/null +++ b/libs/fusion/test/sequence/tuple_mutate.cpp @@ -0,0 +1,20 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/tuple.hpp> + +#define FUSION_SEQUENCE tuple +#define FUSION_AT get +#include "mutate.hpp" + +int +main() +{ + test(); + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/tuple_tie.cpp b/libs/fusion/test/sequence/tuple_tie.cpp new file mode 100644 index 000000000..2d5ec24f6 --- /dev/null +++ b/libs/fusion/test/sequence/tuple_tie.cpp @@ -0,0 +1,22 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/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(); +} + diff --git a/libs/fusion/test/sequence/value_at.hpp b/libs/fusion/test/sequence/value_at.hpp new file mode 100644 index 000000000..9fe3a1982 --- /dev/null +++ b/libs/fusion/test/sequence/value_at.hpp @@ -0,0 +1,87 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/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) boost::fusion::result_of::value_at_c<S, N> +#endif + +namespace test_detail +{ + // something to prevent warnings for unused variables + template<class T> void dummy(const T&) {} + + class A {}; +} + +void +test() +{ + using namespace boost::fusion; + using namespace test_detail; + + 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 +} diff --git a/libs/fusion/test/sequence/vector_comparison.cpp b/libs/fusion/test/sequence/vector_comparison.cpp new file mode 100644 index 000000000..c23db8336 --- /dev/null +++ b/libs/fusion/test/sequence/vector_comparison.cpp @@ -0,0 +1,19 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/container/vector/vector.hpp> + +#define FUSION_SEQUENCE vector +#include "comparison.hpp" + +int +main() +{ + equality_test(); + ordering_test(); + return boost::report_errors(); +} diff --git a/libs/fusion/test/sequence/vector_construction.cpp b/libs/fusion/test/sequence/vector_construction.cpp new file mode 100644 index 000000000..8af5bc042 --- /dev/null +++ b/libs/fusion/test/sequence/vector_construction.cpp @@ -0,0 +1,18 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/container/vector/vector.hpp> + +#define FUSION_SEQUENCE vector +#include "construction.hpp" + +int +main() +{ + test(); + return boost::report_errors(); +} diff --git a/libs/fusion/test/sequence/vector_copy.cpp b/libs/fusion/test/sequence/vector_copy.cpp new file mode 100644 index 000000000..d21f5c9cb --- /dev/null +++ b/libs/fusion/test/sequence/vector_copy.cpp @@ -0,0 +1,21 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/container/vector/vector.hpp> +#include <boost/fusion/container/generation/make_vector.hpp> +#include <boost/fusion/container/generation/vector_tie.hpp> + +#define FUSION_SEQUENCE vector +#include "copy.hpp" + +int +main() +{ + test(); + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/vector_iterator.cpp b/libs/fusion/test/sequence/vector_iterator.cpp new file mode 100644 index 000000000..4d4b6b39a --- /dev/null +++ b/libs/fusion/test/sequence/vector_iterator.cpp @@ -0,0 +1,22 @@ +/*============================================================================= + Copyright (c) 2001-2011 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/fusion/container/vector/vector.hpp> +#include <boost/fusion/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(); +} + + + diff --git a/libs/fusion/test/sequence/vector_make.cpp b/libs/fusion/test/sequence/vector_make.cpp new file mode 100644 index 000000000..8a687354a --- /dev/null +++ b/libs/fusion/test/sequence/vector_make.cpp @@ -0,0 +1,20 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/container/vector/vector.hpp> +#include <boost/fusion/container/generation/make_vector.hpp> + +#define FUSION_SEQUENCE vector +#include "make.hpp" + +int +main() +{ + test(); + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/vector_misc.cpp b/libs/fusion/test/sequence/vector_misc.cpp new file mode 100644 index 000000000..e2b273967 --- /dev/null +++ b/libs/fusion/test/sequence/vector_misc.cpp @@ -0,0 +1,21 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/container/vector/vector.hpp> +#include <boost/fusion/container/vector/convert.hpp> +#include <boost/fusion/adapted/mpl.hpp> + +#define FUSION_SEQUENCE vector +#include "misc.hpp" + +int +main() +{ + test(); + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/vector_move.cpp b/libs/fusion/test/sequence/vector_move.cpp new file mode 100644 index 000000000..70483f06a --- /dev/null +++ b/libs/fusion/test/sequence/vector_move.cpp @@ -0,0 +1,31 @@ +/*============================================================================= + Copyright (c) 2012 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) +==============================================================================*/ +#define BOOST_FUSION_DONT_USE_PREPROCESSED_FILES // $$$ JDG temp $$$ + +#include <boost/config.hpp> + +#if !defined(BOOST_NO_RVALUE_REFERENCES) + +#include <boost/fusion/container/vector/vector.hpp> + +#define FUSION_SEQUENCE boost::fusion::vector +#include "move.hpp" + +#else +#include <boost/detail/lightweight_test.hpp> +#endif + +int +main() +{ +#if !defined(BOOST_NO_RVALUE_REFERENCES) + test(); +#endif + + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/vector_mutate.cpp b/libs/fusion/test/sequence/vector_mutate.cpp new file mode 100644 index 000000000..448bbf768 --- /dev/null +++ b/libs/fusion/test/sequence/vector_mutate.cpp @@ -0,0 +1,19 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/container/vector/vector.hpp> + +#define FUSION_SEQUENCE vector +#include "mutate.hpp" + +int +main() +{ + test(); + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/vector_n.cpp b/libs/fusion/test/sequence/vector_n.cpp new file mode 100644 index 000000000..05c07ce45 --- /dev/null +++ b/libs/fusion/test/sequence/vector_n.cpp @@ -0,0 +1,231 @@ +/*============================================================================= + Copyright (c) 2001-2011 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/vector10.hpp> +#include <boost/fusion/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/container/vector/vector20.hpp> +#include <boost/fusion/container/vector/vector30.hpp> +#include <boost/fusion/container/vector/vector40.hpp> +#include <boost/fusion/container/vector/vector50.hpp> + +#include <boost/type_traits/is_same.hpp> +#include <boost/type_traits/is_empty.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; + + { + vector0<> vec; + (void) vec; + std::cout << "(): " << sizeof(vec) << std::endl; + std::cout << (boost::is_empty<vector0<> >::value ? "is empty" : "is not empty") << std::endl; + } + + { + typedef vector1<int> type; + type vec; + BOOST_STATIC_ASSERT(boost::fusion::result_of::size<type>::value == 1); + + BOOST_TEST(at_c<0>(vec) == 0); + BOOST_STATIC_ASSERT((boost::is_same<int, boost::fusion::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); + std::cout << "(int): " << sizeof(vec) << std::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(boost::fusion::result_of::size<type>::value == 2); + + BOOST_TEST(at_c<0>(vec) == 0); + BOOST_TEST(at_c<1>(vec) == char()); + + BOOST_STATIC_ASSERT((boost::is_same<int, boost::fusion::result_of::value_at_c<type, 0>::type>::value)); + BOOST_STATIC_ASSERT((boost::is_same<char, boost::fusion::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'); + std::cout << "(int, char): " << sizeof(vec) << std::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(boost::fusion::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((boost::is_same<int, boost::fusion::result_of::value_at_c<type, 0>::type>::value)); + BOOST_STATIC_ASSERT((boost::is_same<char, boost::fusion::result_of::value_at_c<type, 1>::type>::value)); + BOOST_STATIC_ASSERT((boost::is_same<double, boost::fusion::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); + std::cout << "(int, char, double): " << sizeof(vec) << std::endl; + } + + { + typedef vector4<int, char, double, bool> type; + type vec(123, 'x', 123.456, true); + std::cout << "(int, char, double, bool): " << sizeof(vec) << std::endl; + } + + { + typedef vector4<int, char, bool, double> type; + type vec(123, 'x', true, 123.456); + std::cout << "(int, char, bool, double): " << sizeof(vec) << std::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((boost::is_same<bool, boost::fusion::result_of::value_at_c<type, 0>::type>::value)); + BOOST_STATIC_ASSERT((boost::is_same<char, boost::fusion::result_of::value_at_c<type, 1>::type>::value)); + BOOST_STATIC_ASSERT((boost::is_same<short, boost::fusion::result_of::value_at_c<type, 2>::type>::value)); + BOOST_STATIC_ASSERT((boost::is_same<int, boost::fusion::result_of::value_at_c<type, 3>::type>::value)); + BOOST_STATIC_ASSERT((boost::is_same<long, boost::fusion::result_of::value_at_c<type, 4>::type>::value)); + BOOST_STATIC_ASSERT((boost::is_same<float, boost::fusion::result_of::value_at_c<type, 5>::type>::value)); + BOOST_STATIC_ASSERT((boost::is_same<double, boost::fusion::result_of::value_at_c<type, 6>::type>::value)); + std::cout << "(bool, char, short, int, long, float, double): " << sizeof(vec) << std::endl; + } + + { + typedef vector10<int, int, int, int, int, int, int, int, int, int> type; + type vec; // compile check only + std::cout << "vector10 of int: " << sizeof(vec) << std::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 + std::cout << "vector20 of int: " << sizeof(vec) << std::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 + std::cout << "vector30 of int: " << sizeof(vec) << std::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 + std::cout << "vector40 of int: " << sizeof(vec) << std::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 + std::cout << "vector50 of int: " << sizeof(vec) << std::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(); +} + diff --git a/libs/fusion/test/sequence/vector_tie.cpp b/libs/fusion/test/sequence/vector_tie.cpp new file mode 100644 index 000000000..123bf888e --- /dev/null +++ b/libs/fusion/test/sequence/vector_tie.cpp @@ -0,0 +1,22 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/container/vector/vector.hpp> +#include <boost/fusion/container/generation/vector_tie.hpp> +#include <boost/fusion/container/generation/ignore.hpp> +#include <boost/fusion/container/generation/make_vector.hpp> + +#define FUSION_SEQUENCE vector +#include "tie.hpp" + +int +main() +{ + test(); + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/vector_value_at.cpp b/libs/fusion/test/sequence/vector_value_at.cpp new file mode 100644 index 000000000..191da4cf7 --- /dev/null +++ b/libs/fusion/test/sequence/vector_value_at.cpp @@ -0,0 +1,19 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 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/fusion/container/vector/vector.hpp> + +#define FUSION_SEQUENCE vector +#include "value_at.hpp" + +int +main() +{ + test(); + return boost::report_errors(); +} + diff --git a/libs/fusion/test/sequence/zip_view.cpp b/libs/fusion/test/sequence/zip_view.cpp new file mode 100644 index 000000000..83bfa8798 --- /dev/null +++ b/libs/fusion/test/sequence/zip_view.cpp @@ -0,0 +1,87 @@ +/*============================================================================= + Copyright (c) 2001-2011 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/support/category_of.hpp> +#include <boost/fusion/view/zip_view.hpp> +#include <boost/fusion/container/vector.hpp> +#include <boost/fusion/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/container/generation/make_vector.hpp> +#include <boost/fusion/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, vector2<int,char> >)); + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_of<boost::fusion::result_of::begin<view>::type>::type, vector2<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(); +} + diff --git a/libs/fusion/test/sequence/zip_view2.cpp b/libs/fusion/test/sequence/zip_view2.cpp new file mode 100644 index 000000000..b63a27446 --- /dev/null +++ b/libs/fusion/test/sequence/zip_view2.cpp @@ -0,0 +1,64 @@ +/*============================================================================= + Copyright (c) 2001-2011 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/detail/lightweight_test.hpp> +#include <boost/fusion/support/category_of.hpp> +#include <boost/fusion/view/zip_view.hpp> +#include <boost/fusion/container/vector.hpp> +#include <boost/fusion/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/container/generation/make_vector.hpp> +#include <boost/fusion/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, vector3<int,char,char> >)); + BOOST_MPL_ASSERT((boost::is_same<boost::fusion::result_of::value_of<boost::fusion::result_of::begin<view>::type>::type, vector3<int,char,char> >)); + } + return boost::report_errors(); +} diff --git a/libs/fusion/test/sequence/zip_view_ignore.cpp b/libs/fusion/test/sequence/zip_view_ignore.cpp new file mode 100644 index 000000000..d22bf70ff --- /dev/null +++ b/libs/fusion/test/sequence/zip_view_ignore.cpp @@ -0,0 +1,58 @@ +/*============================================================================= + 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/view/zip_view.hpp> +#include <boost/fusion/support/unused.hpp> +#include <boost/fusion/iterator.hpp> +#include <boost/fusion/sequence/intrinsic.hpp> + +#include <boost/mpl/assert.hpp> +#include <boost/type_traits/is_same.hpp> + +int main() +{ + using namespace boost::fusion; + { + typedef vector2<int,int> int_vector; + typedef vector2<char,char> char_vector; + typedef vector<int_vector&, unused_type const&, char_vector&> seqs_type; + typedef zip_view<seqs_type> view; + + int_vector iv(1,2); + char_vector cv('a','b'); + seqs_type seq(iv, unused, cv); + view v(seq); + + BOOST_TEST(at_c<0>(front(v)) == 1); + BOOST_TEST(at_c<2>(front(v)) == 'a'); + BOOST_TEST(at_c<0>(back(v)) == 2); + BOOST_TEST(at_c<2>(back(v)) == 'b'); + + typedef boost::fusion::result_of::begin<view>::type first_iterator; + typedef boost::fusion::result_of::value_of<first_iterator>::type first_element; + + typedef boost::fusion::result_of::at_c<first_element, 0>::type e0; + typedef boost::fusion::result_of::at_c<first_element, 2>::type e2; + BOOST_MPL_ASSERT((boost::is_same<e0, int&>)); + BOOST_MPL_ASSERT((boost::is_same<e2, char&>)); + + BOOST_TEST(size(front(v)) == 3); + + typedef boost::fusion::result_of::value_at_c<view, 0>::type first_value_at; + typedef boost::fusion::result_of::value_at_c<first_value_at, 0>::type v0; + typedef boost::fusion::result_of::value_at_c<first_value_at, 2>::type v2; + + BOOST_MPL_ASSERT((boost::is_same<v0, int>)); + BOOST_MPL_ASSERT((boost::is_same<v2, char>)); + + BOOST_TEST(at_c<0>(at_c<0>(v)) == 1); + BOOST_TEST(at_c<2>(at_c<0>(v)) == 'a'); + } + return boost::report_errors(); +} |