From 2e77d2e8271cb34324cb1551fbd1f4c3303d74bb Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Wed, 17 Oct 2012 19:59:44 +0900 Subject: [PATCH] Support adapting std::tuple to Boost.MPL via Boost.Fusion --- boost/fusion/adapted/std_tuple.hpp | 2 + .../adapted/std_tuple/detail/convert_impl.hpp | 91 ++++++++++++++++++++ boost/fusion/adapted/std_tuple/mpl/clear.hpp | 23 +++++ 3 files changed, 116 insertions(+) create mode 100644 boost/fusion/adapted/std_tuple/detail/convert_impl.hpp create mode 100644 boost/fusion/adapted/std_tuple/mpl/clear.hpp diff --git a/boost/fusion/adapted/std_tuple.hpp b/boost/fusion/adapted/std_tuple.hpp index a49b480..73dcdcd 100644 --- a/boost/fusion/adapted/std_tuple.hpp +++ b/boost/fusion/adapted/std_tuple.hpp @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include #include diff --git a/boost/fusion/adapted/std_tuple/detail/convert_impl.hpp b/boost/fusion/adapted/std_tuple/detail/convert_impl.hpp new file mode 100644 index 0000000..b5b6078 --- /dev/null +++ b/boost/fusion/adapted/std_tuple/detail/convert_impl.hpp @@ -0,0 +1,91 @@ +/*============================================================================= + 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_0940) +#define BOOST_FUSION_CONVERT_IMPL_10172012_0940 + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost { namespace fusion +{ + struct std_tuple_tag; + + namespace extension + { + template + struct convert_impl; + + template <> + struct convert_impl + { + template + struct expand; + + template + struct delay_expanding + { + typedef typename expand< + typename result_of::next::type + , Last + , T... + , typename result_of::deref::type + >::type type; + }; + + template + struct expand + { + typedef typename mpl::eval_if< + result_of::equal_to + , mpl::identity > + , delay_expanding + >::type type; + }; + + template + struct apply + { + typedef typename expand< + typename result_of::begin::type + , typename result_of::end::type + >::type type; + + template + static typename boost::enable_if< + result_of::equal_to + , type + >::type call(I& i, E& e, T&... v) + { + return type(v...); + } + + template + static typename boost::disable_if< + result_of::equal_to + , type + >::type call(I& i, E& e, T&... v) + { + return call(next(i), e, v..., deref(i)); + } + + static type call(Sequence& seq) + { + return call(begin(seq), end(seq)); + } + }; + }; + } +}} + +#endif diff --git a/boost/fusion/adapted/std_tuple/mpl/clear.hpp b/boost/fusion/adapted/std_tuple/mpl/clear.hpp new file mode 100644 index 0000000..8712316 --- /dev/null +++ b/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 -- 1.7.9.5