| 1 | // Copyright John Maddock 2018. |
| 2 | // Use, modification and distribution are subject to the |
| 3 | // Boost Software License, Version 1.0. (See accompanying file |
| 4 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 5 | |
| 6 | // |
| 7 | // Tools for operator on complex as well as scalar types. |
| 8 | // |
| 9 | |
| 10 | #ifndef BOOST_MATH_TOOLS_COMPLEX_HPP |
| 11 | #define BOOST_MATH_TOOLS_COMPLEX_HPP |
| 12 | |
| 13 | #include <boost/type_traits/is_complex.hpp> |
| 14 | |
| 15 | namespace boost { |
| 16 | namespace math { |
| 17 | namespace tools { |
| 18 | |
| 19 | // |
| 20 | // Specialize this trait for user-defined complex types (ie Boost.Multiprecision): |
| 21 | // |
| 22 | template <class T> |
| 23 | struct is_complex_type : public boost::is_complex<T> {}; |
| 24 | // |
| 25 | // Use this trait to typecast integer literals to something |
| 26 | // that will interoperate with T: |
| 27 | // |
| 28 | template <class T, bool = is_complex_type<T>::value> |
| 29 | struct integer_scalar_type |
| 30 | { |
| 31 | typedef int type; |
| 32 | }; |
| 33 | template <class T> |
| 34 | struct integer_scalar_type<T, true> |
| 35 | { |
| 36 | typedef typename T::value_type type; |
| 37 | }; |
| 38 | template <class T, bool = is_complex_type<T>::value> |
| 39 | struct unsigned_scalar_type |
| 40 | { |
| 41 | typedef unsigned type; |
| 42 | }; |
| 43 | template <class T> |
| 44 | struct unsigned_scalar_type<T, true> |
| 45 | { |
| 46 | typedef typename T::value_type type; |
| 47 | }; |
| 48 | template <class T, bool = is_complex_type<T>::value> |
| 49 | struct scalar_type |
| 50 | { |
| 51 | typedef T type; |
| 52 | }; |
| 53 | template <class T> |
| 54 | struct scalar_type<T, true> |
| 55 | { |
| 56 | typedef typename T::value_type type; |
| 57 | }; |
| 58 | |
| 59 | |
| 60 | } } } |
| 61 | |
| 62 | #endif // BOOST_MATH_TOOLS_COMPLEX_HPP |
| 63 | |