Chris@16
|
1 // (c) Copyright Fernando Luis Cacciola Carballal 2000-2004
|
Chris@16
|
2 // Use, modification, and distribution is subject to the Boost Software
|
Chris@16
|
3 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
4 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
5
|
Chris@16
|
6 // See library home page at http://www.boost.org/libs/numeric/conversion
|
Chris@16
|
7 //
|
Chris@16
|
8 // Contact the author at: fernando_cacciola@hotmail.com
|
Chris@16
|
9 //
|
Chris@16
|
10 #ifndef BOOST_NUMERIC_CONVERSION_DETAIL_META_FLC_12NOV2002_HPP
|
Chris@16
|
11 #define BOOST_NUMERIC_CONVERSION_DETAIL_META_FLC_12NOV2002_HPP
|
Chris@16
|
12
|
Chris@16
|
13 #include "boost/type_traits/remove_cv.hpp"
|
Chris@16
|
14
|
Chris@16
|
15 #include "boost/mpl/if.hpp"
|
Chris@16
|
16 #include "boost/mpl/eval_if.hpp"
|
Chris@16
|
17 #include "boost/mpl/equal_to.hpp"
|
Chris@16
|
18 #include "boost/mpl/not.hpp"
|
Chris@16
|
19 #include "boost/mpl/and.hpp"
|
Chris@16
|
20 #include "boost/mpl/bool.hpp"
|
Chris@16
|
21 #include "boost/mpl/identity.hpp"
|
Chris@16
|
22
|
Chris@16
|
23 namespace boost { namespace numeric { namespace convdetail
|
Chris@16
|
24 {
|
Chris@16
|
25 template< class T1, class T2>
|
Chris@16
|
26 struct equal_to
|
Chris@16
|
27 {
|
Chris@16
|
28 #if !defined(__BORLANDC__)
|
Chris@16
|
29
|
Chris@16
|
30 enum { x = ( BOOST_MPL_AUX_VALUE_WKND(T1)::value == BOOST_MPL_AUX_VALUE_WKND(T2)::value ) };
|
Chris@16
|
31
|
Chris@16
|
32 BOOST_STATIC_CONSTANT(bool, value = x);
|
Chris@16
|
33
|
Chris@16
|
34 typedef mpl::bool_<value> type;
|
Chris@16
|
35
|
Chris@16
|
36 #else
|
Chris@16
|
37
|
Chris@16
|
38 BOOST_STATIC_CONSTANT(bool, value = (
|
Chris@16
|
39 BOOST_MPL_AUX_VALUE_WKND(T1)::value
|
Chris@16
|
40 == BOOST_MPL_AUX_VALUE_WKND(T2)::value
|
Chris@16
|
41 ));
|
Chris@16
|
42
|
Chris@16
|
43 typedef mpl::bool_<(
|
Chris@16
|
44 BOOST_MPL_AUX_VALUE_WKND(T1)::value
|
Chris@16
|
45 == BOOST_MPL_AUX_VALUE_WKND(T2)::value
|
Chris@16
|
46 )> type;
|
Chris@16
|
47 #endif
|
Chris@16
|
48 };
|
Chris@16
|
49
|
Chris@16
|
50 // Metafunction:
|
Chris@16
|
51 //
|
Chris@16
|
52 // ct_switch4<Value,Case0Val,Case1Val,Case2Val,Case0Type,Case1Type,Case2Type,DefaultType>::type
|
Chris@16
|
53 //
|
Chris@16
|
54 // {Value,Case(X)Val} are Integral Constants (such as: mpl::int_<>)
|
Chris@16
|
55 // {Case(X)Type,DefaultType} are arbitrary types. (not metafunctions)
|
Chris@16
|
56 //
|
Chris@16
|
57 // Returns Case(X)Type if Val==Case(X)Val; DefaultType otherwise.
|
Chris@16
|
58 //
|
Chris@16
|
59 template<class Value,
|
Chris@16
|
60 class Case0Val,
|
Chris@16
|
61 class Case1Val,
|
Chris@16
|
62 class Case2Val,
|
Chris@16
|
63 class Case0Type,
|
Chris@16
|
64 class Case1Type,
|
Chris@16
|
65 class Case2Type,
|
Chris@16
|
66 class DefaultType
|
Chris@16
|
67 >
|
Chris@16
|
68 struct ct_switch4
|
Chris@16
|
69 {
|
Chris@16
|
70 typedef mpl::identity<Case0Type> Case0TypeQ ;
|
Chris@16
|
71 typedef mpl::identity<Case1Type> Case1TypeQ ;
|
Chris@16
|
72
|
Chris@16
|
73 typedef equal_to<Value,Case0Val> is_case0 ;
|
Chris@16
|
74 typedef equal_to<Value,Case1Val> is_case1 ;
|
Chris@16
|
75 typedef equal_to<Value,Case2Val> is_case2 ;
|
Chris@16
|
76
|
Chris@16
|
77 typedef mpl::if_<is_case2,Case2Type,DefaultType> choose_2_3Q ;
|
Chris@16
|
78 typedef mpl::eval_if<is_case1,Case1TypeQ,choose_2_3Q> choose_1_2_3Q ;
|
Chris@16
|
79
|
Chris@16
|
80 typedef typename
|
Chris@16
|
81 mpl::eval_if<is_case0,Case0TypeQ,choose_1_2_3Q>::type
|
Chris@16
|
82 type ;
|
Chris@16
|
83 } ;
|
Chris@16
|
84
|
Chris@16
|
85
|
Chris@16
|
86
|
Chris@16
|
87
|
Chris@16
|
88 // Metafunction:
|
Chris@16
|
89 //
|
Chris@16
|
90 // for_both<expr0,expr1,TT,TF,FT,FF>::type
|
Chris@16
|
91 //
|
Chris@16
|
92 // {exp0,expr1} are Boolean Integral Constants
|
Chris@16
|
93 // {TT,TF,FT,FF} are aribtrary types. (not metafunctions)
|
Chris@16
|
94 //
|
Chris@16
|
95 // According to the combined boolean value of 'expr0 && expr1', selects the corresponding type.
|
Chris@16
|
96 //
|
Chris@16
|
97 template<class expr0, class expr1, class TT, class TF, class FT, class FF>
|
Chris@16
|
98 struct for_both
|
Chris@16
|
99 {
|
Chris@16
|
100 typedef mpl::identity<TF> TF_Q ;
|
Chris@16
|
101 typedef mpl::identity<TT> TT_Q ;
|
Chris@16
|
102
|
Chris@16
|
103 typedef typename mpl::not_<expr0>::type not_expr0 ;
|
Chris@16
|
104 typedef typename mpl::not_<expr1>::type not_expr1 ;
|
Chris@16
|
105
|
Chris@16
|
106 typedef typename mpl::and_<expr0,expr1>::type caseTT ;
|
Chris@16
|
107 typedef typename mpl::and_<expr0,not_expr1>::type caseTF ;
|
Chris@16
|
108 typedef typename mpl::and_<not_expr0,expr1>::type caseFT ;
|
Chris@16
|
109
|
Chris@16
|
110 typedef mpl::if_<caseFT,FT,FF> choose_FT_FF_Q ;
|
Chris@16
|
111 typedef mpl::eval_if<caseTF,TF_Q,choose_FT_FF_Q> choose_TF_FT_FF_Q ;
|
Chris@16
|
112
|
Chris@16
|
113 typedef typename mpl::eval_if<caseTT,TT_Q,choose_TF_FT_FF_Q>::type type ;
|
Chris@16
|
114 } ;
|
Chris@16
|
115
|
Chris@16
|
116 } } } // namespace boost::numeric::convdetail
|
Chris@16
|
117
|
Chris@16
|
118 #endif
|
Chris@16
|
119
|
Chris@16
|
120
|