From 6e2bfab3fda26abf264c9b4578b6e0ba41e3d20a Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Wed, 17 Oct 2012 18:05:39 +0900 Subject: [PATCH] Support adapting Boost.Tuple to Boost.MPL via Boost.Fusion --- boost/fusion/adapted/boost_tuple.hpp | 3 ++ .../adapted/boost_tuple/detail/build_cons.hpp | 57 ++++++++++++++++++++ .../adapted/boost_tuple/detail/convert_impl.hpp | 48 +++++++++++++++++ boost/fusion/adapted/boost_tuple/mpl/clear.hpp | 23 ++++++++ 4 files changed, 131 insertions(+) create mode 100644 boost/fusion/adapted/boost_tuple/detail/build_cons.hpp create mode 100644 boost/fusion/adapted/boost_tuple/detail/convert_impl.hpp create mode 100644 boost/fusion/adapted/boost_tuple/mpl/clear.hpp diff --git a/boost/fusion/adapted/boost_tuple.hpp b/boost/fusion/adapted/boost_tuple.hpp index 6149478..88eada1 100644 --- a/boost/fusion/adapted/boost_tuple.hpp +++ b/boost/fusion/adapted/boost_tuple.hpp @@ -1,5 +1,6 @@ /*============================================================================= Copyright (c) 2001-2011 Joel de Guzman + 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) @@ -16,5 +17,7 @@ #include #include #include +#include +#include #endif diff --git a/boost/fusion/adapted/boost_tuple/detail/build_cons.hpp b/boost/fusion/adapted/boost_tuple/detail/build_cons.hpp new file mode 100644 index 0000000..9e2673e --- /dev/null +++ b/boost/fusion/adapted/boost_tuple/detail/build_cons.hpp @@ -0,0 +1,57 @@ +/*============================================================================= + 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_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_cons; + + template + struct build_cons + { + typedef boost::tuples::null_type type; + + static type + call(First const&, Last const&) + { + return type(); + } + }; + + template + struct build_cons + { + typedef + build_cons::type, Last> + next_build_cons; + + typedef boost::tuples::cons< + typename result_of::value_of::type + , typename next_build_cons::type> + type; + + static type + call(First const& f, Last const& l) + { + typename result_of::value_of::type v = *f; + return type(v, next_build_cons::call(fusion::next(f), l)); + } + }; +}}} + +#endif diff --git a/boost/fusion/adapted/boost_tuple/detail/convert_impl.hpp b/boost/fusion/adapted/boost_tuple/detail/convert_impl.hpp new file mode 100644 index 0000000..e099981 --- /dev/null +++ b/boost/fusion/adapted/boost_tuple/detail/convert_impl.hpp @@ -0,0 +1,48 @@ +/*============================================================================= + 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_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_cons< + typename result_of::begin::type + , typename result_of::end::type + > + build_cons; + + typedef typename build_cons::type type; + + static type call(Sequence& seq) + { + return build_cons::call(fusion::begin(seq), fusion::end(seq)); + } + }; + }; + } +}} + +#endif diff --git a/boost/fusion/adapted/boost_tuple/mpl/clear.hpp b/boost/fusion/adapted/boost_tuple/mpl/clear.hpp new file mode 100644 index 0000000..1cca019 --- /dev/null +++ b/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 -- 1.7.9.5