forked from boostorg/fusion
Merge remote-tracking branch 'official/develop' into fusion_adapters
Conflicts: test/sequence/adapt_struct.cpp
This commit is contained in:
@@ -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>
|
||||
|
Reference in New Issue
Block a user