sl@0: // (C) Copyright Jeremy Siek 2000. sl@0: // Distributed under the Boost Software License, Version 1.0. (See sl@0: // accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: sl@0: // The ct_if implementation that avoids partial specialization is sl@0: // based on the IF class by Ulrich W. Eisenecker and Krzysztof sl@0: // Czarnecki. sl@0: sl@0: #ifndef BOOST_CT_IF_HPP sl@0: #define BOOST_CT_IF_HPP sl@0: sl@0: #include sl@0: sl@0: /* sl@0: There is a bug in the Borland compiler with regards to using sl@0: integers to specialize templates. This made it hard to use ct_if in sl@0: the graph library. Changing from 'ct_if' to 'ct_if_t' fixed the sl@0: problem. sl@0: */ sl@0: sl@0: #include // true_type and false_type sl@0: sl@0: namespace boost { sl@0: sl@0: struct ct_if_error { }; sl@0: sl@0: template sl@0: struct ct_and { typedef false_type type; }; sl@0: template <> struct ct_and { typedef true_type type; }; sl@0: sl@0: template struct ct_not { typedef ct_if_error type; }; sl@0: template <> struct ct_not { typedef false_type type; }; sl@0: template <> struct ct_not { typedef true_type type; }; sl@0: sl@0: #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION sl@0: sl@0: // agurt, 15/sep/02: in certain cases Borland has problems with sl@0: // choosing the right 'ct_if' specialization even though 'cond' sl@0: // _does_ equal '1'; the easiest way to fix it is to make first sl@0: // 'ct_if' non-type template parameter boolean. sl@0: #if !defined(__BORLANDC__) sl@0: template sl@0: struct ct_if { typedef ct_if_error type; }; sl@0: template sl@0: struct ct_if { typedef A type; }; sl@0: template sl@0: struct ct_if { typedef B type; }; sl@0: #else sl@0: template sl@0: struct ct_if { typedef A type; }; sl@0: template sl@0: struct ct_if { typedef B type; }; sl@0: #endif sl@0: sl@0: template sl@0: struct ct_if_t { typedef ct_if_error type; }; sl@0: template sl@0: struct ct_if_t { typedef A type; }; sl@0: template sl@0: struct ct_if_t { typedef B type; }; sl@0: sl@0: #else sl@0: sl@0: namespace detail { sl@0: sl@0: template struct IF; sl@0: template struct SlectSelector; sl@0: struct SelectFirstType; sl@0: struct SelectSecondType; sl@0: sl@0: struct SelectFirstType { sl@0: template sl@0: struct Template { typedef A type; }; sl@0: }; sl@0: sl@0: struct SelectSecondType { sl@0: template sl@0: struct Template { typedef B type; }; sl@0: }; sl@0: sl@0: template sl@0: struct SlectSelector { sl@0: typedef SelectFirstType type; sl@0: }; sl@0: sl@0: template <> sl@0: struct SlectSelector<0> { sl@0: typedef SelectSecondType type; sl@0: }; sl@0: sl@0: } // namespace detail sl@0: sl@0: template sl@0: struct ct_if sl@0: { sl@0: typedef typename detail::SlectSelector::type Selector; sl@0: typedef typename Selector::template Template::type type; sl@0: }; sl@0: sl@0: template sl@0: struct ct_if_t { sl@0: typedef typename ct_if::type type; sl@0: }; sl@0: sl@0: #endif sl@0: sl@0: } // namespace boost sl@0: sl@0: #endif // BOOST_CT_IF_HPP sl@0: