os/ossrv/ossrv_pub/boost_apis/boost/variant/detail/substitute.hpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
sl@0
     2
#if !defined(BOOST_PP_IS_ITERATING)
sl@0
     3
sl@0
     4
///// header body
sl@0
     5
sl@0
     6
//-----------------------------------------------------------------------------
sl@0
     7
// boost variant/detail/substitute.hpp header file
sl@0
     8
// See http://www.boost.org for updates, documentation, and revision history.
sl@0
     9
//-----------------------------------------------------------------------------
sl@0
    10
//
sl@0
    11
// Copyright (c) 2003
sl@0
    12
// Eric Friedman
sl@0
    13
//
sl@0
    14
// Distributed under the Boost Software License, Version 1.0. (See
sl@0
    15
// accompanying file LICENSE_1_0.txt or copy at
sl@0
    16
// http://www.boost.org/LICENSE_1_0.txt)
sl@0
    17
sl@0
    18
#ifndef BOOST_VARIANT_DETAIL_SUBSTITUTE_HPP
sl@0
    19
#define BOOST_VARIANT_DETAIL_SUBSTITUTE_HPP
sl@0
    20
sl@0
    21
#include "boost/mpl/aux_/config/ctps.hpp"
sl@0
    22
sl@0
    23
#include "boost/variant/detail/substitute_fwd.hpp"
sl@0
    24
#include "boost/mpl/aux_/lambda_arity_param.hpp"
sl@0
    25
#include "boost/mpl/aux_/preprocessor/params.hpp"
sl@0
    26
#include "boost/mpl/aux_/preprocessor/repeat.hpp"
sl@0
    27
#include "boost/mpl/int_fwd.hpp"
sl@0
    28
#include "boost/mpl/limits/arity.hpp"
sl@0
    29
#include "boost/preprocessor/cat.hpp"
sl@0
    30
#include "boost/preprocessor/empty.hpp"
sl@0
    31
#include "boost/preprocessor/arithmetic/inc.hpp"
sl@0
    32
#include "boost/preprocessor/iterate.hpp"
sl@0
    33
sl@0
    34
namespace boost {
sl@0
    35
namespace detail { namespace variant {
sl@0
    36
sl@0
    37
#if !defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE)
sl@0
    38
sl@0
    39
///////////////////////////////////////////////////////////////////////////////
sl@0
    40
// (detail) metafunction substitute
sl@0
    41
//
sl@0
    42
// Substitutes one type for another in the given type expression.
sl@0
    43
//
sl@0
    44
sl@0
    45
//
sl@0
    46
// primary template
sl@0
    47
//
sl@0
    48
template <
sl@0
    49
      typename T, typename Dest, typename Source
sl@0
    50
      BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(
sl@0
    51
          typename Arity /* = ... (see substitute_fwd.hpp) */
sl@0
    52
        )
sl@0
    53
    >
sl@0
    54
struct substitute
sl@0
    55
{
sl@0
    56
    typedef T type;
sl@0
    57
};
sl@0
    58
sl@0
    59
//
sl@0
    60
// tag substitution specializations
sl@0
    61
//
sl@0
    62
sl@0
    63
#define BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_SUBSTITUTE_TAG(CV_) \
sl@0
    64
    template <typename Dest, typename Source> \
sl@0
    65
    struct substitute< \
sl@0
    66
          CV_ Source \
sl@0
    67
        , Dest \
sl@0
    68
        , Source \
sl@0
    69
          BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(mpl::int_<-1>) \
sl@0
    70
        > \
sl@0
    71
    { \
sl@0
    72
        typedef CV_ Dest type; \
sl@0
    73
    }; \
sl@0
    74
    /**/
sl@0
    75
sl@0
    76
BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_SUBSTITUTE_TAG( BOOST_PP_EMPTY() )
sl@0
    77
BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_SUBSTITUTE_TAG(const)
sl@0
    78
BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_SUBSTITUTE_TAG(volatile)
sl@0
    79
BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_SUBSTITUTE_TAG(const volatile)
sl@0
    80
sl@0
    81
#undef BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_SUBSTITUTE_TAG
sl@0
    82
sl@0
    83
//
sl@0
    84
// pointer specializations
sl@0
    85
//
sl@0
    86
#define BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_HANDLE_POINTER(CV_) \
sl@0
    87
    template <typename T, typename Dest, typename Source> \
sl@0
    88
    struct substitute< \
sl@0
    89
          T * CV_ \
sl@0
    90
        , Dest \
sl@0
    91
        , Source \
sl@0
    92
          BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(mpl::int_<-1>) \
sl@0
    93
        > \
sl@0
    94
    { \
sl@0
    95
        typedef typename substitute< \
sl@0
    96
              T, Dest, Source \
sl@0
    97
            >::type * CV_ type; \
sl@0
    98
    }; \
sl@0
    99
    /**/
sl@0
   100
sl@0
   101
BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_HANDLE_POINTER( BOOST_PP_EMPTY() )
sl@0
   102
BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_HANDLE_POINTER(const)
sl@0
   103
BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_HANDLE_POINTER(volatile)
sl@0
   104
BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_HANDLE_POINTER(const volatile)
sl@0
   105
sl@0
   106
#undef BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL_HANDLE_POINTER
sl@0
   107
sl@0
   108
//
sl@0
   109
// reference specializations
sl@0
   110
//
sl@0
   111
template <typename T, typename Dest, typename Source>
sl@0
   112
struct substitute<
sl@0
   113
      T&
sl@0
   114
    , Dest
sl@0
   115
    , Source
sl@0
   116
      BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(mpl::int_<-1>)
sl@0
   117
    >
sl@0
   118
{
sl@0
   119
    typedef typename substitute<
sl@0
   120
          T, Dest, Source
sl@0
   121
        >::type & type;
sl@0
   122
};
sl@0
   123
sl@0
   124
//
sl@0
   125
// template expression (i.e., F<...>) specializations
sl@0
   126
//
sl@0
   127
sl@0
   128
#define BOOST_VARIANT_AUX_SUBSTITUTE_TYPEDEF_IMPL(N) \
sl@0
   129
    typedef typename substitute< \
sl@0
   130
          BOOST_PP_CAT(U,N), Dest, Source \
sl@0
   131
        >::type BOOST_PP_CAT(u,N); \
sl@0
   132
    /**/
sl@0
   133
sl@0
   134
#define BOOST_VARIANT_AUX_SUBSTITUTE_TYPEDEF(z, N, _) \
sl@0
   135
    BOOST_VARIANT_AUX_SUBSTITUTE_TYPEDEF_IMPL( BOOST_PP_INC(N) ) \
sl@0
   136
    /**/
sl@0
   137
sl@0
   138
#define BOOST_PP_ITERATION_LIMITS (0,BOOST_MPL_LIMIT_METAFUNCTION_ARITY)
sl@0
   139
#define BOOST_PP_FILENAME_1 "boost/variant/detail/substitute.hpp"
sl@0
   140
#include BOOST_PP_ITERATE()
sl@0
   141
sl@0
   142
#undef BOOST_VARIANT_AUX_SUBSTITUTE_TYPEDEF_IMPL
sl@0
   143
#undef BOOST_VARIANT_AUX_SUBSTITUTE_TYPEDEF
sl@0
   144
sl@0
   145
#endif // !defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE)
sl@0
   146
sl@0
   147
}} // namespace detail::variant
sl@0
   148
} // namespace boost
sl@0
   149
