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