mirror of
https://github.com/boostorg/fusion.git
synced 2025-07-29 20:17:32 +02:00
Merge remote-tracking branch 'official/develop' into fusion_adapters
Conflicts: test/sequence/adapt_struct.cpp
This commit is contained in:
14
test/Jamfile
14
test/Jamfile
@ -28,11 +28,11 @@ project
|
||||
[ 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/move.cpp : : : : ]
|
||||
[ run algorithm/none.cpp : : : : ]
|
||||
[ run algorithm/pop_back.cpp : : : : ]
|
||||
[ run algorithm/pop_front.cpp : : : : ]
|
||||
@ -56,11 +56,13 @@ project
|
||||
[ run algorithm/zip_ignore.cpp : : : : ]
|
||||
[ run algorithm/flatten.cpp : : : : ]
|
||||
|
||||
[ run sequence/as_deque.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/boost_tuple_iterator.cpp : : : : ]
|
||||
[ run sequence/cons.cpp : : : : ]
|
||||
[ run sequence/filter_view.cpp : : : : ]
|
||||
[ run sequence/hash.cpp : : : : ]
|
||||
@ -100,6 +102,7 @@ project
|
||||
[ run sequence/map_move.cpp : : : : ]
|
||||
[ run sequence/map_mutate.cpp : : : : ]
|
||||
[ run sequence/map_tie.cpp : : : : ]
|
||||
[ run sequence/nil.cpp : : : : ]
|
||||
[ run sequence/nview.cpp : : : : ]
|
||||
[ run sequence/reverse_view.cpp : : : : ]
|
||||
[ run sequence/segmented_iterator_range.cpp : : : : ]
|
||||
@ -155,11 +158,12 @@ project
|
||||
[ run sequence/define_tpl_struct_inline.cpp : : : : ]
|
||||
[ run sequence/define_assoc_tpl_struct.cpp : : : : ]
|
||||
[ run sequence/std_tuple.cpp : : : : ]
|
||||
[ run sequence/std_tuple_auto_conv.cpp : : : : ]
|
||||
[ run sequence/std_tuple_iterator.cpp : : : : ]
|
||||
[ run sequence/ref_vector.cpp : : : : ]
|
||||
[ run sequence/flatten_view.cpp : : : : ]
|
||||
|
||||
[ compile sequence/size.cpp : : : : ]
|
||||
|
||||
[ run functional/fused.cpp : : : : ]
|
||||
[ run functional/fused_function_object.cpp : : : : ]
|
||||
[ run functional/fused_procedure.cpp : : : : ]
|
||||
@ -174,6 +178,12 @@ project
|
||||
[ run functional/invoke_procedure.cpp : : : : ]
|
||||
[ run sequence/swap.cpp : : : : ]
|
||||
|
||||
[ compile support/pair_deque.cpp : : : : ]
|
||||
[ compile support/pair_list.cpp : : : : ]
|
||||
[ compile support/pair_map.cpp : : : : ]
|
||||
[ compile support/pair_set.cpp : : : : ]
|
||||
[ compile support/pair_vector.cpp : : : : ]
|
||||
|
||||
# [ compile-fail xxx.cpp : : : : ]
|
||||
|
||||
;
|
||||
|
@ -2,7 +2,7 @@
|
||||
Copyright (c) 2001-2011 Joel de Guzman
|
||||
Copyright (c) 2007 Dan Marsden
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
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>
|
||||
@ -120,6 +120,26 @@ int add(int lhs, int rhs)
|
||||
return lhs + rhs;
|
||||
}
|
||||
|
||||
struct functor
|
||||
{
|
||||
template<typename T>
|
||||
int
|
||||
operator() (int hitherho, T const& cur) const
|
||||
{
|
||||
return int(hitherho + cur);
|
||||
}
|
||||
};
|
||||
|
||||
struct visitor
|
||||
{
|
||||
typedef int result_type;
|
||||
|
||||
int operator()(int sum, long&)
|
||||
{
|
||||
return sum;
|
||||
}
|
||||
};
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
@ -217,6 +237,21 @@ main()
|
||||
BOOST_TEST(fusion::accumulate(vec, 0, add) == 3);
|
||||
}
|
||||
|
||||
{
|
||||
#if !defined(BOOST_FUSION_NO_DECLTYPE_BASED_RESULT_OF)
|
||||
{
|
||||
boost::fusion::vector<int, double, long> container{1, 2, 3};
|
||||
functor f;
|
||||
boost::fusion::fold(container, 0, f);
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
boost::fusion::vector<long> vec;
|
||||
visitor v;
|
||||
boost::fusion::fold(vec, 0, v);
|
||||
}
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
|
40
test/algorithm/move.cpp
Normal file
40
test/algorithm/move.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2014 Kohei Takahashi
|
||||
|
||||
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_CXX11_RVALUE_REFERENCES)
|
||||
|
||||
#include <boost/core/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/move.hpp>
|
||||
#include <utility>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::fusion::vector<int, short, double> v(1, 2, 3);
|
||||
boost::fusion::list<int, short, double> l1 = v;
|
||||
boost::fusion::list<int, short, double> l2;
|
||||
|
||||
boost::fusion::move(std::move(v), l2);
|
||||
BOOST_TEST(l1 == l2);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
// no thing to do
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -10,18 +10,18 @@
|
||||
#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>
|
||||
#include <boost/mpl/empty_base.hpp>
|
||||
|
||||
namespace fusion = boost::fusion;
|
||||
using boost::noncopyable;
|
||||
|
||||
template <class Base = boost::blank>
|
||||
template <class Base = boost::mpl::empty_base>
|
||||
struct test_func
|
||||
: Base
|
||||
{
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/blank.hpp>
|
||||
#include <boost/mpl/empty_base.hpp>
|
||||
|
||||
#include <boost/fusion/container/generation/make_vector.hpp>
|
||||
#include <boost/fusion/container/vector.hpp>
|
||||
@ -18,7 +18,7 @@
|
||||
namespace fusion = boost::fusion;
|
||||
using boost::noncopyable;
|
||||
|
||||
template <class Base = boost::blank>
|
||||
template <class Base = boost::mpl::empty_base>
|
||||
struct test_func
|
||||
: Base
|
||||
{
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/blank.hpp>
|
||||
#include <boost/mpl/empty_base.hpp>
|
||||
|
||||
#include <boost/fusion/container/generation/make_vector.hpp>
|
||||
#include <boost/fusion/container/vector.hpp>
|
||||
@ -26,7 +26,7 @@ int effect;
|
||||
BOOST_TEST(effect == e); \
|
||||
}
|
||||
|
||||
template <class Base = boost::blank>
|
||||
template <class Base = boost::mpl::empty_base>
|
||||
struct test_func
|
||||
: Base
|
||||
{
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/blank.hpp>
|
||||
#include <boost/mpl/empty_base.hpp>
|
||||
|
||||
#include <boost/fusion/container/generation/make_vector.hpp>
|
||||
#include <boost/fusion/container/vector.hpp>
|
||||
@ -20,7 +20,7 @@ using boost::noncopyable;
|
||||
using boost::cref;
|
||||
using boost::ref;
|
||||
|
||||
template <class Base = boost::blank>
|
||||
template <class Base = boost::mpl::empty_base>
|
||||
struct test_func
|
||||
: Base
|
||||
{
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/blank.hpp>
|
||||
#include <boost/mpl/empty_base.hpp>
|
||||
|
||||
#include <boost/fusion/container/generation/make_vector.hpp>
|
||||
#include <boost/fusion/container/vector.hpp>
|
||||
@ -20,7 +20,7 @@ using boost::noncopyable;
|
||||
using boost::cref;
|
||||
using boost::ref;
|
||||
|
||||
template <class Base = boost::blank>
|
||||
template <class Base = boost::mpl::empty_base>
|
||||
struct test_func
|
||||
: Base
|
||||
{
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/blank.hpp>
|
||||
#include <boost/mpl/empty_base.hpp>
|
||||
|
||||
#include <boost/fusion/container/generation/make_vector.hpp>
|
||||
#include <boost/fusion/container/vector.hpp>
|
||||
@ -28,7 +28,7 @@ int effect;
|
||||
BOOST_TEST(effect == e); \
|
||||
}
|
||||
|
||||
template <class Base = boost::blank>
|
||||
template <class Base = boost::mpl::empty_base>
|
||||
struct test_func
|
||||
: Base
|
||||
{
|
||||
|
@ -10,14 +10,15 @@
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/blank.hpp>
|
||||
|
||||
#include <boost/mpl/empty_base.hpp>
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/mpl/and.hpp>
|
||||
#include <boost/mpl/not.hpp>
|
||||
#include <boost/mpl/bool.hpp>
|
||||
#include <boost/mpl/identity.hpp>
|
||||
|
||||
#include <boost/utility/result_of.hpp>
|
||||
#include <boost/core/enable_if.hpp>
|
||||
|
||||
#include <boost/fusion/sequence/intrinsic/empty.hpp>
|
||||
#include <boost/fusion/algorithm/iteration/fold.hpp>
|
||||
@ -33,17 +34,18 @@ typedef mpl::true_ no_nullary_call;
|
||||
using boost::ref;
|
||||
using boost::cref;
|
||||
|
||||
template <class Base = boost::blank, class RemoveNullary = mpl::false_>
|
||||
template <class Base = mpl::empty_base, class RemoveNullary = mpl::false_>
|
||||
struct test_func
|
||||
: Base
|
||||
{
|
||||
template <typename Sig>
|
||||
struct result;
|
||||
|
||||
template <class Self, class Seq>
|
||||
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
|
||||
: boost::enable_if<
|
||||
mpl::not_<mpl::and_<boost::fusion::result_of::empty<Seq>, RemoveNullary> >,
|
||||
long>
|
||||
{ };
|
||||
|
||||
template <typename Seq>
|
||||
|
@ -10,8 +10,8 @@
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/blank.hpp>
|
||||
|
||||
#include <boost/mpl/empty_base.hpp>
|
||||
#include <boost/mpl/identity.hpp>
|
||||
|
||||
#include <boost/utility/result_of.hpp>
|
||||
@ -24,7 +24,7 @@ namespace mpl = boost::mpl;
|
||||
|
||||
using boost::noncopyable;
|
||||
|
||||
template <class Base = boost::blank>
|
||||
template <class Base = boost::mpl::empty_base>
|
||||
struct test_func
|
||||
: Base
|
||||
{
|
||||
|
@ -9,11 +9,9 @@
|
||||
#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/empty_base.hpp>
|
||||
#include <boost/mpl/identity.hpp>
|
||||
#include <boost/mpl/placeholders.hpp>
|
||||
|
||||
@ -31,7 +29,7 @@ typedef fusion::vector<> types0;
|
||||
typedef fusion::vector<long &> types1;
|
||||
typedef fusion::vector<long &,int,char> types3;
|
||||
|
||||
template <class Base = boost::blank>
|
||||
template <class Base = boost::mpl::empty_base>
|
||||
struct test_func
|
||||
: Base
|
||||
{
|
||||
|
@ -56,6 +56,17 @@ namespace ns
|
||||
{}
|
||||
};
|
||||
#endif
|
||||
|
||||
struct foo
|
||||
{
|
||||
int x;
|
||||
};
|
||||
|
||||
struct bar
|
||||
{
|
||||
foo foo_;
|
||||
int y;
|
||||
};
|
||||
}
|
||||
|
||||
#if BOOST_PP_VARIADICS
|
||||
@ -79,6 +90,12 @@ namespace ns
|
||||
struct s { int m; };
|
||||
BOOST_FUSION_ADAPT_STRUCT(s, m)
|
||||
|
||||
BOOST_FUSION_ADAPT_STRUCT(
|
||||
ns::bar,
|
||||
foo_.x, // test that adapted members can actually be expressions
|
||||
y
|
||||
)
|
||||
|
||||
#else // BOOST_PP_VARIADICS
|
||||
|
||||
BOOST_FUSION_ADAPT_STRUCT(
|
||||
@ -100,6 +117,12 @@ namespace ns
|
||||
struct s { int m; };
|
||||
BOOST_FUSION_ADAPT_STRUCT(s, (BOOST_FUSION_ADAPT_AUTO, m))
|
||||
|
||||
BOOST_FUSION_ADAPT_STRUCT(
|
||||
ns::bar,
|
||||
(BOOST_FUSION_ADAPT_AUTO, foo_.x) // test that adapted members can actually be expressions
|
||||
(BOOST_FUSION_ADAPT_AUTO, y)
|
||||
)
|
||||
|
||||
#endif
|
||||
|
||||
int
|
||||
@ -192,6 +215,15 @@ main()
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
fusion::vector<int, float> v1(4, 2);
|
||||
ns::bar v2 = {5, 3};
|
||||
BOOST_TEST(v1 < v2);
|
||||
BOOST_TEST(v1 <= v2);
|
||||
BOOST_TEST(v2 > v1);
|
||||
BOOST_TEST(v2 >= v1);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
|
70
test/sequence/as_deque.cpp
Normal file
70
test/sequence/as_deque.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2014 Louis Dionne
|
||||
|
||||
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/push_back.hpp>
|
||||
#include <boost/fusion/algorithm/transformation/push_front.hpp>
|
||||
#include <boost/fusion/container/deque/convert.hpp>
|
||||
#include <boost/fusion/container/deque/deque.hpp>
|
||||
#include <boost/fusion/container/generation/make_deque.hpp>
|
||||
#include <boost/fusion/container/generation/make_list.hpp>
|
||||
#include <boost/fusion/container/generation/make_vector.hpp>
|
||||
#include <boost/fusion/sequence/comparison/equal_to.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
int main() {
|
||||
using namespace boost::fusion;
|
||||
using namespace boost;
|
||||
|
||||
BOOST_TEST(as_deque(make_vector()) == make_deque());
|
||||
BOOST_TEST(as_deque(make_vector(1)) == make_deque(1));
|
||||
BOOST_TEST(as_deque(make_vector(1, '2')) == make_deque(1, '2'));
|
||||
BOOST_TEST(as_deque(make_vector(1, '2', 3.3f)) == make_deque(1, '2', 3.3f));
|
||||
|
||||
BOOST_TEST(as_deque(make_list()) == make_deque());
|
||||
BOOST_TEST(as_deque(make_list(1)) == make_deque(1));
|
||||
BOOST_TEST(as_deque(make_list(1, '2')) == make_deque(1, '2'));
|
||||
BOOST_TEST(as_deque(make_list(1, '2', 3.3f)) == make_deque(1, '2', 3.3f));
|
||||
|
||||
{
|
||||
deque<> xs;
|
||||
BOOST_TEST(as_deque(push_back(xs, 1)) == make_deque(1));
|
||||
}
|
||||
|
||||
{
|
||||
deque<int> xs(1);
|
||||
BOOST_TEST(as_deque(push_back(xs, '2')) == make_deque(1, '2'));
|
||||
}
|
||||
|
||||
{
|
||||
deque<int, char> xs(1, '2');
|
||||
BOOST_TEST(as_deque(push_back(xs, 3.3f)) == make_deque(1, '2', 3.3f));
|
||||
}
|
||||
|
||||
{
|
||||
deque<> xs;
|
||||
BOOST_TEST(
|
||||
as_deque(push_front(xs, make_deque(1, '2', 3.3f))) ==
|
||||
make_deque(make_deque(1, '2', 3.3f))
|
||||
);
|
||||
|
||||
BOOST_TEST(as_deque(make_deque(make_deque(1))) == make_deque(make_deque(1)));
|
||||
}
|
||||
|
||||
/* Disabling test for now, see https://github.com/boostorg/fusion/pull/38 ($$$ FIXME $$$)
|
||||
|
||||
{
|
||||
deque<> xs;
|
||||
BOOST_TEST(
|
||||
as_deque(push_front(xs, make_vector(1, '2', 3.3f))) ==
|
||||
make_deque(make_vector(1, '2', 3.3f))
|
||||
);
|
||||
}
|
||||
*/
|
||||
return boost::report_errors();
|
||||
}
|
@ -23,6 +23,45 @@
|
||||
int main()
|
||||
{
|
||||
using namespace boost::fusion;
|
||||
{
|
||||
typedef deque<> initial_deque_type;
|
||||
initial_deque_type initial_deque;
|
||||
typedef back_extended_deque<initial_deque_type, long> extended_type;
|
||||
extended_type extended(initial_deque, 101L);
|
||||
|
||||
BOOST_TEST(size(extended) == 1);
|
||||
BOOST_TEST(extended == make_vector(101L));
|
||||
BOOST_TEST(*begin(extended) == 101L);
|
||||
BOOST_TEST(*prior(end(extended)) == 101L);
|
||||
BOOST_TEST(distance(begin(extended), end(extended)) == 1);
|
||||
}
|
||||
{
|
||||
namespace mpl = boost::mpl;
|
||||
typedef deque<> 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, long>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<mpl::deref<mpl::begin<extended_type>::type>::type, long>));
|
||||
BOOST_MPL_ASSERT((mpl::equal_to<mpl::size<extended_type>::type, mpl::int_<1> >));
|
||||
}
|
||||
{
|
||||
long l(101L);
|
||||
typedef deque<> initial_deque_type;
|
||||
initial_deque_type initial_deque;
|
||||
typedef back_extended_deque<initial_deque_type, long&> extended_type;
|
||||
extended_type extended(initial_deque, l);
|
||||
BOOST_TEST(extended == make_vector(101L));
|
||||
|
||||
long l2(202L);
|
||||
extended_type extended2(initial_deque_type(), l2);
|
||||
|
||||
extended = extended2;
|
||||
|
||||
BOOST_TEST(extended == make_vector(202L));
|
||||
|
||||
BOOST_TEST(l == l2);
|
||||
}
|
||||
|
||||
{
|
||||
typedef deque<int, char> initial_deque_type;
|
||||
initial_deque_type initial_deque(1, 'a');
|
||||
|
21
test/sequence/boost_tuple_iterator.cpp
Normal file
21
test/sequence/boost_tuple_iterator.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2014 Kohei Takahashi
|
||||
|
||||
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/adapted/boost_tuple.hpp>
|
||||
|
||||
#define FUSION_SEQUENCE boost::tuple
|
||||
#define FUSION_TRAVERSAL_TAG forward_traversal_tag
|
||||
#define FUSION_NO_PRIOR
|
||||
#include "./iterator.hpp"
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
test();
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <boost/lambda/lambda.hpp>
|
||||
#include <boost/fusion/algorithm/iteration/for_each.hpp>
|
||||
#include <boost/fusion/algorithm/transformation/filter_if.hpp>
|
||||
#include <boost/fusion/algorithm/transformation/push_front.hpp>
|
||||
#include <boost/fusion/sequence/io/out.hpp>
|
||||
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
@ -83,6 +84,12 @@ main()
|
||||
BOOST_TEST((*begin(tie) == 3));
|
||||
}
|
||||
|
||||
{
|
||||
// This used to trigger a hard compilation error:
|
||||
cons<cons<int> > xs;
|
||||
begin(push_front(xs, 3));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2010, 2012 Christopher Schmidt, Nathan Ridge
|
||||
|
||||
Distributed under the Boost Software Liceclse, Version 1.0. (See accompanying
|
||||
file LICEclsE_1_0.txt or copy at http://www.boost.org/LICEclsE_1_0.txt)
|
||||
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>
|
||||
|
@ -23,6 +23,45 @@
|
||||
int main()
|
||||
{
|
||||
using namespace boost::fusion;
|
||||
{
|
||||
typedef deque<> initial_deque_type;
|
||||
initial_deque_type initial_deque;
|
||||
typedef front_extended_deque<initial_deque_type, int> extended_type;
|
||||
extended_type extended(initial_deque, 1);
|
||||
|
||||
BOOST_TEST(size(extended) == 1);
|
||||
BOOST_TEST(extended == make_vector(1));
|
||||
BOOST_TEST(*begin(extended) == 1);
|
||||
BOOST_TEST(*prior(end(extended)) == 1);
|
||||
BOOST_TEST(distance(begin(extended), end(extended)) == 1);
|
||||
}
|
||||
{
|
||||
namespace mpl = boost::mpl;
|
||||
typedef deque<> 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::deref<mpl::begin<extended_type>::type>::type, int>));
|
||||
BOOST_MPL_ASSERT((mpl::equal_to<mpl::size<extended_type>::type, mpl::int_<1> >));
|
||||
}
|
||||
{
|
||||
int i(1);
|
||||
typedef deque<> initial_deque_type;
|
||||
initial_deque_type initial_deque;
|
||||
typedef front_extended_deque<initial_deque_type, int&> extended_type;
|
||||
extended_type extended(initial_deque, i);
|
||||
BOOST_TEST(extended == make_vector(1));
|
||||
|
||||
int i2(2);
|
||||
extended_type extended2(initial_deque_type(), i2);
|
||||
|
||||
extended = extended2;
|
||||
|
||||
BOOST_TEST(extended == make_vector(2));
|
||||
|
||||
BOOST_TEST(i == i2);
|
||||
}
|
||||
|
||||
{
|
||||
typedef deque<char, long> initial_deque_type;
|
||||
initial_deque_type initial_deque('a', 101L);
|
||||
|
@ -25,6 +25,19 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
|
||||
struct copy_all
|
||||
{
|
||||
copy_all() {}
|
||||
copy_all(copy_all const&) {}
|
||||
|
||||
template <typename T>
|
||||
copy_all(T const& x)
|
||||
{
|
||||
foo(x); // should fail!
|
||||
}
|
||||
};
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
@ -119,6 +132,31 @@ main()
|
||||
BOOST_TEST(at_key<char>(make_map<char, int>('X', 123)) == 'X');
|
||||
BOOST_TEST(at_key<int>(make_map<char, int>('X', 123)) == 123);
|
||||
}
|
||||
|
||||
{
|
||||
// test for copy construction of fusion pairs
|
||||
// make sure that the correct constructor is called
|
||||
pair<int, copy_all> p1;
|
||||
pair<int, copy_all> p2 = p1;
|
||||
}
|
||||
|
||||
{
|
||||
// compile test only
|
||||
// make sure result_of::deref_data returns a reference
|
||||
typedef map<pair<float, int> > map_type;
|
||||
typedef boost::fusion::result_of::begin<map_type>::type i_type;
|
||||
typedef boost::fusion::result_of::deref_data<i_type>::type r_type;
|
||||
BOOST_STATIC_ASSERT((boost::is_same<r_type, int&>::value));
|
||||
}
|
||||
|
||||
{
|
||||
// compile test only
|
||||
// make sure result_of::deref_data is const correct
|
||||
typedef map<pair<float, int> > const map_type;
|
||||
typedef boost::fusion::result_of::begin<map_type>::type i_type;
|
||||
typedef boost::fusion::result_of::deref_data<i_type>::type r_type;
|
||||
BOOST_STATIC_ASSERT((boost::is_same<r_type, int const&>::value));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <boost/mpl/equal.hpp>
|
||||
#include <boost/mpl/int.hpp>
|
||||
#include <boost/mpl/integral_c.hpp>
|
||||
#include <boost/mpl/is_sequence.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <string>
|
||||
|
||||
@ -148,6 +149,17 @@ test()
|
||||
BOOST_STATIC_ASSERT(!traits::is_sequence<char>::value);
|
||||
}
|
||||
|
||||
{ // testing mpl::is_sequence
|
||||
|
||||
typedef map<pair<k1, int>, pair<k2, float>, pair<k3, double> > t1;
|
||||
typedef map<> t2;
|
||||
typedef map<pair<k1, char> > t3;
|
||||
|
||||
BOOST_STATIC_ASSERT(boost::mpl::is_sequence<t1>::value);
|
||||
BOOST_STATIC_ASSERT(boost::mpl::is_sequence<t2>::value);
|
||||
BOOST_STATIC_ASSERT(boost::mpl::is_sequence<t3>::value);
|
||||
}
|
||||
|
||||
{ // testing mpl compatibility
|
||||
|
||||
// test an algorithm
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <boost/mpl/equal.hpp>
|
||||
#include <boost/mpl/int.hpp>
|
||||
#include <boost/mpl/integral_c.hpp>
|
||||
#include <boost/mpl/is_sequence.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <string>
|
||||
|
||||
@ -175,6 +176,17 @@ test()
|
||||
BOOST_STATIC_ASSERT(!traits::is_sequence<char>::value);
|
||||
}
|
||||
|
||||
{ // testing mpl::is_sequence
|
||||
|
||||
typedef FUSION_SEQUENCE<int, float, double> t1;
|
||||
typedef FUSION_SEQUENCE<> t2;
|
||||
typedef FUSION_SEQUENCE<char> t3;
|
||||
|
||||
BOOST_STATIC_ASSERT(boost::mpl::is_sequence<t1>::value);
|
||||
BOOST_STATIC_ASSERT(boost::mpl::is_sequence<t2>::value);
|
||||
BOOST_STATIC_ASSERT(boost::mpl::is_sequence<t3>::value);
|
||||
}
|
||||
|
||||
{ // testing mpl compatibility
|
||||
|
||||
// test begin, end, next, prior, advance, size, deref, etc.
|
||||
|
25
test/sequence/nil.cpp
Normal file
25
test/sequence/nil.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2014 Louis Dionne
|
||||
|
||||
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/list/cons_iterator.hpp>
|
||||
#include <boost/fusion/container/list/nil.hpp>
|
||||
#include <boost/fusion/support/config.hpp>
|
||||
#include <boost/mpl/bool.hpp>
|
||||
|
||||
|
||||
int main() {
|
||||
using namespace boost::fusion;
|
||||
|
||||
// nil should be constexpr constructible
|
||||
{
|
||||
BOOST_CONSTEXPR nil x1 = nil();
|
||||
BOOST_CONSTEXPR nil x2 = nil(nil_iterator(), boost::mpl::true_());
|
||||
(void)x1; (void)x2;
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
@ -18,8 +18,10 @@
|
||||
#include <boost/fusion/iterator/next.hpp>
|
||||
#include <boost/fusion/support/pair.hpp>
|
||||
#include <boost/fusion/support/category_of.hpp>
|
||||
#include <boost/fusion/support/is_sequence.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/mpl/is_sequence.hpp>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
@ -78,6 +80,28 @@ main()
|
||||
BOOST_TEST(at_key<int>(make_set('X', 123)) == 123);
|
||||
}
|
||||
|
||||
{ // testing is_sequence
|
||||
|
||||
typedef set<int, float, double> t1;
|
||||
typedef set<> t2;
|
||||
typedef set<char> t3;
|
||||
|
||||
BOOST_MPL_ASSERT((traits::is_sequence<t1>));
|
||||
BOOST_MPL_ASSERT((traits::is_sequence<t2>));
|
||||
BOOST_MPL_ASSERT((traits::is_sequence<t3>));
|
||||
}
|
||||
|
||||
{ // testing mpl::is_sequence
|
||||
|
||||
typedef set<int, float, double> t1;
|
||||
typedef set<> t2;
|
||||
typedef set<char> t3;
|
||||
|
||||
BOOST_MPL_ASSERT((boost::mpl::is_sequence<t1>));
|
||||
BOOST_MPL_ASSERT((boost::mpl::is_sequence<t2>));
|
||||
BOOST_MPL_ASSERT((boost::mpl::is_sequence<t3>));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
|
101
test/sequence/size.cpp
Normal file
101
test/sequence/size.cpp
Normal file
@ -0,0 +1,101 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2014 Kohei Takahashi
|
||||
|
||||
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/fusion/container/vector.hpp>
|
||||
#include <boost/fusion/container/deque.hpp>
|
||||
#include <boost/fusion/container/list.hpp>
|
||||
#include <boost/fusion/container/set.hpp>
|
||||
#include <boost/fusion/container/map.hpp>
|
||||
#include <boost/fusion/support/pair.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/size.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
|
||||
#include <boost/array.hpp>
|
||||
#include <boost/fusion/adapted/boost_array.hpp>
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <boost/fusion/adapted/boost_tuple.hpp>
|
||||
#if !defined(BOOST_NO_CXX11_HDR_TUPLE)
|
||||
#include <tuple>
|
||||
#include <boost/fusion/adapted/std_tuple.hpp>
|
||||
#endif
|
||||
|
||||
template <typename LHS, typename RHS>
|
||||
void check_(LHS const&, RHS const&)
|
||||
{
|
||||
BOOST_MPL_ASSERT((boost::is_same<LHS, RHS>));
|
||||
}
|
||||
|
||||
template <typename S>
|
||||
void check()
|
||||
{
|
||||
check_(
|
||||
boost::fusion::result_of::size<S>::type::value
|
||||
, boost::fusion::result_of::size<S>::value
|
||||
);
|
||||
}
|
||||
|
||||
void test()
|
||||
{
|
||||
{
|
||||
check<boost::fusion::vector<> >();
|
||||
check<boost::fusion::vector<int> >();
|
||||
check<boost::fusion::vector<int, int> >();
|
||||
check<boost::fusion::vector<int, int, int> >();
|
||||
}
|
||||
|
||||
{
|
||||
check<boost::fusion::deque<> >();
|
||||
check<boost::fusion::deque<int> >();
|
||||
check<boost::fusion::deque<int, int> >();
|
||||
check<boost::fusion::deque<int, int, int> >();
|
||||
}
|
||||
|
||||
{
|
||||
check<boost::fusion::list<> >();
|
||||
check<boost::fusion::list<int> >();
|
||||
check<boost::fusion::list<int, int> >();
|
||||
check<boost::fusion::list<int, int, int> >();
|
||||
}
|
||||
|
||||
{
|
||||
check<boost::fusion::set<> >();
|
||||
check<boost::fusion::set<int> >();
|
||||
check<boost::fusion::set<int, float> >();
|
||||
check<boost::fusion::set<int, float, double> >();
|
||||
}
|
||||
|
||||
{
|
||||
check<boost::fusion::map<> >();
|
||||
check<boost::fusion::map<boost::fusion::pair<int, int> > >();
|
||||
check<boost::fusion::map<boost::fusion::pair<int, int> , boost::fusion::pair<float, int> > >();
|
||||
check<boost::fusion::map<boost::fusion::pair<int, int> , boost::fusion::pair<float, int> , boost::fusion::pair<double, int> > >();
|
||||
}
|
||||
|
||||
{
|
||||
check<boost::array<int, 1> >();
|
||||
check<boost::array<int, 2> >();
|
||||
check<boost::array<int, 3> >();
|
||||
}
|
||||
|
||||
{
|
||||
check<boost::tuples::tuple<> >();
|
||||
check<boost::tuples::tuple<int> >();
|
||||
check<boost::tuples::tuple<int, int> >();
|
||||
check<boost::tuples::tuple<int, int, int> >();
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_TUPLE)
|
||||
{
|
||||
check<std::tuple<> >();
|
||||
check<std::tuple<int> >();
|
||||
check<std::tuple<int, int> >();
|
||||
check<std::tuple<int, int, int> >();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -1,70 +0,0 @@
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_TUPLE) && \
|
||||
!defined(BOOST_NO_CXX11_SMART_PTR)
|
||||
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
#include <boost/any.hpp>
|
||||
#include <iostream>
|
||||
|
||||
namespace Core
|
||||
{
|
||||
class AutoConverter
|
||||
{
|
||||
std::shared_ptr<boost::any> t_;
|
||||
|
||||
public:
|
||||
AutoConverter(std::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::shared_ptr<boost::any> p_result
|
||||
(new boost::any(std::make_tuple(1, 2, 3, 4)));
|
||||
return p_result;
|
||||
}
|
||||
|
||||
} // namespace Core
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
std::tuple<int, int, int, int> test = Core::Demo();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -1,3 +1,9 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 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/mpl/vector.hpp>
|
||||
#include <boost/fusion/support.hpp>
|
||||
|
27
test/support/pair_container.hpp
Normal file
27
test/support/pair_container.hpp
Normal file
@ -0,0 +1,27 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2014 Kohei Takahashi
|
||||
|
||||
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/core/ignore_unused.hpp>
|
||||
#include <boost/fusion/support/pair.hpp>
|
||||
|
||||
using namespace boost::fusion;
|
||||
|
||||
template <typename C>
|
||||
void copy()
|
||||
{
|
||||
pair<int, C> src;
|
||||
pair<int, C> dest = src;
|
||||
boost::ignore_unused(dest);
|
||||
}
|
||||
|
||||
void test()
|
||||
{
|
||||
copy<FUSION_SEQUENCE<> >();
|
||||
copy<FUSION_SEQUENCE<TEST_TYPE> >();
|
||||
copy<FUSION_SEQUENCE<TEST_TYPE, TEST_TYPE> >();
|
||||
}
|
||||
|
17
test/support/pair_deque.cpp
Normal file
17
test/support/pair_deque.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2014 Kohei Takahashi
|
||||
|
||||
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 TEST_TYPE int
|
||||
#include "./pair_container.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
test();
|
||||
}
|
||||
|
17
test/support/pair_list.cpp
Normal file
17
test/support/pair_list.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2014 Kohei Takahashi
|
||||
|
||||
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 TEST_TYPE int
|
||||
#include "./pair_container.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
test();
|
||||
}
|
||||
|
17
test/support/pair_map.cpp
Normal file
17
test/support/pair_map.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2014 Kohei Takahashi
|
||||
|
||||
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/map/map.hpp>
|
||||
|
||||
#define FUSION_SEQUENCE map
|
||||
#define TEST_TYPE pair<int,int>
|
||||
#include "./pair_container.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
test();
|
||||
}
|
||||
|
@ -1,8 +1,17 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2010 Christopher Schmidt
|
||||
Copyright (c) 2014 Kohei Takahashi
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
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/set/set.hpp>
|
||||
|
||||
#define FUSION_SEQUENCE set
|
||||
#define TEST_TYPE int
|
||||
#include "./pair_container.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
test();
|
||||
}
|
||||
|
||||
#include "fold.hpp"
|
17
test/support/pair_vector.cpp
Normal file
17
test/support/pair_vector.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2014 Kohei Takahashi
|
||||
|
||||
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
|
||||
#define TEST_TYPE int
|
||||
#include "./pair_container.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
test();
|
||||
}
|
||||
|
Reference in New Issue
Block a user