sl@0
   150
#endif // BOOST_VARIANT_DETAIL_SUBSTITUTE_HPP
sl@0
   151
sl@0
   152
///// iteration, depth == 1
sl@0
   153
sl@0
   154
#elif BOOST_PP_ITERATION_DEPTH() == 1
sl@0
   155
#define i BOOST_PP_FRAME_ITERATION(1)
sl@0
   156
sl@0
   157
#if i > 0
sl@0
   158
sl@0
   159
//
sl@0
   160
// template specializations
sl@0
   161
//
sl@0
   162
template <
sl@0
   163
      template < BOOST_MPL_PP_PARAMS(i,typename P) > class T
sl@0
   164
    , BOOST_MPL_PP_PARAMS(i,typename U)
sl@0
   165
    , typename Dest
sl@0
   166
    , typename Source
sl@0
   167
    >
sl@0
   168
struct substitute<
sl@0
   169
      T< BOOST_MPL_PP_PARAMS(i,U) >
sl@0
   170
    , Dest
sl@0
   171
    , Source
sl@0
   172
      BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(mpl::int_<( i )>)
sl@0
   173
    >
sl@0
   174
{
sl@0
   175
private:
sl@0
   176
    BOOST_MPL_PP_REPEAT(i, BOOST_VARIANT_AUX_SUBSTITUTE_TYPEDEF, _)
sl@0
   177
sl@0
   178
public:
sl@0
   179
    typedef T< BOOST_MPL_PP_PARAMS(i,u) > type;
sl@0
   180
};
sl@0
   181
sl@0
   182
//
sl@0
   183
// function specializations
sl@0
   184
//
sl@0
   185
template <
sl@0
   186
      typename R
sl@0
   187
    , BOOST_MPL_PP_PARAMS(i,typename U)
sl@0
   188
    , typename Dest
sl@0
   189
    , typename Source
sl@0
   190
    >
sl@0
   191
struct substitute<
sl@0
   192
      R (*)( BOOST_MPL_PP_PARAMS(i,U) )
sl@0
   193
    , Dest
sl@0
   194
    , Source
sl@0
   195
      BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(mpl::int_<-1>)
sl@0
   196
    >
sl@0
   197
{
sl@0
   198
private:
sl@0
   199
    typedef typename substitute< R, Dest, Source >::type r;
sl@0
   200
    BOOST_MPL_PP_REPEAT(i, BOOST_VARIANT_AUX_SUBSTITUTE_TYPEDEF, _)
sl@0
   201
sl@0
   202
public:
sl@0
   203
    typedef r (*type)( BOOST_MPL_PP_PARAMS(i,u) );
sl@0
   204
};
sl@0
   205
sl@0
   206
#elif i == 0
sl@0
   207
sl@0
   208
//
sl@0
   209
// zero-arg function specialization
sl@0
   210
//
sl@0
   211
template <
sl@0
   212
      typename R, typename Dest, typename Source
sl@0
   213
    >
sl@0
   214
struct substitute<
sl@0
   215
      R (*)( void )
sl@0
   216
    , Dest
sl@0
   217
    , Source
sl@0
   218
      BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(mpl::int_<-1>)
sl@0
   219
    >
sl@0
   220
{
sl@0
   221
private:
sl@0
   222
    typedef typename substitute< R, Dest, Source >::type r;
sl@0
   223
sl@0
   224
public:
sl@0
   225
    typedef r (*type)( void );
sl@0
   226
};
sl@0
   227
sl@0
   228
#endif // i
sl@0
   229
sl@0
   230
#undef i
sl@0
   231
#endif // BOOST_PP_IS_ITERATING