comparison DEPENDENCIES/generic/include/boost/numeric/ublas/traits.hpp @ 101:c530137014c0

Update Boost headers (1.58.0)
author Chris Cannam
date Mon, 07 Sep 2015 11:12:49 +0100
parents 2665513ce2d3
children
comparison
equal deleted inserted replaced
100:793467b5e61c 101:c530137014c0
18 #include <boost/config/no_tr1/cmath.hpp> 18 #include <boost/config/no_tr1/cmath.hpp>
19 19
20 #include <boost/numeric/ublas/detail/config.hpp> 20 #include <boost/numeric/ublas/detail/config.hpp>
21 #include <boost/numeric/ublas/detail/iterator.hpp> 21 #include <boost/numeric/ublas/detail/iterator.hpp>
22 #include <boost/numeric/ublas/detail/returntype_deduction.hpp> 22 #include <boost/numeric/ublas/detail/returntype_deduction.hpp>
23 #ifdef BOOST_UBLAS_USE_INTERVAL
24 #include <boost/numeric/interval.hpp>
25 #endif
23 26
24 #include <boost/type_traits.hpp> 27 #include <boost/type_traits.hpp>
25 #include <complex> 28 #include <complex>
26 #include <boost/typeof/typeof.hpp> 29 #include <boost/typeof/typeof.hpp>
27 #include <boost/utility/enable_if.hpp> 30 #include <boost/utility/enable_if.hpp>
28 #include <boost/type_traits/is_float.hpp> 31 #include <boost/type_traits/is_float.hpp>
29 #include <boost/type_traits/is_integral.hpp> 32 #include <boost/type_traits/is_integral.hpp>
33 #include <boost/type_traits/is_unsigned.hpp>
30 #include <boost/mpl/and.hpp> 34 #include <boost/mpl/and.hpp>
31 35
32 // anonymous namespace to avoid ADL issues 36 // anonymous namespace to avoid ADL issues
33 namespace { 37 namespace {
34 template<class T> T boost_numeric_ublas_sqrt (const T& t) { 38 template<class T> T boost_numeric_ublas_sqrt (const T& t) {
35 using namespace std; 39 using namespace std;
36 // we'll find either std::sqrt or else another version via ADL: 40 // we'll find either std::sqrt or else another version via ADL:
37 return sqrt (t); 41 return sqrt (t);
38 } 42 }
39 template<class T> T boost_numeric_ublas_abs (const T& t) { 43
40 using namespace std; 44 template<typename T>
41 // we'll find either std::abs or else another version via ADL: 45 inline typename boost::disable_if<
42 return abs (t); 46 boost::is_unsigned<T>, T >::type
43 } 47 boost_numeric_ublas_abs (const T &t ) {
44 // unsigned types are always non-negative 48 using namespace std;
45 template<> unsigned int boost_numeric_ublas_abs (const unsigned int& t) { 49 return abs( t );
46 return t; 50 }
47 } 51
48 // unsigned types are always non-negative 52 template<typename T>
49 template<> unsigned long boost_numeric_ublas_abs (const unsigned long& t) { 53 inline typename boost::enable_if<
50 return t; 54 boost::is_unsigned<T>, T >::type
51 } 55 boost_numeric_ublas_abs (const T &t ) {
56 return t;
57 }
52 } 58 }
53 59
54 namespace boost { namespace numeric { namespace ublas { 60 namespace boost { namespace numeric { namespace ublas {
61
62
63 template<typename R, typename I>
64 typename boost::enable_if<
65 mpl::and_<
66 boost::is_float<R>,
67 boost::is_integral<I>
68 >,
69 std::complex<R> >::type inline operator+ (I in1, std::complex<R> const& in2 ) {
70 return R (in1) + in2;
71 }
72
73 template<typename R, typename I>
74 typename boost::enable_if<
75 mpl::and_<
76 boost::is_float<R>,
77 boost::is_integral<I>
78 >,
79 std::complex<R> >::type inline operator+ (std::complex<R> const& in1, I in2) {
80 return in1 + R (in2);
81 }
82
83 template<typename R, typename I>
84 typename boost::enable_if<
85 mpl::and_<
86 boost::is_float<R>,
87 boost::is_integral<I>
88 >,
89 std::complex<R> >::type inline operator- (I in1, std::complex<R> const& in2) {
90 return R (in1) - in2;
91 }
92
93 template<typename R, typename I>
94 typename boost::enable_if<
95 mpl::and_<
96 boost::is_float<R>,
97 boost::is_integral<I>
98 >,
99 std::complex<R> >::type inline operator- (std::complex<R> const& in1, I in2) {
100 return in1 - R (in2);
101 }
102
103 template<typename R, typename I>
104 typename boost::enable_if<
105 mpl::and_<
106 boost::is_float<R>,
107 boost::is_integral<I>
108 >,
109 std::complex<R> >::type inline operator* (I in1, std::complex<R> const& in2) {
110 return R (in1) * in2;
111 }
112
113 template<typename R, typename I>
114 typename boost::enable_if<
115 mpl::and_<
116 boost::is_float<R>,
117 boost::is_integral<I>
118 >,
119 std::complex<R> >::type inline operator* (std::complex<R> const& in1, I in2) {
120 return in1 * R(in2);
121 }
122
123 template<typename R, typename I>
124 typename boost::enable_if<
125 mpl::and_<
126 boost::is_float<R>,
127 boost::is_integral<I>
128 >,
129 std::complex<R> >::type inline operator/ (I in1, std::complex<R> const& in2) {
130 return R(in1) / in2;
131 }
132
133 template<typename R, typename I>
134 typename boost::enable_if<
135 mpl::and_<
136 boost::is_float<R>,
137 boost::is_integral<I>
138 >,
139 std::complex<R> >::type inline operator/ (std::complex<R> const& in1, I in2) {
140 return in1 / R (in2);
141 }
55 142
56 // Use Joel de Guzman's return type deduction 143 // Use Joel de Guzman's return type deduction
57 // uBLAS assumes a common return type for all binary arithmetic operators 144 // uBLAS assumes a common return type for all binary arithmetic operators
58 template<class X, class Y> 145 template<class X, class Y>
59 struct promote_traits { 146 struct promote_traits {
71 typedef typename mpl::at_c< 158 typedef typename mpl::at_c<
72 typename base_type::types, index>::type id; 159 typename base_type::types, index>::type id;
73 typedef typename id::type promote_type; 160 typedef typename id::type promote_type;
74 }; 161 };
75 162
76 template<typename R, typename I>
77 typename boost::enable_if<
78 mpl::and_<
79 boost::is_float<R>,
80 boost::is_integral<I>
81 >,
82 std::complex<R> >::type inline operator+ (I in1, std::complex<R> const& in2 ) {
83 return R (in1) + in2;
84 }
85
86 template<typename R, typename I>
87 typename boost::enable_if<
88 mpl::and_<
89 boost::is_float<R>,
90 boost::is_integral<I>
91 >,
92 std::complex<R> >::type inline operator+ (std::complex<R> const& in1, I in2) {
93 return in1 + R (in2);
94 }
95
96 template<typename R, typename I>
97 typename boost::enable_if<
98 mpl::and_<
99 boost::is_float<R>,
100 boost::is_integral<I>
101 >,
102 std::complex<R> >::type inline operator- (I in1, std::complex<R> const& in2) {
103 return R (in1) - in2;
104 }
105
106 template<typename R, typename I>
107 typename boost::enable_if<
108 mpl::and_<
109 boost::is_float<R>,
110 boost::is_integral<I>
111 >,
112 std::complex<R> >::type inline operator- (std::complex<R> const& in1, I in2) {
113 return in1 - R (in2);
114 }
115
116 template<typename R, typename I>
117 typename boost::enable_if<
118 mpl::and_<
119 boost::is_float<R>,
120 boost::is_integral<I>
121 >,
122 std::complex<R> >::type inline operator* (I in1, std::complex<R> const& in2) {
123 return R (in1) * in2;
124 }
125
126 template<typename R, typename I>
127 typename boost::enable_if<
128 mpl::and_<
129 boost::is_float<R>,
130 boost::is_integral<I>
131 >,
132 std::complex<R> >::type inline operator* (std::complex<R> const& in1, I in2) {
133 return in1 * R(in2);
134 }
135
136 template<typename R, typename I>
137 typename boost::enable_if<
138 mpl::and_<
139 boost::is_float<R>,
140 boost::is_integral<I>
141 >,
142 std::complex<R> >::type inline operator/ (I in1, std::complex<R> const& in2) {
143 return R(in1) / in2;
144 }
145
146 template<typename R, typename I>
147 typename boost::enable_if<
148 mpl::and_<
149 boost::is_float<R>,
150 boost::is_integral<I>
151 >,
152 std::complex<R> >::type inline operator/ (std::complex<R> const& in1, I in2) {
153 return in1 / R (in2);
154 }
155
156 163
157 164
158 // Type traits - generic numeric properties and functions 165 // Type traits - generic numeric properties and functions
159 template<class T> 166 template<class T>
160 struct type_traits; 167 struct type_traits;