From 219b4124d7306c48f7fbcf2589f527c5373e9849 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Wed, 17 Oct 2012 19:59:44 +0900 Subject: [PATCH] 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