os/ossrv/ossrv_pub/boost_apis/boost/mpl/if.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
#ifndef BOOST_MPL_IF_HPP_INCLUDED
sl@0
     3
#define BOOST_MPL_IF_HPP_INCLUDED
sl@0
     4
sl@0
     5
// Copyright Aleksey Gurtovoy 2000-2004
sl@0
     6
//
sl@0
     7
// Distributed under the Boost Software License, Version 1.0. 
sl@0
     8
// (See accompanying file LICENSE_1_0.txt or copy at 
sl@0
     9
// http://www.boost.org/LICENSE_1_0.txt)
sl@0
    10
//
sl@0
    11
// See http://www.boost.org/libs/mpl for documentation.
sl@0
    12
sl@0
    13
// $Source: /cvsroot/boost/boost/boost/mpl/if.hpp,v $
sl@0
    14
// $Date: 2004/09/07 08:51:31 $
sl@0
    15
// $Revision: 1.25 $
sl@0
    16
sl@0
    17
#include <boost/mpl/aux_/value_wknd.hpp>
sl@0
    18
#include <boost/mpl/aux_/static_cast.hpp>
sl@0
    19
#include <boost/mpl/aux_/na_spec.hpp>
sl@0
    20
#include <boost/mpl/aux_/lambda_support.hpp>
sl@0
    21
#include <boost/mpl/aux_/config/integral.hpp>
sl@0
    22
#include <boost/mpl/aux_/config/ctps.hpp>
sl@0
    23
#include <boost/mpl/aux_/config/workaround.hpp>
sl@0
    24
sl@0
    25
namespace boost { namespace mpl {
sl@0
    26
sl@0
    27
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
sl@0
    28
sl@0
    29
template<
sl@0
    30
      bool C
sl@0
    31
    , typename T1
sl@0
    32
    , typename T2
sl@0
    33
    >
sl@0
    34
struct if_c
sl@0
    35
{
sl@0
    36
    typedef T1 type;
sl@0
    37
};
sl@0
    38
sl@0
    39
template<
sl@0
    40
      typename T1
sl@0
    41
    , typename T2
sl@0
    42
    >
sl@0
    43
struct if_c<false,T1,T2>
sl@0
    44
{
sl@0
    45
    typedef T2 type;
sl@0
    46
};
sl@0
    47
sl@0
    48
// agurt, 05/sep/04: nondescriptive parameter names for the sake of DigitalMars
sl@0
    49
// (and possibly MWCW < 8.0); see http://article.gmane.org/gmane.comp.lib.boost.devel/108959
sl@0
    50
template<
sl@0
    51
      typename BOOST_MPL_AUX_NA_PARAM(T1)
sl@0
    52
    , typename BOOST_MPL_AUX_NA_PARAM(T2)
sl@0
    53
    , typename BOOST_MPL_AUX_NA_PARAM(T3)
sl@0
    54
    >
sl@0
    55
struct if_
sl@0
    56
{
sl@0
    57
 private:
sl@0
    58
    // agurt, 02/jan/03: two-step 'type' definition for the sake of aCC 
sl@0
    59
    typedef if_c<
sl@0
    60
#if defined(BOOST_MPL_CFG_BCC_INTEGRAL_CONSTANTS)
sl@0
    61
          BOOST_MPL_AUX_VALUE_WKND(T1)::value
sl@0
    62
#else
sl@0
    63
          BOOST_MPL_AUX_STATIC_CAST(bool, BOOST_MPL_AUX_VALUE_WKND(T1)::value)
sl@0
    64
#endif
sl@0
    65
        , T2
sl@0
    66
        , T3
sl@0
    67
        > almost_type_;
sl@0
    68
 
sl@0
    69
 public:
sl@0
    70
    typedef typename almost_type_::type type;
sl@0
    71
    
sl@0
    72
    BOOST_MPL_AUX_LAMBDA_SUPPORT(3,if_,(T1,T2,T3))
sl@0
    73
};
sl@0
    74
sl@0
    75
#else
sl@0
    76
sl@0
    77
// no partial class template specialization
sl@0
    78
sl@0
    79
namespace aux {
sl@0
    80
sl@0
    81
template< bool C >
sl@0
    82
struct if_impl
sl@0
    83
{
sl@0
    84
    template< typename T1, typename T2 > struct result_
sl@0
    85
    {
sl@0
    86
        typedef T1 type;
sl@0
    87
    };
sl@0
    88
};
sl@0
    89
sl@0
    90
template<>
sl@0
    91
struct if_impl<false>
sl@0
    92
{
sl@0
    93
    template< typename T1, typename T2 > struct result_
sl@0
    94
    { 
sl@0
    95
        typedef T2 type;
sl@0
    96
    };
sl@0
    97
};
sl@0
    98
sl@0
    99
} // namespace aux
sl@0
   100
sl@0
   101
template<
sl@0
   102
      bool C_
sl@0
   103
    , typename T1
sl@0
   104
    , typename T2
sl@0
   105
    >
sl@0
   106
struct if_c
sl@0
   107
{
sl@0
   108
    typedef typename aux::if_impl< C_ >
sl@0
   109
        ::template result_<T1,T2>::type type;
sl@0
   110
};
sl@0
   111
sl@0
   112
// (almost) copy & paste in order to save one more 
sl@0
   113
// recursively nested template instantiation to user
sl@0
   114
template<
sl@0
   115
      typename BOOST_MPL_AUX_NA_PARAM(C_)
sl@0
   116
    , typename BOOST_MPL_AUX_NA_PARAM(T1)
sl@0
   117
    , typename BOOST_MPL_AUX_NA_PARAM(T2)
sl@0
   118
    >
sl@0
   119
struct if_
sl@0
   120
{
sl@0
   121
    enum { msvc_wknd_ = BOOST_MPL_AUX_MSVC_VALUE_WKND(C_)::value };
sl@0
   122
sl@0
   123
    typedef typename aux::if_impl< BOOST_MPL_AUX_STATIC_CAST(bool, msvc_wknd_) >
sl@0
   124
        ::template result_<T1,T2>::type type;
sl@0
   125
sl@0
   126
    BOOST_MPL_AUX_LAMBDA_SUPPORT(3,if_,(C_,T1,T2))
sl@0
   127
};
sl@0
   128
sl@0
   129
#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
sl@0
   130
sl@0
   131
BOOST_MPL_AUX_NA_SPEC(3, if_)
sl@0
   132
sl@0
   133
}}
sl@0
   134
sl@0
   135
#endif // BOOST_MPL_IF_HPP_INCLUDED