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