BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslstl_complex.h
Go to the documentation of this file.
1/// @file bslstl_complex.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslstl_complex.h -*-C++-*-
8#ifndef INCLUDED_BSLSTL_COMPLEX
9#define INCLUDED_BSLSTL_COMPLEX
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslstl_complex bslstl_complex
15/// @brief Provide functionality of the corresponding C++ Standard header.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslstl
19/// @{
20/// @addtogroup bslstl_complex
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslstl_complex-purpose"> Purpose</a>
25/// * <a href="#bslstl_complex-canonical-header"> Canonical Header </a>
26/// * <a href="#bslstl_complex-description"> Description </a>
27/// * <a href="#bslstl_complex-user-defined-literals"> User-defined literals </a>
28/// * <a href="#bslstl_complex-usage"> Usage </a>
29/// * <a href="#bslstl_complex-example-1-basic-bsl-complex-s-udls-usage"> Example 1: Basic bsl-complex's UDLs Usage </a>
30///
31/// # Purpose {#bslstl_complex-purpose}
32/// Provide functionality of the corresponding C++ Standard header.
33///
34/// # Canonical Header {#bslstl_complex-canonical-header}
35/// bsl_complex.h
36///
37/// # Description {#bslstl_complex-description}
38/// This component is for internal use only. Please include
39///`<bsl_complex.h>` directly. This component imports symbols declared in the
40/// <complex> header file implemented in the standard library provided by the
41/// compiler vendor.
42///
43/// ## User-defined literals {#bslstl_complex-user-defined-literals}
44///
45///
46/// This component provides a set of user-defined literals (UDL) to form
47/// `bsl::complex` objects with various ranges of values. The ud-suffixes are
48/// preceded with the `_` symbol to distinguish between the `bsl`-complex's UDLs
49/// and the `std`-complex's UDLs introduced in the C++14 standard and
50/// implemented in the standard library. Note that `bsl`-complex's UDLs, unlike
51/// the `std`-complex's UDLs, can be used in a client's code if the current
52/// compiler supports the C++11 standard.
53///
54/// Also note that `bsl`-complex's UDL operators are declared in the
55/// `bsl::literals::complex_literals` namespace, where `literals` and
56/// @ref complex_literals are inline namespaces. Access to these operators can be
57/// gained with either `using namespace bsl::literals`,
58/// `using namespace bsl::complex_literals` or
59/// `using namespace bsl::literals::complex_literals`. But we recommend
60/// `using namespace bsl::complex_literals` to minimize the scope of the using
61/// declaration.
62///
63/// ## Usage {#bslstl_complex-usage}
64///
65///
66/// In this section we show intended use of this component.
67///
68/// ### Example 1: Basic bsl-complex's UDLs Usage {#bslstl_complex-example-1-basic-bsl-complex-s-udls-usage}
69///
70///
71/// This example demonstrates basic use of the complex user-defined literal
72/// operators.
73///
74/// First, we provide an access to `bsl`-complex's UDLs.
75/// @code
76/// using namespace bsl::complex_literals;
77/// @endcode
78/// Then, we construct a `bsl::complex` object `z`.
79/// @code
80/// auto z = 1.0 + 1_i;
81/// @endcode
82/// Finally, stream the magnitude of the complex number `z` to `stdout`:
83/// @code
84/// printf("abs(%.1f,%.1f) = %f\n", z.real(), z.imag(), bsl::abs(z));
85/// @endcode
86/// The streaming operator produces output in the following format on `stdout`:
87/// @code
88/// abs(1.0,1.0) = 1.414214
89/// @endcode
90/// @}
91/** @} */
92/** @} */
93
94/** @addtogroup bsl
95 * @{
96 */
97/** @addtogroup bslstl
98 * @{
99 */
100/** @addtogroup bslstl_complex
101 * @{
102 */
103
104#include <bslscm_version.h>
105
107#include <bsls_keyword.h>
108#include <bsls_libraryfeatures.h>
109
110#include <complex>
111
112#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
113#include <bsls_nativestd.h>
114#endif // BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
115
116namespace bsl {
117
118 // Import selected symbols into bsl namespace
119
120 using std::abs;
121 using std::acos;
122 using std::arg;
123 using std::asin;
124 using std::atan;
125 using std::complex;
126 using std::conj;
127 using std::cos;
128 using std::cosh;
129 using std::exp;
130 using std::imag;
131 using std::log;
132 using std::log10;
133 using std::norm;
134 using std::polar;
135 using std::pow;
136 using std::real;
137 using std::sin;
138 using std::sinh;
139 using std::sqrt;
140 using std::tan;
141 using std::tanh;
142
143#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
144 using std::acosh;
145 using std::asinh;
146 using std::atanh;
147 using std::proj;
148#endif // BSLS_LIBRARYFEATURES_HAS_C99_LIBRARY
149
150#ifndef BDE_OMIT_INTERNAL_DEPRECATED
151 using std::basic_ios;
152 using std::basic_iostream;
153 using std::basic_istream;
154 using std::basic_ostream;
155 using std::basic_streambuf;
156 using std::ios_base;
157 using std::istreambuf_iterator;
158 using std::locale;
159 using std::ostreambuf_iterator;
160#endif // BDE_OMIT_INTERNAL_DEPRECATED
161
162#ifdef BSLS_LIBRARYFEATURES_HAS_CPP14_BASELINE_LIBRARY
163 inline namespace literals {
164 inline namespace complex_literals {
165 using namespace std::literals::complex_literals;
166 } // close complex_literals namespace
167 } // close literals namespace
168#endif // BSLS_LIBRARYFEATURES_HAS_CPP14_BASELINE_LIBRARY
169
170#if defined (BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY) && \
171 defined (BSLS_COMPILERFEATURES_SUPPORT_INLINE_NAMESPACE)
172
173inline namespace literals {
174inline namespace complex_literals {
175
176 /// Create a `bsl::complex<double>` complex number having the specified
177 /// `imag` imaginary component and the real part zero.
179 bsl::complex<double> operator""_i(unsigned long long imag);
181 bsl::complex<double> operator""_i(long double imag);
182
183 /// Create a `bsl::complex<float>` complex number having the specified
184 /// `imag` imaginary component and the real part zero.
186 bsl::complex<float> operator""_if(unsigned long long imag);
188 bsl::complex<float> operator""_if(long double imag);
189
190 /// Create a `bsl::complex<long double>` complex number having the
191 /// specified `imag` imaginary component and the real part zero.
193 bsl::complex<long double> operator""_il(unsigned long long imag);
195 bsl::complex<long double> operator""_il(long double imag);
196
197} // close complex_literals namespace
198} // close literals namespace
199#endif
200
201// ============================================================================
202// INLINE AND TEMPLATE FUNCTION DEFINITIONS
203// ============================================================================
204
205#if defined (BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY) && \
206 defined (BSLS_COMPILERFEATURES_SUPPORT_INLINE_NAMESPACE)
207
208inline namespace literals {
209inline namespace complex_literals {
211 bsl::complex<double> operator""_i(unsigned long long arg)
212 {
213 return bsl::complex<double>{0.0, static_cast<double>(arg)};
214 }
215
217 bsl::complex<double> operator""_i(long double arg)
218 {
219 return bsl::complex<double>{0.0, static_cast<double>(arg)};
220 }
221
223 bsl::complex<float> operator""_if(unsigned long long arg)
224 {
225 return bsl::complex<float>{0.0f, static_cast<float>(arg)};
226 }
227
229 bsl::complex<float> operator""_if(long double arg)
230 {
231 return bsl::complex<float>{0.0f, static_cast<float>(arg)};
232 }
233
235 bsl::complex<long double> operator""_il(unsigned long long arg)
236 {
237 return bsl::complex<long double>{0.0L, static_cast<long double>(arg)};
238 }
239
241 bsl::complex<long double> operator""_il(long double arg)
242 {
243 return bsl::complex<long double>{0.0L, static_cast<long double>(arg)};
244 }
245} // close complex_literals namespace
246} // close literals namespace
247#endif
248} // close package namespace
249
250//#endif
251#endif
252
253// ----------------------------------------------------------------------------
254// Copyright 2018 Bloomberg Finance L.P.
255//
256// Licensed under the Apache License, Version 2.0 (the "License");
257// you may not use this file except in compliance with the License.
258// You may obtain a copy of the License at
259//
260// http://www.apache.org/licenses/LICENSE-2.0
261//
262// Unless required by applicable law or agreed to in writing, software
263// distributed under the License is distributed on an "AS IS" BASIS,
264// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
265// See the License for the specific language governing permissions and
266// limitations under the License.
267// ----------------------------- END-OF-FILE ----------------------------------
268
269/** @} */
270/** @} */
271/** @} */
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
#define BSLS_KEYWORD_CONSTEXPR
Definition bsls_keyword.h:624
Definition bdlat_valuetypefunctions.h:939