12ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh//  (c) Copyright Fernando Luis Cacciola Carballal 2000-2004
22ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh//  Use, modification, and distribution is subject to the Boost Software
32ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh//  License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
42ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh//  http://www.boost.org/LICENSE_1_0.txt)
52ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh
62ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh//  See library home page at http://www.boost.org/libs/numeric/conversion
72ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh//
82ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh// Contact the author at: fernando_cacciola@hotmail.com
92ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh//
102ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh#ifndef BOOST_NUMERIC_CONVERSION_DETAIL_META_FLC_12NOV2002_HPP
112ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh#define BOOST_NUMERIC_CONVERSION_DETAIL_META_FLC_12NOV2002_HPP
122ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh
132ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh#include "boost/type_traits/remove_cv.hpp"
142ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh
152ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh#include "boost/mpl/if.hpp"
162ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh#include "boost/mpl/eval_if.hpp"
172ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh#include "boost/mpl/equal_to.hpp"
182ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh#include "boost/mpl/not.hpp"
192ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh#include "boost/mpl/and.hpp"
202ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh#include "boost/mpl/bool.hpp"
212ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh#include "boost/mpl/identity.hpp"
222ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh
232ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsiehnamespace boost { namespace numeric { namespace convdetail
242ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh{
252ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh   template< class T1, class T2>
262ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh   struct equal_to
272ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh   {
282ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh   #if !defined(__BORLANDC__)
292ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh
302ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh       enum { x = ( BOOST_MPL_AUX_VALUE_WKND(T1)::value == BOOST_MPL_AUX_VALUE_WKND(T2)::value ) };
312ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh
322ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh       BOOST_STATIC_CONSTANT(bool, value = x);
332ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh
342ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh       typedef mpl::bool_<value> type;
352ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh
362ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh   #else
372ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh
382ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh       BOOST_STATIC_CONSTANT(bool, value = (
392ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh             BOOST_MPL_AUX_VALUE_WKND(T1)::value
402ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh               == BOOST_MPL_AUX_VALUE_WKND(T2)::value
412ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh           ));
422ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh
432ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh       typedef mpl::bool_<(
442ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh             BOOST_MPL_AUX_VALUE_WKND(T1)::value
452ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh               == BOOST_MPL_AUX_VALUE_WKND(T2)::value
462ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh           )> type;
472ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh   #endif
482ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh   };
492ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh
502ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh// Metafunction:
512ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh  //
522ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh  //   ct_switch4<Value,Case0Val,Case1Val,Case2Val,Case0Type,Case1Type,Case2Type,DefaultType>::type
532ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh  //
542ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh  // {Value,Case(X)Val} are Integral Constants (such as: mpl::int_<>)
552ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh  // {Case(X)Type,DefaultType} are arbitrary types. (not metafunctions)
562ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh  //
572ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh  // Returns Case(X)Type if Val==Case(X)Val; DefaultType otherwise.
582ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh  //
592ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh  template<class Value,
602ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh           class Case0Val,
612ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh           class Case1Val,
622ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh           class Case2Val,
632ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh           class Case0Type,
642ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh           class Case1Type,
652ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh           class Case2Type,
662ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh           class DefaultType
672ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh          >
682ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh  struct ct_switch4
692ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh  {
702ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh    typedef mpl::identity<Case0Type> Case0TypeQ ;
712ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh    typedef mpl::identity<Case1Type> Case1TypeQ ;
722ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh
732ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh    typedef equal_to<Value,Case0Val> is_case0 ;
742ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh    typedef equal_to<Value,Case1Val> is_case1 ;
752ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh    typedef equal_to<Value,Case2Val> is_case2 ;
762ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh
772ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh    typedef mpl::if_<is_case2,Case2Type,DefaultType> choose_2_3Q ;
782ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh    typedef mpl::eval_if<is_case1,Case1TypeQ,choose_2_3Q> choose_1_2_3Q ;
792ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh
802ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh    typedef typename
812ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh      mpl::eval_if<is_case0,Case0TypeQ,choose_1_2_3Q>::type
822ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh        type ;
832ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh  } ;
842ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh
852ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh
862ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh
872ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh
882ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh  // Metafunction:
892ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh  //
902ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh  //   for_both<expr0,expr1,TT,TF,FT,FF>::type
912ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh  //
922ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh  // {exp0,expr1} are Boolean Integral Constants
932ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh  // {TT,TF,FT,FF} are aribtrary types. (not metafunctions)
942ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh  //
952ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh  // According to the combined boolean value of 'expr0 && expr1', selects the corresponding type.
962ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh  //
972ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh  template<class expr0, class expr1, class TT, class TF, class FT, class FF>
982ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh  struct for_both
992ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh  {
1002ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh    typedef mpl::identity<TF> TF_Q ;
1012ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh    typedef mpl::identity<TT> TT_Q ;
1022ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh
1032ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh    typedef typename mpl::not_<expr0>::type not_expr0 ;
1042ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh    typedef typename mpl::not_<expr1>::type not_expr1 ;
1052ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh
1062ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh    typedef typename mpl::and_<expr0,expr1>::type     caseTT ;
1072ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh    typedef typename mpl::and_<expr0,not_expr1>::type caseTF ;
1082ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh    typedef typename mpl::and_<not_expr0,expr1>::type caseFT ;
1092ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh
1102ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh    typedef mpl::if_<caseFT,FT,FF>                    choose_FT_FF_Q ;
1112ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh    typedef mpl::eval_if<caseTF,TF_Q,choose_FT_FF_Q> choose_TF_FT_FF_Q ;
1122ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh
1132ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh    typedef typename mpl::eval_if<caseTT,TT_Q,choose_TF_FT_FF_Q>::type type ;
1142ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh  } ;
1152ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh
1162ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh} } } // namespace boost::numeric::convdetail
1172ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh
1182ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh#endif
1192ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh
1202ca0e41376e99ad53c02fdb5333339ad3dcad19fAndrew Hsieh
121