williamr@4
|
1 |
// © Copyright Fernando Luis Cacciola Carballal 2000-2004
|
williamr@4
|
2 |
// Use, modification, and distribution is subject to the Boost Software
|
williamr@4
|
3 |
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
williamr@4
|
4 |
// http://www.boost.org/LICENSE_1_0.txt)
|
williamr@4
|
5 |
|
williamr@4
|
6 |
// See library home page at http://www.boost.org/libs/numeric/conversion
|
williamr@4
|
7 |
//
|
williamr@4
|
8 |
// Contact the author at: fernando_cacciola@hotmail.com
|
williamr@4
|
9 |
//
|
williamr@4
|
10 |
#ifndef BOOST_NUMERIC_CONVERSION_DETAIL_CONVERSION_TRAITS_FLC_12NOV2002_HPP
|
williamr@4
|
11 |
#define BOOST_NUMERIC_CONVERSION_DETAIL_CONVERSION_TRAITS_FLC_12NOV2002_HPP
|
williamr@4
|
12 |
|
williamr@4
|
13 |
#include "boost/type_traits/is_arithmetic.hpp"
|
williamr@4
|
14 |
#include "boost/type_traits/is_same.hpp"
|
williamr@4
|
15 |
#include "boost/type_traits/remove_cv.hpp"
|
williamr@4
|
16 |
|
williamr@4
|
17 |
#include "boost/numeric/conversion/detail/meta.hpp"
|
williamr@4
|
18 |
#include "boost/numeric/conversion/detail/int_float_mixture.hpp"
|
williamr@4
|
19 |
#include "boost/numeric/conversion/detail/sign_mixture.hpp"
|
williamr@4
|
20 |
#include "boost/numeric/conversion/detail/udt_builtin_mixture.hpp"
|
williamr@4
|
21 |
#include "boost/numeric/conversion/detail/is_subranged.hpp"
|
williamr@4
|
22 |
|
williamr@4
|
23 |
namespace boost { namespace numeric { namespace convdetail
|
williamr@4
|
24 |
{
|
williamr@4
|
25 |
//-------------------------------------------------------------------
|
williamr@4
|
26 |
// Implementation of the Conversion Traits for T != S
|
williamr@4
|
27 |
//
|
williamr@4
|
28 |
// This is a VISIBLE base class of the user-level conversion_traits<> class.
|
williamr@4
|
29 |
//-------------------------------------------------------------------
|
williamr@4
|
30 |
template<class T,class S>
|
williamr@4
|
31 |
struct non_trivial_traits_impl
|
williamr@4
|
32 |
{
|
williamr@4
|
33 |
typedef typename get_int_float_mixture <T,S>::type int_float_mixture ;
|
williamr@4
|
34 |
typedef typename get_sign_mixture <T,S>::type sign_mixture ;
|
williamr@4
|
35 |
typedef typename get_udt_builtin_mixture <T,S>::type udt_builtin_mixture ;
|
williamr@4
|
36 |
|
williamr@4
|
37 |
typedef typename get_is_subranged<T,S>::type subranged ;
|
williamr@4
|
38 |
|
williamr@4
|
39 |
typedef mpl::false_ trivial ;
|
williamr@4
|
40 |
|
williamr@4
|
41 |
typedef T target_type ;
|
williamr@4
|
42 |
typedef S source_type ;
|
williamr@4
|
43 |
typedef T result_type ;
|
williamr@4
|
44 |
|
williamr@4
|
45 |
typedef typename mpl::if_< is_arithmetic<S>, S, S const&>::type argument_type ;
|
williamr@4
|
46 |
|
williamr@4
|
47 |
typedef typename mpl::if_<subranged,S,T>::type supertype ;
|
williamr@4
|
48 |
typedef typename mpl::if_<subranged,T,S>::type subtype ;
|
williamr@4
|
49 |
} ;
|
williamr@4
|
50 |
|
williamr@4
|
51 |
//-------------------------------------------------------------------
|
williamr@4
|
52 |
// Implementation of the Conversion Traits for T == S
|
williamr@4
|
53 |
//
|
williamr@4
|
54 |
// This is a VISIBLE base class of the user-level conversion_traits<> class.
|
williamr@4
|
55 |
//-------------------------------------------------------------------
|
williamr@4
|
56 |
template<class N>
|
williamr@4
|
57 |
struct trivial_traits_impl
|
williamr@4
|
58 |
{
|
williamr@4
|
59 |
typedef typename get_int_float_mixture <N,N>::type int_float_mixture ;
|
williamr@4
|
60 |
typedef typename get_sign_mixture <N,N>::type sign_mixture ;
|
williamr@4
|
61 |
typedef typename get_udt_builtin_mixture<N,N>::type udt_builtin_mixture ;
|
williamr@4
|
62 |
|
williamr@4
|
63 |
typedef mpl::false_ subranged ;
|
williamr@4
|
64 |
typedef mpl::true_ trivial ;
|
williamr@4
|
65 |
|
williamr@4
|
66 |
typedef N target_type ;
|
williamr@4
|
67 |
typedef N source_type ;
|
williamr@4
|
68 |
typedef N const& result_type ;
|
williamr@4
|
69 |
typedef N const& argument_type ;
|
williamr@4
|
70 |
|
williamr@4
|
71 |
typedef N supertype ;
|
williamr@4
|
72 |
typedef N subtype ;
|
williamr@4
|
73 |
|
williamr@4
|
74 |
} ;
|
williamr@4
|
75 |
|
williamr@4
|
76 |
//-------------------------------------------------------------------
|
williamr@4
|
77 |
// Top level implementation selector.
|
williamr@4
|
78 |
//-------------------------------------------------------------------
|
williamr@4
|
79 |
template<class T, class S>
|
williamr@4
|
80 |
struct get_conversion_traits
|
williamr@4
|
81 |
{
|
williamr@4
|
82 |
typedef typename remove_cv<T>::type target_type ;
|
williamr@4
|
83 |
typedef typename remove_cv<S>::type source_type ;
|
williamr@4
|
84 |
|
williamr@4
|
85 |
typedef typename is_same<target_type,source_type>::type is_trivial ;
|
williamr@4
|
86 |
|
williamr@4
|
87 |
typedef trivial_traits_impl <target_type> trivial_imp ;
|
williamr@4
|
88 |
typedef non_trivial_traits_impl<target_type,source_type> non_trivial_imp ;
|
williamr@4
|
89 |
|
williamr@4
|
90 |
typedef typename mpl::if_<is_trivial,trivial_imp,non_trivial_imp>::type type ;
|
williamr@4
|
91 |
} ;
|
williamr@4
|
92 |
|
williamr@4
|
93 |
} } } // namespace boost::numeric::convdetail
|
williamr@4
|
94 |
|
williamr@4
|
95 |
#endif
|
williamr@4
|
96 |
|
williamr@4
|
97 |
|