~ubuntu-branches/ubuntu/warty/aqsis/warty

« back to all changes in this revision

Viewing changes to boost/boost/pending/ct_if.hpp

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-08-24 07:25:04 UTC
  • Revision ID: james.westby@ubuntu.com-20040824072504-zf993vnevvisdsvb
Tags: upstream-0.9.1
ImportĀ upstreamĀ versionĀ 0.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// (C) Copyright Jeremy Siek 2000. Permission to copy, use, modify, sell and
 
2
// distribute this software is granted provided this copyright notice appears
 
3
// in all copies. This software is provided "as is" without express or implied
 
4
// warranty, and with no claim as to its suitability for any purpose.
 
5
 
 
6
// The ct_if implementation that avoids partial specialization is
 
7
// based on the IF class by Ulrich W. Eisenecker and Krzysztof
 
8
// Czarnecki.
 
9
 
 
10
#ifndef BOOST_CT_IF_HPP
 
11
#define BOOST_CT_IF_HPP
 
12
 
 
13
#include <boost/config.hpp>
 
14
 
 
15
/*
 
16
  There is a bug in the Borland compiler with regards to using
 
17
  integers to specialize templates. This made it hard to use ct_if in
 
18
  the graph library. Changing from 'ct_if' to 'ct_if_t' fixed the
 
19
  problem.
 
20
*/
 
21
 
 
22
namespace boost {
 
23
 
 
24
  struct ct_if_error { };
 
25
 
 
26
  struct true_type { enum { value = true }; };
 
27
  struct false_type { enum { value = false }; };
 
28
 
 
29
  template <class A, class B>
 
30
  struct ct_and { typedef false_type type; };
 
31
  template <> struct ct_and<true_type,true_type> { typedef true_type type; };
 
32
 
 
33
  template <class A> struct ct_not { typedef ct_if_error type; };
 
34
  template <> struct ct_not<true_type> { typedef false_type type; };
 
35
  template <> struct ct_not<false_type> { typedef true_type type; };
 
36
 
 
37
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
 
38
 
 
39
// agurt, 15/sep/02: in certain cases Borland has problems with
 
40
// choosing the right 'ct_if' specialization even though 'cond' 
 
41
// _does_ equal '1'; the easiest way to fix it is to make first 
 
42
// 'ct_if' non-type template parameter boolean.
 
43
#if !defined(__BORLANDC__)
 
44
  template <bool cond, class A, class B>
 
45
  struct ct_if { typedef ct_if_error type; };
 
46
  template <class A, class B>
 
47
  struct ct_if<true, A, B> { typedef A type; };
 
48
  template <class A, class B>
 
49
  struct ct_if<false, A, B> { typedef B type; };
 
50
#else
 
51
  template <bool cond, class A, class B>
 
52
  struct ct_if { typedef A type; };
 
53
  template <class A, class B>
 
54
  struct ct_if<false, A, B> { typedef B type; };
 
55
#endif
 
56
 
 
57
  template <class cond, class A, class B>
 
58
  struct ct_if_t { typedef ct_if_error type; };
 
59
  template <class A, class B>
 
60
  struct ct_if_t<true_type, A, B> { typedef A type; };
 
61
  template <class A, class B>
 
62
  struct ct_if_t<false_type, A, B> { typedef B type; };
 
63
 
 
64
#else
 
65
 
 
66
  namespace detail {
 
67
 
 
68
    template <int condition, class A, class B> struct IF;
 
69
    template <int condition> struct SlectSelector;
 
70
    struct SelectFirstType;
 
71
    struct SelectSecondType;
 
72
    
 
73
    struct SelectFirstType {
 
74
      template<class A, class B>
 
75
      struct Template {        typedef A type; };
 
76
    };
 
77
    
 
78
    struct SelectSecondType {
 
79
      template<class A, class B>
 
80
      struct Template { typedef B type; };
 
81
    };
 
82
    
 
83
    template<int condition>
 
84
    struct SlectSelector {
 
85
      typedef SelectFirstType type;
 
86
    };
 
87
    
 
88
    template <>
 
89
    struct SlectSelector<0> {
 
90
      typedef SelectSecondType type;
 
91
    };
 
92
 
 
93
  } // namespace detail
 
94
    
 
95
  template<int condition, class A, class B>
 
96
  struct ct_if
 
97
  {
 
98
    typedef typename detail::SlectSelector<condition>::type Selector;
 
99
    typedef typename Selector::template Template<A, B>::type type;
 
100
  };
 
101
  
 
102
  template <class cond, class A, class B>
 
103
  struct ct_if_t { 
 
104
    typedef typename ct_if<cond::value, A, B>::type type;
 
105
  };
 
106
 
 
107
#endif
 
108
 
 
109
} // namespace boost
 
110
 
 
111
#endif // BOOST_CT_IF_HPP
 
112