From 39785ddb0e6b3ef83ebf8aaa3e89be3c4005fa31 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Wed, 17 Oct 2012 18:05:39 +0900 Subject: [PATCH 1/6] Add convert implementation for Boost.Tuple Signed-off-by: Kohei Takahashi --- include/boost/fusion/adapted/boost_tuple.hpp | 1 + .../adapted/boost_tuple/detail/build_cons.hpp | 59 +++++++++++++++++++ .../boost_tuple/detail/convert_impl.hpp | 50 ++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 include/boost/fusion/adapted/boost_tuple/detail/build_cons.hpp create mode 100644 include/boost/fusion/adapted/boost_tuple/detail/convert_impl.hpp diff --git a/include/boost/fusion/adapted/boost_tuple.hpp b/include/boost/fusion/adapted/boost_tuple.hpp index 85af5764..a391156d 100644 --- a/include/boost/fusion/adapted/boost_tuple.hpp +++ b/include/boost/fusion/adapted/boost_tuple.hpp @@ -17,5 +17,6 @@ #include #include #include +#include #endif diff --git a/include/boost/fusion/adapted/boost_tuple/detail/build_cons.hpp b/include/boost/fusion/adapted/boost_tuple/detail/build_cons.hpp new file mode 100644 index 00000000..216fb0a6 --- /dev/null +++ b/include/boost/fusion/adapted/boost_tuple/detail/build_cons.hpp @@ -0,0 +1,59 @@ +/*============================================================================= + Copyright (c) 2012-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) +==============================================================================*/ +#if !defined(BOOST_FUSION_BUILD_CONS_10172012_0130) +#define BOOST_FUSION_BUILD_CONS_10172012_0130 + +#include +#include +#include +#include +#include + +namespace boost { namespace fusion { namespace detail +{ + template < + typename First + , typename Last + , bool is_empty = result_of::equal_to::value> + struct build_tuple_cons; + + template + struct build_tuple_cons + { + typedef boost::tuples::null_type type; + + BOOST_FUSION_GPU_ENABLED + static type + call(First const&, Last const&) + { + return type(); + } + }; + + template + struct build_tuple_cons + { + typedef + build_tuple_cons::type, Last> + next_build_tuple_cons; + + typedef boost::tuples::cons< + typename result_of::value_of::type + , typename next_build_tuple_cons::type> + type; + + BOOST_FUSION_GPU_ENABLED + static type + call(First const& f, Last const& l) + { + typename result_of::value_of::type v = *f; + return type(v, next_build_tuple_cons::call(fusion::next(f), l)); + } + }; +}}} + +#endif diff --git a/include/boost/fusion/adapted/boost_tuple/detail/convert_impl.hpp b/include/boost/fusion/adapted/boost_tuple/detail/convert_impl.hpp new file mode 100644 index 00000000..8f2fbeec --- /dev/null +++ b/include/boost/fusion/adapted/boost_tuple/detail/convert_impl.hpp @@ -0,0 +1,50 @@ +/*============================================================================= + Copyright (c) 2012-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) +==============================================================================*/ +#if !defined(BOOST_FUSION_CONVERT_IMPL_10172012_0120) +#define BOOST_FUSION_CONVERT_IMPL_10172012_0120 + +#include +#include +#include +#include + +namespace boost { namespace fusion +{ + struct boost_tuple_tag; + + namespace extension + { + template + struct convert_impl; + + template <> + struct convert_impl + { + template + struct apply + { + typedef typename + detail::build_tuple_cons< + typename result_of::begin::type + , typename result_of::end::type + > + build_tuple_cons; + + typedef typename build_tuple_cons::type type; + + BOOST_FUSION_GPU_ENABLED + static type + call(Sequence& seq) + { + return build_tuple_cons::call(fusion::begin(seq), fusion::end(seq)); + } + }; + }; + } +}} + +#endif From 219b4124d7306c48f7fbcf2589f527c5373e9849 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Wed, 17 Oct 2012 19:59:44 +0900 Subject: [PATCH 2/6] Add convert implementation for std::tuple Signed-off-by: Kohei Takahashi --- include/boost/fusion/adapted/std_tuple.hpp | 1 + .../std_tuple/detail/build_std_tuple.hpp | 105 ++++++++++++++++++ .../adapted/std_tuple/detail/convert_impl.hpp | 48 ++++++++ 3 files changed, 154 insertions(+) create mode 100644 include/boost/fusion/adapted/std_tuple/detail/build_std_tuple.hpp create mode 100644 include/boost/fusion/adapted/std_tuple/detail/convert_impl.hpp diff --git a/include/boost/fusion/adapted/std_tuple.hpp b/include/boost/fusion/adapted/std_tuple.hpp index 984a4df4..3716d73b 100644 --- a/include/boost/fusion/adapted/std_tuple.hpp +++ b/include/boost/fusion/adapted/std_tuple.hpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include diff --git a/include/boost/fusion/adapted/std_tuple/detail/build_std_tuple.hpp b/include/boost/fusion/adapted/std_tuple/detail/build_std_tuple.hpp new file mode 100644 index 00000000..fd96eabf --- /dev/null +++ b/include/boost/fusion/adapted/std_tuple/detail/build_std_tuple.hpp @@ -0,0 +1,105 @@ +/*============================================================================= + 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) +==============================================================================*/ +#if !defined(BOOST_FUSION_BUILD_STD_TUPLE_05292014_0100) +#define BOOST_FUSION_BUILD_STD_TUPLE_05292014_0100 + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost { namespace fusion { namespace detail +{ + template ::value + > + struct build_std_tuple; + + template + struct build_std_tuple + { + typedef std::tuple<> type; + BOOST_FUSION_GPU_ENABLED + static type + call(First const&, Last const&) + { + return type(); + } + }; + + template struct indexed_tuple { }; + + template > + struct make_indexed_tuple; + + template + struct make_indexed_tuple> + { + typedef typename + boost::mpl::eval_if_c< + (Head == 0), + boost::mpl::identity>, + make_indexed_tuple> + >::type + type; + }; + + template + struct push_front_std_tuple; + + template + struct push_front_std_tuple> + { + typedef std::tuple type; + + template + BOOST_FUSION_GPU_ENABLED + static type + indexed_call(T const& first, std::tuple const& rest, indexed_tuple) + { + return type(first, std::get(rest)...); + } + + BOOST_FUSION_GPU_ENABLED + static type + call(T const& first, std::tuple const& rest) + { + typedef typename make_indexed_tuple::type gen; + return indexed_call(first, rest, gen()); + } + }; + + template + struct build_std_tuple + { + typedef + build_std_tuple::type, Last> + next_build_std_tuple; + + typedef push_front_std_tuple< + typename result_of::value_of::type + , typename next_build_std_tuple::type> + push_front; + + typedef typename push_front::type type; + + BOOST_FUSION_GPU_ENABLED + static type + call(First const& f, Last const& l) + { + typename result_of::value_of::type v = *f; + return push_front::call( + v, next_build_std_tuple::call(fusion::next(f), l)); + } + }; +}}} + +#endif diff --git a/include/boost/fusion/adapted/std_tuple/detail/convert_impl.hpp b/include/boost/fusion/adapted/std_tuple/detail/convert_impl.hpp new file mode 100644 index 00000000..ee079bed --- /dev/null +++ b/include/boost/fusion/adapted/std_tuple/detail/convert_impl.hpp @@ -0,0 +1,48 @@ +/*============================================================================= + Copyright (c) 2012-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) +==============================================================================*/ +#if !defined(BOOST_FUSION_CONVERT_IMPL_10172012_0940) +#define BOOST_FUSION_CONVERT_IMPL_10172012_0940 + +#include +#include +#include +#include + +namespace boost { namespace fusion +{ + struct std_tuple_tag; + + namespace extension + { + template + struct convert_impl; + + template <> + struct convert_impl + { + template + struct apply + { + typedef detail::build_std_tuple< + typename result_of::begin::type + , typename result_of::end::type + > gen; + + typedef typename gen::type type; + + BOOST_FUSION_GPU_ENABLED + static type + call(Sequence& seq) + { + return gen::call(begin(seq), end(seq)); + } + }; + }; + } +}} + +#endif From 38bcd6e779ae06ff7da2aba1066307d9f3666dc1 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Wed, 17 Oct 2012 18:05:39 +0900 Subject: [PATCH 3/6] Add mpl::clear implementation for Boost.Tuple Signed-off-by: Kohei Takahashi --- include/boost/fusion/adapted/boost_tuple.hpp | 1 + .../fusion/adapted/boost_tuple/mpl/clear.hpp | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 include/boost/fusion/adapted/boost_tuple/mpl/clear.hpp diff --git a/include/boost/fusion/adapted/boost_tuple.hpp b/include/boost/fusion/adapted/boost_tuple.hpp index a391156d..7ef65686 100644 --- a/include/boost/fusion/adapted/boost_tuple.hpp +++ b/include/boost/fusion/adapted/boost_tuple.hpp @@ -18,5 +18,6 @@ #include #include #include +#include #endif diff --git a/include/boost/fusion/adapted/boost_tuple/mpl/clear.hpp b/include/boost/fusion/adapted/boost_tuple/mpl/clear.hpp new file mode 100644 index 00000000..1cca019c --- /dev/null +++ b/include/boost/fusion/adapted/boost_tuple/mpl/clear.hpp @@ -0,0 +1,23 @@ +/*============================================================================= + Copyright (c) 2012 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) +==============================================================================*/ +#if !defined(BOOST_FUSION_CLEAR_10172012_0100) +#define BOOST_FUSION_CLEAR_10172012_0100 + +#include +#include + +namespace boost { namespace fusion { namespace detail { + + template + struct clear; + + template <> + struct clear : mpl::identity > {}; + +}}} + +#endif From f5fe438f14a6a4b58fa3e8758f53b32fd2d5ecf1 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Wed, 17 Oct 2012 19:59:44 +0900 Subject: [PATCH 4/6] Add mpl::clear implementation for std::tuple Signed-off-by: Kohei Takahashi --- include/boost/fusion/adapted/std_tuple.hpp | 1 + .../fusion/adapted/std_tuple/mpl/clear.hpp | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 include/boost/fusion/adapted/std_tuple/mpl/clear.hpp diff --git a/include/boost/fusion/adapted/std_tuple.hpp b/include/boost/fusion/adapted/std_tuple.hpp index 3716d73b..b7e84791 100644 --- a/include/boost/fusion/adapted/std_tuple.hpp +++ b/include/boost/fusion/adapted/std_tuple.hpp @@ -19,5 +19,6 @@ #include #include #include +#include #endif diff --git a/include/boost/fusion/adapted/std_tuple/mpl/clear.hpp b/include/boost/fusion/adapted/std_tuple/mpl/clear.hpp new file mode 100644 index 00000000..87123164 --- /dev/null +++ b/include/boost/fusion/adapted/std_tuple/mpl/clear.hpp @@ -0,0 +1,23 @@ +/*============================================================================= + Copyright (c) 2012 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) +==============================================================================*/ +#if !defined(BOOST_FUSION_CLEAR_10172012_0940) +#define BOOST_FUSION_CLEAR_10172012_0940 + +#include +#include + +namespace boost { namespace fusion { namespace detail +{ + template + struct clear; + + template <> + struct clear : mpl::identity > {}; + +}}} + +#endif From f7adae2b3d4cfa205c680f4c663c9bfc12410081 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Thu, 29 May 2014 02:24:26 +0900 Subject: [PATCH 5/6] Add test for convert seq to tuple Signed-off-by: Kohei Takahashi --- test/sequence/boost_tuple.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/sequence/boost_tuple.cpp b/test/sequence/boost_tuple.cpp index c16c0894..7d19ffef 100644 --- a/test/sequence/boost_tuple.cpp +++ b/test/sequence/boost_tuple.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -87,7 +88,14 @@ main() fusion::list l(tuples::make_tuple(123, "Hola!!!")); l = tuples::make_tuple(123, "Hola!!!"); } - + + { + // conversion vector to boost tuple + boost::tuple t = convert(make_vector(123, "Hola!!!")); + BOOST_TEST(get<0>(t) == 123); + BOOST_TEST(get<1>(t) == "Hola!!!"); + } + { // test from Ticket #1601, submitted by Shunsuke Sogame // expanded by Stjepan Rajko From 059c0416599827fbc6c71d45d95d23191953676e Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Sun, 8 Jun 2014 02:47:06 +0900 Subject: [PATCH 6/6] Add test for convert seq to std::tuple Signed-off-by: Kohei Takahashi --- test/Jamfile | 1 + test/sequence/std_tuple.cpp | 47 +++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 test/sequence/std_tuple.cpp diff --git a/test/Jamfile b/test/Jamfile index 1c84637d..73c4e89a 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -150,6 +150,7 @@ project [ run sequence/define_tpl_struct.cpp : : : : ] [ run sequence/define_tpl_struct_inline.cpp : : : : ] [ run sequence/define_assoc_tpl_struct.cpp : : : : ] + [ run sequence/std_tuple.cpp : : : : ] [ run sequence/std_tuple_iterator.cpp : : : : ] [ run sequence/ref_vector.cpp : : : : ] [ run sequence/flatten_view.cpp : : : : ] diff --git a/test/sequence/std_tuple.cpp b/test/sequence/std_tuple.cpp new file mode 100644 index 00000000..3ac6e387 --- /dev/null +++ b/test/sequence/std_tuple.cpp @@ -0,0 +1,47 @@ +/*============================================================================= + 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 + +#if !defined(BOOST_NO_CXX11_HDR_TUPLE) + +#include +#include +#include +#include +#include +#include +#include + +int +main() +{ + using namespace boost::fusion; + using namespace boost; + +// The convert only supports implementations using variadic templates +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + { + // conversion vector to std tuple + std::tuple t = convert(make_vector(123, "Hola!!!")); + BOOST_TEST(std::get<0>(t) == 123); + BOOST_TEST(std::get<1>(t) == "Hola!!!"); + } +#endif + + return boost::report_errors(); +} + +#else + +int +main() +{ + return 0; +} + +#endif