1 // © 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)
6 // See library home page at http://www.boost.org/libs/numeric/conversion
8 // Contact the author at: fernando_cacciola@hotmail.com
10 #ifndef BOOST_NUMERIC_CONVERSION_DETAIL_CONVERSION_TRAITS_FLC_12NOV2002_HPP
11 #define BOOST_NUMERIC_CONVERSION_DETAIL_CONVERSION_TRAITS_FLC_12NOV2002_HPP
13 #include "boost/type_traits/is_arithmetic.hpp"
14 #include "boost/type_traits/is_same.hpp"
15 #include "boost/type_traits/remove_cv.hpp"
17 #include "boost/numeric/conversion/detail/meta.hpp"
18 #include "boost/numeric/conversion/detail/int_float_mixture.hpp"
19 #include "boost/numeric/conversion/detail/sign_mixture.hpp"
20 #include "boost/numeric/conversion/detail/udt_builtin_mixture.hpp"
21 #include "boost/numeric/conversion/detail/is_subranged.hpp"
23 namespace boost { namespace numeric { namespace convdetail
25 //-------------------------------------------------------------------
26 // Implementation of the Conversion Traits for T != S
28 // This is a VISIBLE base class of the user-level conversion_traits<> class.
29 //-------------------------------------------------------------------
30 template<class T,class S>
31 struct non_trivial_traits_impl
33 typedef typename get_int_float_mixture <T,S>::type int_float_mixture ;
34 typedef typename get_sign_mixture <T,S>::type sign_mixture ;
35 typedef typename get_udt_builtin_mixture <T,S>::type udt_builtin_mixture ;
37 typedef typename get_is_subranged<T,S>::type subranged ;
39 typedef mpl::false_ trivial ;
41 typedef T target_type ;
42 typedef S source_type ;
43 typedef T result_type ;
45 typedef typename mpl::if_< is_arithmetic<S>, S, S const&>::type argument_type ;
47 typedef typename mpl::if_<subranged,S,T>::type supertype ;
48 typedef typename mpl::if_<subranged,T,S>::type subtype ;
51 //-------------------------------------------------------------------
52 // Implementation of the Conversion Traits for T == S
54 // This is a VISIBLE base class of the user-level conversion_traits<> class.
55 //-------------------------------------------------------------------
57 struct trivial_traits_impl
59 typedef typename get_int_float_mixture <N,N>::type int_float_mixture ;
60 typedef typename get_sign_mixture <N,N>::type sign_mixture ;
61 typedef typename get_udt_builtin_mixture<N,N>::type udt_builtin_mixture ;
63 typedef mpl::false_ subranged ;
64 typedef mpl::true_ trivial ;
66 typedef N target_type ;
67 typedef N source_type ;
68 typedef N const& result_type ;
69 typedef N const& argument_type ;
76 //-------------------------------------------------------------------
77 // Top level implementation selector.
78 //-------------------------------------------------------------------
79 template<class T, class S>
80 struct get_conversion_traits
82 typedef typename remove_cv<T>::type target_type ;
83 typedef typename remove_cv<S>::type source_type ;
85 typedef typename is_same<target_type,source_type>::type is_trivial ;
87 typedef trivial_traits_impl <target_type> trivial_imp ;
88 typedef non_trivial_traits_impl<target_type,source_type> non_trivial_imp ;
90 typedef typename mpl::if_<is_trivial,trivial_imp,non_trivial_imp>::type type ;
93 } } } // namespace boost::numeric::convdetail