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.
6 // The ct_if implementation that avoids partial specialization is
7 // based on the IF class by Ulrich W. Eisenecker and Krzysztof
10 #ifndef BOOST_CT_IF_HPP
11 #define BOOST_CT_IF_HPP
13 #include <boost/config.hpp>
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
24 struct ct_if_error { };
26 struct true_type { enum { value = true }; };
27 struct false_type { enum { value = false }; };
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; };
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; };
37 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
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; };
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; };
57 template <int condition, class A, class B> struct IF;
58 template <int condition> struct SlectSelector;
59 struct SelectFirstType;
60 struct SelectSecondType;
62 struct SelectFirstType {
63 template<class A, class B>
64 struct Template { typedef A type; };
67 struct SelectSecondType {
68 template<class A, class B>
69 struct Template { typedef B type; };
72 template<int condition>
73 struct SlectSelector {
74 typedef SelectFirstType type;
78 struct SlectSelector<0> {
79 typedef SelectSecondType type;
84 template<int condition, class A, class B>
87 typedef typename detail::SlectSelector<condition>::type Selector;
88 typedef typename Selector::template Template<A, B>::type type;
91 template <class cond, class A, class B>
93 typedef typename ct_if<cond::value, A, B>::type type;
100 #endif // BOOST_CT_IF_HPP