]> git.lyx.org Git - lyx.git/blob - boost/boost/pending/ct_if.hpp
1655cfab5ab3b8390d8f747d94965f6cf193ec52
[lyx.git] / boost / boost / pending / ct_if.hpp
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   template <int cond, class A, class B>
40   struct ct_if { typedef ct_if_error type; };
41   template <class A, class B>
42   struct ct_if<1, A, B> { typedef A type; };
43   template <class A, class B>
44   struct ct_if<0, A, B> { typedef B type; };
45
46   template <class cond, class A, class B>
47   struct ct_if_t { typedef ct_if_error type; };
48   template <class A, class B>
49   struct ct_if_t<true_type, A, B> { typedef A type; };
50   template <class A, class B>
51   struct ct_if_t<false_type, A, B> { typedef B type; };
52
53 #else
54
55   namespace detail {
56
57     template <int condition, class A, class B> struct IF;
58     template <int condition> struct SlectSelector;
59     struct SelectFirstType;
60     struct SelectSecondType;
61     
62     struct SelectFirstType {
63       template<class A, class B>
64       struct Template {        typedef A type; };
65     };
66     
67     struct SelectSecondType {
68       template<class A, class B>
69       struct Template { typedef B type; };
70     };
71     
72     template<int condition>
73     struct SlectSelector {
74       typedef SelectFirstType type;
75     };
76     
77     template <>
78     struct SlectSelector<0> {
79       typedef SelectSecondType type;
80     };
81
82   } // namespace detail
83     
84   template<int condition, class A, class B>
85   struct ct_if
86   {
87     typedef typename detail::SlectSelector<condition>::type Selector;
88     typedef typename Selector::template Template<A, B>::type type;
89   };
90   
91   template <class cond, class A, class B>
92   struct ct_if_t { 
93     typedef typename ct_if<cond::value, A, B>::type type;
94   };
95
96 #endif
97
98 } // namespace boost
99
100 #endif // BOOST_CT_IF_HPP
101