2 * Copyright (c) 2001-2003 Joel de Guzman
4 * Use, modification and distribution is subject to the Boost Software
5 * License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 * http://www.boost.org/LICENSE_1_0.txt)
8 #ifndef _BOOST_UBLAS_NUMERICTYPE_DEDUCTION_
9 #define _BOOST_UBLAS_NUMERICTYPE_DEDUCTION_
11 // See original in boost-sandbox/boost/utility/type_deduction.hpp for comments
13 #include <boost/mpl/vector/vector20.hpp>
14 #include <boost/mpl/at.hpp>
15 #include <boost/mpl/or.hpp>
16 #include <boost/mpl/identity.hpp>
17 #include <boost/type_traits/remove_cv.hpp>
18 #include <boost/type_traits/is_same.hpp>
19 #include <boost/utility/enable_if.hpp>
21 namespace boost { namespace numeric { namespace ublas {
23 struct error_cant_deduce_type {};
25 namespace type_deduction_detail
27 typedef char(&bool_value_type)[1];
28 typedef char(&float_value_type)[2];
29 typedef char(&double_value_type)[3];
30 typedef char(&long_double_value_type)[4];
31 typedef char(&char_value_type)[5];
32 typedef char(&schar_value_type)[6];
33 typedef char(&uchar_value_type)[7];
34 typedef char(&short_value_type)[8];
35 typedef char(&ushort_value_type)[9];
36 typedef char(&int_value_type)[10];
37 typedef char(&uint_value_type)[11];
38 typedef char(&long_value_type)[12];
39 typedef char(&ulong_value_type)[13];
41 typedef char(&x_value_type)[14];
42 typedef char(&y_value_type)[15];
44 typedef char(&cant_deduce_type)[16];
46 template <typename T, typename PlainT = typename remove_cv<T>::type>
51 , is_same<PlainT, float>
52 , is_same<PlainT, double>
53 , is_same<PlainT, long double>
57 , is_same<PlainT, signed char>
58 , is_same<PlainT, unsigned char>
59 , is_same<PlainT, short>
60 , is_same<PlainT, unsigned short>
64 , is_same<PlainT, unsigned int>
65 , is_same<PlainT, long>
66 , is_same<PlainT, unsigned long>
72 template <typename X, typename Y>
74 test(...); // The black hole !!!
76 template <typename X, typename Y>
80 template <typename X, typename Y>
84 template <typename X, typename Y>
88 template <typename X, typename Y>
89 long_double_value_type
90 test(long double const&);
92 template <typename X, typename Y>
96 template <typename X, typename Y>
98 test(signed char const&);
100 template <typename X, typename Y>
102 test(unsigned char const&);
104 template <typename X, typename Y>
108 template <typename X, typename Y>
110 test(unsigned short const&);
112 template <typename X, typename Y>
116 template <typename X, typename Y>
118 test(unsigned int const&);
120 template <typename X, typename Y>
124 template <typename X, typename Y>
126 test(unsigned long const&);
128 template <typename X, typename Y>
130 is_basic<X>, x_value_type
134 template <typename X, typename Y>
138 , is_same<Y, asymmetric>
139 , is_same<const X, const Y>
145 template <typename X, typename Y>
146 struct base_result_of
148 typedef typename remove_cv<X>::type x_type;
149 typedef typename remove_cv<Y>::type y_type;
151 typedef mpl::vector16<
153 , mpl::identity<float>
154 , mpl::identity<double>
155 , mpl::identity<long double>
156 , mpl::identity<char>
157 , mpl::identity<signed char>
158 , mpl::identity<unsigned char>
159 , mpl::identity<short>
160 , mpl::identity<unsigned short>
162 , mpl::identity<unsigned int>
163 , mpl::identity<long>
164 , mpl::identity<unsigned long>
165 , mpl::identity<x_type>
166 , mpl::identity<y_type>
167 , mpl::identity<error_cant_deduce_type>
172 }}} } // namespace boost::numeric::ublas ::type_deduction_detail