Ticket #7526: std_tuple-convert.patch

File std_tuple-convert.patch, 5.5 KB (added by Kohei Takahashi <flast@…>, 10 years ago)
  • boost/fusion/adapted/std_tuple.hpp

    From 2e77d2e8271cb34324cb1551fbd1f4c3303d74bb Mon Sep 17 00:00:00 2001
    From: Kohei Takahashi <flast@flast.jp>
    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 b  
    1515#include <boost/fusion/adapted/std_tuple/detail/size_impl.hpp>
    1616#include <boost/fusion/adapted/std_tuple/detail/at_impl.hpp>
    1717#include <boost/fusion/adapted/std_tuple/detail/value_at_impl.hpp>
     18#include <boost/fusion/adapted/std_tuple/detail/convert_impl.hpp>
     19#include <boost/fusion/adapted/std_tuple/mpl/clear.hpp>
    1820#include <boost/fusion/adapted/std_tuple/std_tuple_iterator.hpp>
    1921#include <boost/fusion/adapted/std_tuple/tag_of.hpp>
    2022
  • new file oost/fusion/adapted/std_tuple/detail/convert_impl.hpp

    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
    - +  
     1/*=============================================================================
     2    Copyright (c) 2012 Kohei Takahashi
     3
     4    Distributed under the Boost Software License, Version 1.0. (See accompanying
     5    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
     6==============================================================================*/
     7#if !defined(BOOST_FUSION_CONVERT_IMPL_10172012_0940)
     8#define BOOST_FUSION_CONVERT_IMPL_10172012_0940
     9
     10#include <tuple>
     11#include <boost/utility/enable_if.hpp>
     12#include <boost/mpl/identity.hpp>
     13#include <boost/mpl/eval_if.hpp>
     14#include <boost/fusion/sequence/intrinsic/begin.hpp>
     15#include <boost/fusion/sequence/intrinsic/end.hpp>
     16#include <boost/fusion/iterator/equal_to.hpp>
     17#include <boost/fusion/iterator/next.hpp>
     18#include <boost/fusion/iterator/deref.hpp>
     19
     20namespace boost { namespace fusion
     21{
     22    struct std_tuple_tag;
     23
     24    namespace extension
     25    {
     26        template <typename T>
     27        struct convert_impl;
     28
     29        template <>
     30        struct convert_impl<std_tuple_tag>
     31        {
     32            template <typename First, typename Last, typename... T>
     33            struct expand;
     34
     35            template <typename First, typename Last, typename... T>
     36            struct delay_expanding
     37            {
     38                typedef typename expand<
     39                    typename result_of::next<First>::type
     40                  , Last
     41                  , T...
     42                  , typename result_of::deref<First>::type
     43                >::type type;
     44            };
     45
     46            template <typename First, typename Last, typename... T>
     47            struct expand
     48            {
     49                typedef typename mpl::eval_if<
     50                    result_of::equal_to<First, Last>
     51                  , mpl::identity<std::tuple<T...> >
     52                  , delay_expanding<First, Last, T...>
     53                >::type type;
     54            };
     55
     56            template <typename Sequence>
     57            struct apply
     58            {
     59                typedef typename expand<
     60                    typename result_of::begin<Sequence>::type
     61                  , typename result_of::end<Sequence>::type
     62                >::type type;
     63
     64                template <typename I, typename E, typename... T>
     65                static typename boost::enable_if<
     66                    result_of::equal_to<I, E>
     67                  , type
     68                >::type call(I& i, E& e, T&... v)
     69                {
     70                    return type(v...);
     71                }
     72
     73                template <typename I, typename E, typename... T>
     74                static typename boost::disable_if<
     75                    result_of::equal_to<I, E>
     76                  , type
     77                >::type call(I& i, E& e, T&... v)
     78                {
     79                    return call(next(i), e, v..., deref(i));
     80                }
     81
     82                static type call(Sequence& seq)
     83                {
     84                    return call(begin(seq), end(seq));
     85                }
     86            };
     87        };
     88    }
     89}}
     90
     91#endif
  • new file oost/fusion/adapted/std_tuple/mpl/clear.hpp

    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
    - +  
     1/*=============================================================================
     2    Copyright (c) 2012 Kohei Takahashi
     3
     4    Distributed under the Boost Software License, Version 1.0. (See accompanying
     5    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
     6==============================================================================*/
     7#if !defined(BOOST_FUSION_CLEAR_10172012_0940)
     8#define BOOST_FUSION_CLEAR_10172012_0940
     9
     10#include <boost/mpl/identity.hpp>
     11#include <boost/fusion/adapted/std_tuple/tag_of.hpp>
     12
     13namespace boost { namespace fusion { namespace detail
     14{
     15  template <typename Tag>
     16  struct clear;
     17
     18  template <>
     19  struct clear<std_tuple_tag> : mpl::identity<std::tuple<> > {};
     20
     21}}}
     22
     23#endif