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) |
---|
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_CONVERSION_TRAITS_FLC_12NOV2002_HPP |
---|
11 | #define BOOST_NUMERIC_CONVERSION_DETAIL_CONVERSION_TRAITS_FLC_12NOV2002_HPP |
---|
12 | |
---|
13 | #include "boost/type_traits/is_arithmetic.hpp" |
---|
14 | #include "boost/type_traits/is_same.hpp" |
---|
15 | #include "boost/type_traits/remove_cv.hpp" |
---|
16 | |
---|
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" |
---|
22 | |
---|
23 | namespace boost { namespace numeric { namespace convdetail |
---|
24 | { |
---|
25 | //------------------------------------------------------------------- |
---|
26 | // Implementation of the Conversion Traits for T != S |
---|
27 | // |
---|
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 |
---|
32 | { |
---|
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 ; |
---|
36 | |
---|
37 | typedef typename get_is_subranged<T,S>::type subranged ; |
---|
38 | |
---|
39 | typedef mpl::false_ trivial ; |
---|
40 | |
---|
41 | typedef T target_type ; |
---|
42 | typedef S source_type ; |
---|
43 | typedef T result_type ; |
---|
44 | |
---|
45 | typedef typename mpl::if_< is_arithmetic<S>, S, S const&>::type argument_type ; |
---|
46 | |
---|
47 | typedef typename mpl::if_<subranged,S,T>::type supertype ; |
---|
48 | typedef typename mpl::if_<subranged,T,S>::type subtype ; |
---|
49 | } ; |
---|
50 | |
---|
51 | //------------------------------------------------------------------- |
---|
52 | // Implementation of the Conversion Traits for T == S |
---|
53 | // |
---|
54 | // This is a VISIBLE base class of the user-level conversion_traits<> class. |
---|
55 | //------------------------------------------------------------------- |
---|
56 | template<class N> |
---|
57 | struct trivial_traits_impl |
---|
58 | { |
---|
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 ; |
---|
62 | |
---|
63 | typedef mpl::false_ subranged ; |
---|
64 | typedef mpl::true_ trivial ; |
---|
65 | |
---|
66 | typedef N target_type ; |
---|
67 | typedef N source_type ; |
---|
68 | typedef N const& result_type ; |
---|
69 | typedef N const& argument_type ; |
---|
70 | |
---|
71 | typedef N supertype ; |
---|
72 | typedef N subtype ; |
---|
73 | |
---|
74 | } ; |
---|
75 | |
---|
76 | //------------------------------------------------------------------- |
---|
77 | // Top level implementation selector. |
---|
78 | //------------------------------------------------------------------- |
---|
79 | template<class T, class S> |
---|
80 | struct get_conversion_traits |
---|
81 | { |
---|
82 | typedef typename remove_cv<T>::type target_type ; |
---|
83 | typedef typename remove_cv<S>::type source_type ; |
---|
84 | |
---|
85 | typedef typename is_same<target_type,source_type>::type is_trivial ; |
---|
86 | |
---|
87 | typedef trivial_traits_impl <target_type> trivial_imp ; |
---|
88 | typedef non_trivial_traits_impl<target_type,source_type> non_trivial_imp ; |
---|
89 | |
---|
90 | typedef typename mpl::if_<is_trivial,trivial_imp,non_trivial_imp>::type type ; |
---|
91 | } ; |
---|
92 | |
---|
93 | } } } // namespace boost::numeric::convdetail |
---|
94 | |
---|
95 | #endif |
---|
96 | |
---|
97 | |
---|