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
// 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; };
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; };
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; };
68
template <int condition, class A, class B> struct IF;
69
template <int condition> struct SlectSelector;
70
struct SelectFirstType;
71
struct SelectSecondType;
73
struct SelectFirstType {
74
template<class A, class B>
75
struct Template { typedef A type; };
78
struct SelectSecondType {
79
template<class A, class B>
80
struct Template { typedef B type; };
83
template<int condition>
84
struct SlectSelector {
85
typedef SelectFirstType type;
89
struct SlectSelector<0> {
90
typedef SelectSecondType type;
95
template<int condition, class A, class B>
98
typedef typename detail::SlectSelector<condition>::type Selector;
99
typedef typename Selector::template Template<A, B>::type type;
102
template <class cond, class A, class B>
104
typedef typename ct_if<cond::value, A, B>::type type;
111
#endif // BOOST_CT_IF_HPP