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 <utility>
14#include <boost/math/tools/is_detected.hpp>
15
16namespace boost {
17 namespace math {
18 namespace tools {
19
20 namespace detail {
21 template <typename T, typename = void>
22 struct is_complex_type_impl
23 {
24 static constexpr bool value = false;
25 };
26
27 template <typename T>
28 struct is_complex_type_impl<T, void_t<decltype(std::declval<T>().real()),
29 decltype(std::declval<T>().imag())>>
30 {
31 static constexpr bool value = true;
32 };
33 } // Namespace detail
34
35 template <typename T>
36 struct is_complex_type : public detail::is_complex_type_impl<T> {};
37
38 //
39 // Use this trait to typecast integer literals to something
40 // that will interoperate with T:
41 //
42 template <class T, bool = is_complex_type<T>::value>
43 struct integer_scalar_type
44 {
45 typedef int type;
46 };
47 template <class T>
48 struct integer_scalar_type<T, true>
49 {
50 typedef typename T::value_type type;
51 };
52 template <class T, bool = is_complex_type<T>::value>
53 struct unsigned_scalar_type
54 {
55 typedef unsigned type;
56 };
57 template <class T>
58 struct unsigned_scalar_type<T, true>
59 {
60 typedef typename T::value_type type;
61 };
62 template <class T, bool = is_complex_type<T>::value>
63 struct scalar_type
64 {
65 typedef T type;
66 };
67 template <class T>
68 struct scalar_type<T, true>
69 {
70 typedef typename T::value_type type;
71 };
72
73
74} } }
75
76#endif // BOOST_MATH_TOOLS_COMPLEX_HPP
77

source code of boost/libs/math/include/boost/math/tools/complex.hpp