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