os/ossrv/ossrv_pub/boost_apis/boost/pending/ct_if.hpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200 (2012-06-15)
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// (C) Copyright Jeremy Siek 2000.
sl@0
     2
// Distributed under the Boost Software License, Version 1.0. (See
sl@0
     3
// accompanying file LICENSE_1_0.txt or copy at
sl@0
     4
// http://www.boost.org/LICENSE_1_0.txt)
sl@0
     5
sl@0
     6
// The ct_if implementation that avoids partial specialization is
sl@0
     7
// based on the IF class by Ulrich W. Eisenecker and Krzysztof
sl@0
     8
// Czarnecki.
sl@0
     9
sl@0
    10
#ifndef BOOST_CT_IF_HPP
sl@0
    11
#define BOOST_CT_IF_HPP
sl@0
    12
sl@0
    13
#include <boost/config.hpp>
sl@0
    14
sl@0
    15
/*
sl@0
    16
  There is a bug in the Borland compiler with regards to using
sl@0
    17
  integers to specialize templates. This made it hard to use ct_if in
sl@0
    18
  the graph library. Changing from 'ct_if' to 'ct_if_t' fixed the
sl@0
    19
  problem.
sl@0
    20
*/
sl@0
    21
sl@0
    22
#include <boost/type_traits/integral_constant.hpp> // true_type and false_type
sl@0
    23
sl@0
    24
namespace boost {
sl@0
    25
sl@0
    26
  struct ct_if_error { };
sl@0
    27
sl@0
    28
  template <class A, class B>
sl@0
    29
  struct ct_and { typedef false_type type; };
sl@0
    30
  template <> struct ct_and<true_type,true_type> { typedef true_type type; };
sl@0
    31
sl@0
    32
  template <class A> struct ct_not { typedef ct_if_error type; };
sl@0
    33
  template <> struct ct_not<true_type> { typedef false_type type; };
sl@0
    34
  template <> struct ct_not<false_type> { typedef true_type type; };
sl@0
    35
sl@0
    36
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
sl@0
    37
sl@0
    38
// agurt, 15/sep/02: in certain cases Borland has problems with
sl@0
    39
// choosing the right 'ct_if' specialization even though 'cond' 
sl@0
    40
// _does_ equal '1'; the easiest way to fix it is to make first 
sl@0
    41
// 'ct_if' non-type template parameter boolean.
sl@0
    42
#if !defined(__BORLANDC__)
sl@0
    43
  template <bool cond, class A, class B>
sl@0
    44
  struct ct_if { typedef ct_if_error type; };
sl@0
    45
  template <class A, class B>
sl@0
    46
  struct ct_if<true, A, B> { typedef A type; };
sl@0
    47
  template <class A, class B>
sl@0
    48
  struct ct_if<false, A, B> { typedef B type; };
sl@0
    49
#else
sl@0
    50
  template <bool cond, class A, class B>
sl@0
    51
  struct ct_if { typedef A type; };
sl@0
    52
  template <class A, class B>
sl@0
    53
  struct ct_if<false, A, B> { typedef B type; };
sl@0
    54
#endif
sl@0
    55
sl@0
    56
  template <class cond, class A, class B>
sl@0
    57
  struct ct_if_t { typedef ct_if_error type; };
sl@0
    58
  template <class A, class B>
sl@0
    59
  struct ct_if_t<true_type, A, B> { typedef A type; };
sl@0
    60
  template <class A, class B>
sl@0
    61
  struct ct_if_t<false_type, A, B> { typedef B type; };
sl@0
    62
sl@0
    63
#else
sl@0
    64
sl@0
    65
  namespace detail {
sl@0
    66
sl@0
    67
    template <int condition, class A, class B> struct IF;
sl@0
    68
    template <int condition> struct SlectSelector;
sl@0
    69
    struct SelectFirstType;
sl@0
    70
    struct SelectSecondType;
sl@0
    71
    
sl@0
    72
    struct SelectFirstType {
sl@0
    73
      template<class A, class B>
sl@0
    74
      struct Template {        typedef A type; };
sl@0
    75
    };
sl@0
    76
    
sl@0
    77
    struct SelectSecondType {
sl@0
    78
      template<class A, class B>
sl@0
    79
      struct Template { typedef B type; };
sl@0
    80
    };
sl@0
    81
    
sl@0
    82
    template<int condition>
sl@0
    83
    struct SlectSelector {
sl@0
    84
      typedef SelectFirstType type;
sl@0
    85
    };
sl@0
    86
    
sl@0
    87
    template <>
sl@0
    88
    struct SlectSelector<0> {
sl@0
    89
      typedef SelectSecondType type;
sl@0
    90
    };
sl@0
    91
sl@0
    92
  } // namespace detail
sl@0
    93
    
sl@0
    94
  template<int condition, class A, class B>
sl@0
    95
  struct ct_if
sl@0
    96
  {
sl@0
    97
    typedef typename detail::SlectSelector<condition>::type Selector;
sl@0
    98
    typedef typename Selector::template Template<A, B>::type type;
sl@0
    99
  };
sl@0
   100
  
sl@0
   101
  template <class cond, class A, class B>
sl@0
   102
  struct ct_if_t { 
sl@0
   103
    typedef typename ct_if<cond::value, A, B>::type type;
sl@0
   104
  };
sl@0
   105
sl@0
   106
#endif
sl@0
   107
sl@0
   108
} // namespace boost
sl@0
   109
sl@0
   110
#endif // BOOST_CT_IF_HPP
sl@0
   111