1
// (C) Copyright Jeremy Siek 2000.
2
// Distributed under the Boost Software License, Version 1.0. (See
3
// accompanying file LICENSE_1_0.txt or copy at
4
// http://www.boost.org/LICENSE_1_0.txt)
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
22
#include <boost/type_traits/integral_constant.hpp> // true_type and false_type
26
struct ct_if_error { };
28
template <class A, class B>
29
struct ct_and { typedef false_type type; };
30
template <> struct ct_and<true_type,true_type> { typedef true_type type; };
32
template <class A> struct ct_not { typedef ct_if_error type; };
33
template <> struct ct_not<true_type> { typedef false_type type; };
34
template <> struct ct_not<false_type> { typedef true_type type; };
36
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
38
// agurt, 15/sep/02: in certain cases Borland has problems with
39
// choosing the right 'ct_if' specialization even though 'cond'
40
// _does_ equal '1'; the easiest way to fix it is to make first
41
// 'ct_if' non-type template parameter boolean.
42
#if !defined(__BORLANDC__)
43
template <bool cond, class A, class B>
44
struct ct_if { typedef ct_if_error type; };
45
template <class A, class B>
46
struct ct_if<true, A, B> { typedef A type; };
47
template <class A, class B>
48
struct ct_if<false, A, B> { typedef B type; };
50
template <bool cond, class A, class B>
51
struct ct_if { typedef A type; };
52
template <class A, class B>
53
struct ct_if<false, A, B> { typedef B type; };
56
template <class cond, class A, class B>
57
struct ct_if_t { typedef ct_if_error type; };
58
template <class A, class B>
59
struct ct_if_t<true_type, A, B> { typedef A type; };
60
template <class A, class B>
61
struct ct_if_t<false_type, A, B> { typedef B type; };
67
template <int condition, class A, class B> struct IF;
68
template <int condition> struct SlectSelector;
69
struct SelectFirstType;
70
struct SelectSecondType;
72
struct SelectFirstType {
73
template<class A, class B>
74
struct Template { typedef A type; };
77
struct SelectSecondType {
78
template<class A, class B>
79
struct Template { typedef B type; };
82
template<int condition>
83
struct SlectSelector {
84
typedef SelectFirstType type;
88
struct SlectSelector<0> {
89
typedef SelectSecondType type;
94
template<int condition, class A, class B>
97
typedef typename detail::SlectSelector<condition>::type Selector;
98
typedef typename Selector::template Template<A, B>::type type;
101
template <class cond, class A, class B>
103
typedef typename ct_if<cond::value, A, B>::type type;
110
#endif // BOOST_CT_IF_HPP