From 39785ddb0e6b3ef83ebf8aaa3e89be3c4005fa31 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Wed, 17 Oct 2012 18:05:39 +0900 Subject: [PATCH] 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