complex.hpp 1.6 KB

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