gslcpp
Modern-C++ Wrapper for GSL
complex.hpp
Go to the documentation of this file.
1 /// \file include/gslcpp/wrap/complex.hpp
2 /// \copyright 2022 Thomas E. Vaughan, all rights reserved.
3 /// \brief Definition of gsl::complex.
4 
5 #pragma once
6 #include <complex> // std::complex
7 #include <gsl/gsl_complex.h> // gsl_complex, etc.
8 
9 namespace gsl {
10 
11 
12 /// Complex-number, each of whose components has type A.
13 /// This is the generic declaration; see each specialization for details.
14 /// \sa gsl::complex<double>
15 /// \sa gsl::complex<float>
16 /// \sa gsl::complex<long double>
17 /// \tparam A Type of each component.
18 template<typename A> struct complex;
19 
20 
21 /// Specialization of \ref gsl::complex for double.
22 template<> struct complex<double>: public std::complex<double> {
23  using P= std::complex<double>; ///< Type of parent.
24  using P::P; // Inherit constructors.
25 
26  /// Construct from gsl_complex.
27  /// \param z Reference to instance of gsl_complex.
28  complex(gsl_complex const &z): P(GSL_REAL(z), GSL_IMAG(z)) {}
29 
30  /// Construct from instance of parent's type.
31  /// \param z Reference to instance of parent's type.
32  complex(P const &z): P(z) {}
33 
34  /// Convert to gsl_complex.
35  /// \return Reference to this as gsl_complex.
36  operator gsl_complex &() { return *(gsl_complex *)this; }
37 
38  /// Convert to gsl_complex.
39  /// \return Reference to this as gsl_complex.
40  operator gsl_complex const &() const { return *(gsl_complex const *)this; }
41 };
42 
43 
44 /// Specialization of \ref gsl::complex for float.
45 template<> struct complex<float>: public std::complex<float> {
46  using P= std::complex<float>; ///< Type of parent.
47  using P::P; // Inherit constructors.
48 
49  /// Construct from gsl_complex.
50  /// \param z Reference to instance of gsl_complex.
51  complex(gsl_complex_float const &z): P(GSL_REAL(z), GSL_IMAG(z)) {}
52 
53  /// Construct from instance of parent's type.
54  /// \param z Reference to instance of parent's type.
55  complex(P const &z): P(z) {}
56 
57  /// Convert to gsl_complex.
58  /// \return Reference to this as gsl_complex.
59  operator gsl_complex_float &() { return *(gsl_complex_float *)this; }
60 
61  /// Convert to gsl_complex.
62  /// \return Reference to this as gsl_complex.
63  operator gsl_complex_float const &() const {
64  return *(gsl_complex_float const *)this;
65  }
66 };
67 
68 
69 /// Specialization of \ref gsl::complex for long double.
70 template<> struct complex<long double>: public std::complex<long double> {
71  using P= std::complex<long double>; ///< Type of parent.
72  using P::P; // Inherit constructors.
73 
74  /// Construct from gsl_complex.
75  /// \param z Reference to instance of gsl_complex.
76  complex(gsl_complex_long_double const &z): P(GSL_REAL(z), GSL_IMAG(z)) {}
77 
78  /// Construct from instance of parent's type.
79  /// \param z Reference to instance of parent's type.
80  complex(P const &z): P(z) {}
81 
82  /// Convert to gsl_complex.
83  /// \return Reference to this as gsl_complex.
84  operator gsl_complex_long_double &() {
85  return *(gsl_complex_long_double *)this;
86  }
87 
88  /// Convert to gsl_complex.
89  /// \return Reference to this as gsl_complex.
90  operator gsl_complex_long_double const &() const {
91  return *(gsl_complex_long_double const *)this;
92  }
93 };
94 
95 
96 } // namespace gsl
97 
98 // EOF
gsl::complex< float >::operator gsl_complex_float const &
operator gsl_complex_float const &() const
Convert to gsl_complex.
Definition: complex.hpp:63
gsl::complex< long double >::operator gsl_complex_long_double &
operator gsl_complex_long_double &()
Convert to gsl_complex.
Definition: complex.hpp:84
gsl::complex< double >::complex
complex(P const &z)
Construct from instance of parent's type.
Definition: complex.hpp:32
gsl::complex< float >::complex
complex(gsl_complex_float const &z)
Construct from gsl_complex.
Definition: complex.hpp:51
gsl::complex< long double >::operator gsl_complex_long_double const &
operator gsl_complex_long_double const &() const
Convert to gsl_complex.
Definition: complex.hpp:90
gsl::complex< double >::operator gsl_complex &
operator gsl_complex &()
Convert to gsl_complex.
Definition: complex.hpp:36
gsl::complex< long double >::complex
complex(gsl_complex_long_double const &z)
Construct from gsl_complex.
Definition: complex.hpp:76
gsl::complex< float >::complex
complex(P const &z)
Construct from instance of parent's type.
Definition: complex.hpp:55
gsl::complex< long double >::complex
complex(P const &z)
Construct from instance of parent's type.
Definition: complex.hpp:80
gsl::complex< float >::operator gsl_complex_float &
operator gsl_complex_float &()
Convert to gsl_complex.
Definition: complex.hpp:59
gsl::complex< double >::complex
complex(gsl_complex const &z)
Construct from gsl_complex.
Definition: complex.hpp:28
gsl
Namespace for C++-interface to GSL.
Definition: v-iface.hpp:51
gsl::complex< double >::operator gsl_complex const &
operator gsl_complex const &() const
Convert to gsl_complex.
Definition: complex.hpp:40