complex.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. // Tools for operator on complex as well as scalar types.
  7. //
  8. #ifndef BOOST_MATH_TOOLS_COMPLEX_HPP
  9. #define BOOST_MATH_TOOLS_COMPLEX_HPP
  10. #include <boost/type_traits/is_complex.hpp>
  11. namespace boost {
  12. namespace math {
  13. namespace tools {
  14. //
  15. // Specialize this trait for user-defined complex types (ie Boost.Multiprecision):
  16. //
  17. template <class T>
  18. struct is_complex_type : public boost::is_complex<T> {};
  19. //
  20. // Use this trait to typecast integer literals to something
  21. // that will interoperate with T:
  22. //
  23. template <class T, bool = is_complex_type<T>::value>
  24. struct integer_scalar_type
  25. {
  26. typedef int type;
  27. };
  28. template <class T>
  29. struct integer_scalar_type<T, true>
  30. {
  31. typedef typename T::value_type type;
  32. };
  33. template <class T, bool = is_complex_type<T>::value>
  34. struct unsigned_scalar_type
  35. {
  36. typedef unsigned type;
  37. };
  38. template <class T>
  39. struct unsigned_scalar_type<T, true>
  40. {
  41. typedef typename T::value_type type;
  42. };
  43. template <class T, bool = is_complex_type<T>::value>
  44. struct scalar_type
  45. {
  46. typedef T type;
  47. };
  48. template <class T>
  49. struct scalar_type<T, true>
  50. {
  51. typedef typename T::value_type type;
  52. };
  53. } } }
  54. #endif // BOOST_MATH_TOOLS_COMPLEX_HPP