BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslfmt_format_arg.h
Go to the documentation of this file.
1/// @file bslfmt_format_arg.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslfmt_format_arg.h -*-C++-*-
8
9#ifndef INCLUDED_BSLFMT_FORMAT_ARG
10#define INCLUDED_BSLFMT_FORMAT_ARG
11
12#include <bsls_ident.h>
13BSLS_IDENT("$Id: $")
14
15/// @defgroup bslfmt_format_arg bslfmt_format_arg
16/// @brief Provide a proxy for an argument for use by bsl::format
17/// @addtogroup bsl
18/// @{
19/// @addtogroup bslfmt
20/// @{
21/// @addtogroup bslfmt_format_arg
22/// @{
23///
24/// <h1> Outline </h1>
25/// * <a href="#bslfmt_format_arg-purpose"> Purpose</a>
26/// * <a href="#bslfmt_format_arg-classes"> Classes </a>
27/// * <a href="#bslfmt_format_arg-canonical-header"> Canonical Header </a>
28/// * <a href="#bslfmt_format_arg-description"> Description </a>
29/// * <a href="#bslfmt_format_arg-usage"> Usage </a>
30/// * <a href="#bslfmt_format_arg-example-default-construction-and-value-verification"> Example: Default construction and value verification </a>
31///
32/// # Purpose {#bslfmt_format_arg-purpose}
33/// Provide a proxy for an argument for use by bsl::format
34///
35/// # Classes {#bslfmt_format_arg-classes}
36///
37/// - bslfmt::basic_format_arg: standard-compliant argument
38///
39/// # Canonical Header {#bslfmt_format_arg-canonical-header}
40/// bsl_format.h
41///
42/// # Description {#bslfmt_format_arg-description}
43/// This component provides an implementation of the C++20 Standard
44/// Library's @ref basic_format_arg , providing access via a "visitor pattern". The
45/// value is stored as if using a variant of the following types (as specified
46/// by the Standard):
47///
48/// - `bsl::monostate` (only if the object was default-constructed)
49/// - `bool`
50/// - `Context::char_type`
51/// - `int`
52/// - `unsigned int`
53/// - `long long int`
54/// - `unsigned long long int`
55/// - `float`
56/// - `double`
57/// - `long double`
58/// - `const Context::char_type *`
59/// - `bsl::basic_string_view<Context::char_type>`
60/// - `const void *`
61/// - `basic_format_arg::handle`
62///
63/// Where `basic_format_arg::handle` is a type-erased wrapper holding a
64/// reference to a user-defined type.
65///
66/// This header is not intended to be included directly. Please include
67/// `<bsl_format.h>` to be able to use `bsl::basic_format_arg`.
68///
69/// `bsl::basic_format_arg` differs from the C++20 standard as follows: we
70/// provide the C++23 member `visit`, but we do not provide the overload of
71/// `visit` that accepts an explicitly specified return type.
72///
73/// ## Usage {#bslfmt_format_arg-usage}
74///
75///
76/// In this section we show the intended use of this component.
77///
78/// ### Example: Default construction and value verification {#bslfmt_format_arg-example-default-construction-and-value-verification}
79///
80///
81/// We do not expect most users of `bsl::format` to interact with this type
82/// directly and instead use `bsl::format` or `bsl::vformat`. In addition, there
83/// are only a very limited number of public methods so this example is
84/// necessarily unrealistic.
85///
86/// Suppose we want to construct a default-constructed @ref basic_format_arg and
87/// verify that it contains no value.
88///
89/// @code
90/// bslfmt::format_args args;
91///
92/// assert(!args.get(0));
93/// @endcode
94/// @}
95/** @} */
96/** @} */
97
98/** @addtogroup bsl
99 * @{
100 */
101/** @addtogroup bslfmt
102 * @{
103 */
104/** @addtogroup bslfmt_format_arg
105 * @{
106 */
107
108#include <bslscm_version.h>
109
111
112#include <bslmf_conditional.h>
113#include <bslmf_enableif.h>
115#include <bslmf_isintegral.h>
116#include <bslmf_issame.h>
117#include <bslmf_movableref.h>
118
120#include <bsls_exceptionutil.h>
121#include <bsls_libraryfeatures.h>
122#include <bsls_nullptr.h>
123#include <bsls_unspecifiedbool.h>
124#include <bsls_util.h>
125
126#include <bslstl_array.h>
127#include <bslstl_iterator.h>
128#include <bslstl_monostate.h>
129#include <bslstl_string.h>
130#include <bslstl_stringview.h>
131#include <bslstl_utility.h>
132#include <bslstl_variant.h>
133
134#include <bslfmt_formaterror.h>
135#include <bslfmt_formatterbase.h>
136
137#if BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
138// clang-format off
139// Include version that can be compiled with C++03
140// Generated on Thu Jan 23 14:54:23 2025
141// Command line: sim_cpp11_features.pl bslfmt_format_arg.h
142
143# define COMPILING_BSLFMT_FORMAT_ARG_H
145# undef COMPILING_BSLFMT_FORMAT_ARG_H
146
147// clang-format on
148#else
149
150
151namespace bslfmt {
152
153// FORWARD DECLARATIONS
154
155template <class t_CHAR>
156class basic_format_parse_context;
157
158template <class t_OUT, class t_CHAR>
159class basic_format_context;
160
161template <class t_CONTEXT>
163
164template <class t_VALUE>
166
167// TYPEDEFS
168
171
174
175 // ======================
176 // class basic_format_arg
177 // ======================
178
179/// This class provides an STL-compliant @ref basic_format_arg which holds (by
180/// value for scalar and pointer types, by reference for user-defined types).
181/// These types should not be constructed directly by the user.
182template <class t_OUT, class t_CHAR>
184 public:
185 // TYPES
186
187 /// This class provides a type-erased wrapper which holds a pointer to a
188 /// user-defined type and permits its formatting using the appropriate
189 /// bsl::formatter type.
190 ///
191 /// See @ref bslfmt_format_arg
192 class handle {
193 private:
194 // DATA
195 const void *d_value_p;
196 // pointer to the referenced value
197
198 void (*d_format_impl_p)(basic_format_parse_context<t_CHAR>&,
200 const void *);
201 // pointer to a format_impl instance
202
203 // FRIENDS
204 friend class basic_format_arg<basic_format_context<t_OUT, t_CHAR> >;
205
206 // PRIVATE CLASS METHODS
207
208 /// Format the specified `value` using a `bsl::formatter` instance for
209 /// the specified template parameter `t_TYPE`. The constructed
210 /// formatter will parse the specification in the specified `pc`
211 /// context and write the output to the specified `fc` context.
212 template <class t_TYPE>
213 static void format_impl(basic_format_parse_context<t_CHAR>& pc,
215 const void *value);
216
217 // PRIVATE CREATORS
218
219 /// Create a `handle` referencing the specified `value` and initialize
220 /// the contained formatting function to an instance of @ref format_impl
221 /// for the template parameter `t_TYPE`.
222 template <class t_TYPE>
223 explicit handle(const t_TYPE& value) BSLS_KEYWORD_NOEXCEPT;
224
225 public:
226 // CREATORS
227#if !defined(BSLMF_MOVABLEREF_USES_RVALUE_REFERENCES)
228 /// Move-construct a `handle` from the specified `rhs`. This is
229 /// required to support use within a bsl::variant on C++03, but must
230 /// *not* be specified for C++11 and later as it will result in the
231 /// implicit deletion of other defaulted special member functions.
233#endif // !defined(BSLMF_MOVABLEREF_USES_RVALUE_REFERENCES)
234
235 // ACCESSORS
236
237 /// Format the contained value using a formatter for the template
238 /// parameter `t_TYPE` used in the construction of this object. The
239 /// constructed formatter will parse the specification in the specified
240 /// `pc` context and write the output to the specified `fc` context.
243 };
244
245 typedef typename BloombergLP::bsls::UnspecifiedBool<basic_format_arg>
247 typedef typename UnspecifiedBoolType::BoolType BoolType;
248
249 private:
250 // NOT IMPLEMENTED
251 bool operator==(const basic_format_arg&) const BSLS_KEYWORD_DELETED;
252
253 // PRIVATE TYPES
254 typedef t_CHAR char_type;
255
257 bool,
258 char_type,
259 int,
260 unsigned,
261 long long,
262 unsigned long long,
263 float,
264 double,
265 long double,
266 const char_type *,
268 const void *,
269 handle>
271
272 // DATA
273 variant_type d_value; // the contained value or a reference thereto
274
275 // FRIENDS
276 friend class Format_ArgUtil;
277
278 // PRIVATE CREATORS
279
280 /// Create a @ref basic_format_arg from the specified `value`, which is then
281 /// held by value.
282 explicit basic_format_arg(bool value) BSLS_KEYWORD_NOEXCEPT;
283
284 /// Create a @ref basic_format_arg from the specified `value`, which is then
285 /// held by value.
286 explicit basic_format_arg(char_type value) BSLS_KEYWORD_NOEXCEPT;
287
288 /// Create a @ref basic_format_arg from the specified `value` widened from
289 /// type `char` to type `wchar_t`, which is then held by value. This
290 /// constructor only participates in overload resolution if `value` is of
291 /// type `char` and `t_CHAR` is of type `wchar_t`.
292 template <class t_TYPE>
293 explicit basic_format_arg(
294 t_TYPE value,
297 int>::type = 0) BSLS_KEYWORD_NOEXCEPT;
298
299 /// Create a @ref basic_format_arg from the specified `value`, which is then
300 /// held by value. This constructor only participates in overload
301 /// resolution if `value` is an signed integer type that can be held within
302 /// a `long long` or an unsigned integer type that can be held within an
303 /// `unsigned long long`.
304 template <class t_TYPE>
305 explicit basic_format_arg(
306 t_TYPE value,
307 typename bsl::enable_if<bsl::is_integral<t_TYPE>::value &&
308 !bsl::is_same<t_TYPE, char>::value &&
309 !bsl::is_same<t_TYPE, wchar_t>::value &&
310 (sizeof(t_TYPE) <= sizeof(long long)),
311 int>::type = 0) BSLS_KEYWORD_NOEXCEPT;
312
313 /// Create a @ref basic_format_arg from the specified `value`, which is then
314 /// held by reference in a `basic_format_arg::handle`. This constructor
315 /// only participates in overload resolution if `value` is not an integer
316 /// or if `value` is a signed integer type that can not be held within a
317 /// `long long` or an unsigned integer type that can not be held within an
318 /// `unsigned long long`. Participation in overload resolution is also
319 /// disabled if `value` is of type `long double`.
320 template <class t_TYPE>
321 explicit basic_format_arg(
322 const t_TYPE& value,
323 typename bsl::enable_if<(!bsl::is_integral<t_TYPE>::value &&
324 !bsl::is_same<t_TYPE, long double>::value) ||
325 (sizeof(t_TYPE) > sizeof(long long)),
326 int>::type = 0) BSLS_KEYWORD_NOEXCEPT;
327
328 /// Create a @ref basic_format_arg from the specified `value`, which is then
329 /// held by value.
330 explicit basic_format_arg(float value) BSLS_KEYWORD_NOEXCEPT;
331
332 /// Create a @ref basic_format_arg from the specified `value`, which is then
333 /// held by value.
334 explicit basic_format_arg(double value) BSLS_KEYWORD_NOEXCEPT;
335
336 /// Terminate by calling BSLMF_ASSERT. This constructor only participates
337 /// in overload resolution if `value` is of the currently unsupported type
338 /// `long double`. Note: this is required to use a template parameter to
339 /// ensure that this function is only instantiated when an attempt is made
340 /// to use it.
341 template <class t_TYPE>
342 explicit basic_format_arg(
343 t_TYPE value,
344 typename bsl::enable_if<bsl::is_same<t_TYPE, long double>::value,
345 int>::type = 0) BSLS_KEYWORD_NOEXCEPT;
346
347 /// Create a @ref basic_format_arg from the specified `value`, which is then
348 /// held by value.
349 template <class t_TRAITS>
350 explicit basic_format_arg(
351 bsl::basic_string_view<char_type, t_TRAITS> value) BSLS_KEYWORD_NOEXCEPT;
352
353#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
354#ifndef BSLSTL_STRING_VIEW_IS_ALIASED
355 /// Create a @ref basic_format_arg from the specified `value`, which is then
356 /// held by value.
357 template <class t_TRAITS>
358 explicit basic_format_arg(
359 std::basic_string_view<char_type, t_TRAITS> value) BSLS_KEYWORD_NOEXCEPT;
360#endif
361#endif
362
363 /// Create a @ref basic_format_arg holding (by value) a @ref string_view
364 /// constructed from the specified `value`.
365 template <class t_TRAITS, class t_ALLOC>
368
369 /// Create a @ref basic_format_arg holding (by value) a @ref string_view
370 /// constructed from the specified `value`.
371 template <class t_TRAITS, class t_ALLOC>
372 explicit basic_format_arg(
375
376 /// Create a @ref basic_format_arg holding (by value) a @ref string_view
377 /// constructed from the specified `value`.
378 template <class t_TRAITS, class t_ALLOC>
379 explicit basic_format_arg(std::basic_string<char_type, t_TRAITS, t_ALLOC>&
381
382 /// Create a @ref basic_format_arg holding (by value) a @ref string_view
383 /// constructed from the specified `value`.
384 template <class t_TRAITS, class t_ALLOC>
385 explicit basic_format_arg(
386 const std::basic_string<char_type, t_TRAITS, t_ALLOC>& value)
388
389 /// Create a @ref basic_format_arg from the specified `value`, which is then
390 /// held by value.
391 explicit basic_format_arg(char_type *value) BSLS_KEYWORD_NOEXCEPT;
392
393 /// Create a @ref basic_format_arg from the specified `value`, which is then
394 /// held by value.
395 explicit basic_format_arg(const char_type *value) BSLS_KEYWORD_NOEXCEPT;
396
397 /// Create a @ref basic_format_arg from the specified `value`, which is then
398 /// held by value.
399 explicit basic_format_arg(void *value) BSLS_KEYWORD_NOEXCEPT;
400
401 /// Create a @ref basic_format_arg from the specified `value`, which is then
402 /// held by value.
403 explicit basic_format_arg(const void *value) BSLS_KEYWORD_NOEXCEPT;
404
405 /// Create a @ref basic_format_arg which holds
406 /// `static_cast<const void *>(nullptr)`.
408
409 public:
410 // CREATORS
411
412 /// Create a @ref basic_format_arg which holds a `bsl::monostate`.
414
415#if !defined(BSLMF_MOVABLEREF_USES_RVALUE_REFERENCES)
416 /// Move-construct a @ref basic_format_arg from the specified `rhs`. This is
417 /// required to support use on C++03, but must *not* be specified for C++11
418 /// and later as it will result in the implicit deletion of other defaulted
419 /// special member functions.
422#endif // !defined(BSLMF_MOVABLEREF_USES_RVALUE_REFERENCES)
423
424 // ACCESSORS
425
426 /// Return whether this object holds a value.
427 operator BoolType() const BSLS_KEYWORD_NOEXCEPT;
428
429 // MANIPULATORS
430
431#if !defined(BSLMF_MOVABLEREF_USES_RVALUE_REFERENCES)
432 /// Move-assign a @ref basic_format_arg from the specified `rhs`. This is
433 /// required to support use on C++03, but must *not* be specified for C++11
434 /// and later as it will result in the implicit deletion of other defaulted
435 /// special member functions.
436 basic_format_arg &operator=(
438#endif // !defined(BSLMF_MOVABLEREF_USES_RVALUE_REFERENCES)
439
440#if defined(BSLS_LIBRARYFEATURES_HAS_CPP14_BASELINE_LIBRARY) && \
441 defined(BSLS_LIBRARYFEATURES_HAS_CPP14_INTEGER_SEQUENCE)
442 // This check is a proxy for BSL_VARIANT_FULL_IMPLEMENTATION which is unset
443 // at the end of bslstl_variant.h
444
445 /// Invoke the specified `visitor` functor on the value contained by this
446 /// object, providing that functor non-modifiable access to that value.
447 /// `visitor` must be a `variant`-style functor that is able to visit all
448 /// supported types listed in the {DESCRIPTION}.
449 template <class t_VISITOR>
450 decltype(auto) visit(t_VISITOR&& visitor);
451#else
452 /// Invoke the specified `visitor` functor on the value contained by this
453 /// object, providing that functor non-modifiable access to that value.
454 /// `visitor` must be a `variant`-style functor that is able to visit all
455 /// supported types listed in the {DESCRIPTION}.
456 template <class t_VISITOR>
458 t_VISITOR& visitor);
459#endif
460
461 // HIDDEN FRIENDS
462
463 /// Exchange the values of the specified `lhs` and `rhs`.
464 friend void swap(basic_format_arg& lhs, basic_format_arg& rhs)
465 {
466 lhs.d_value.swap(rhs.d_value);
467 }
468};
469
470 // ====================
471 // class Format_ArgUtil
472 // ====================
473
474#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
475/// This class provides utility functions to enable manipulation of types
476/// declared by this component. It is solely for private use by other
477/// components of the `bslfmt` package and should not be used directly.
478///
479/// See @ref bslfmt_format_arg
481 public:
482 // CLASS METHODS
483
484 /// Replace the members of the specified `out` parameter by
485 /// @ref basic_format_arg objects constructed from the members of the
486 /// specified @ref fmt_args parameter.
487 template <class t_CONTEXT, class... t_FMTARGS>
488 static void makeFormatArgArray(
489 bsl::array<basic_format_arg<t_CONTEXT>, sizeof...(t_FMTARGS)> *out,
490 t_FMTARGS&... fmt_args);
491};
492
493#endif
494
495// FREE FUNCTIONS
496
497#if defined(BSLS_LIBRARYFEATURES_HAS_CPP14_BASELINE_LIBRARY) && \
498 defined(BSLS_LIBRARYFEATURES_HAS_CPP14_INTEGER_SEQUENCE)
499 // This check is a proxy for BSL_VARIANT_FULL_IMPLEMENTATION which is unset
500 // at the end of bslstl_variant.h
501
502/// Invoke the specified `visitor` functor on the value contained by the
503/// specified `arg`, providing that functor non-modifiable access to that
504/// value. `visitor` must be a `variant`-style functor that is able to visit
505/// all supported types listed in the {DESCRIPTION}.
506template <class t_VISITOR, class t_CONTEXT>
507decltype(auto) visit_format_arg(t_VISITOR&& visitor,
509#else
510
511/// Invoke the specified `visitor` functor on the value contained by the
512/// specified `arg`, providing that functor non-modifiable access to that
513/// value. `visitor` must be a `variant`-style functor that is able to visit
514/// all supported types listed in the {DESCRIPTION}.
515template <class t_VISITOR, class t_CONTEXT>
517visit_format_arg(t_VISITOR& visitor, basic_format_arg<t_CONTEXT> arg);
518#endif
519
520// ============================================================================
521// INLINE DEFINITIONS
522// ============================================================================
523
524 // ----------------------
525 // class basic_format_arg
526 // ----------------------
527
528// PRIVATE CLASS METHODS
529template <class t_OUT, class t_CHAR>
530template <class t_TYPE>
531inline
532void
536 const void *value)
537{
539 pc.advance_to(f.parse(pc));
540 fc.advance_to(f.format(*static_cast<const t_TYPE *>(value), fc));
541}
542
543// PRIVATE CREATORS
544template <class t_OUT, class t_CHAR>
545template <class t_TYPE>
546inline
547basic_format_arg<basic_format_context<t_OUT, t_CHAR> >::handle::handle(
548 const t_TYPE& value) BSLS_KEYWORD_NOEXCEPT
549: d_value_p(BSLS_UTIL_ADDRESSOF(value))
550, d_format_impl_p(format_impl<t_TYPE>)
551{
552}
553
554// CREATORS
555#if !defined(BSLMF_MOVABLEREF_USES_RVALUE_REFERENCES)
556template <class t_OUT, class t_CHAR>
557inline
566#endif // !defined(BSLMF_MOVABLEREF_USES_RVALUE_REFERENCES)
567
568// ACCESSORS
569template <class t_OUT, class t_CHAR>
570inline
574{
575 d_format_impl_p(pc, fc, d_value_p);
576}
577
578 // ----------------------
579 // class basic_format_arg
580 // ----------------------
581
582// MANIPULATORS
583
584#if defined(BSLS_LIBRARYFEATURES_HAS_CPP14_BASELINE_LIBRARY) && \
585 defined(BSLS_LIBRARYFEATURES_HAS_CPP14_INTEGER_SEQUENCE)
586 // This check is a proxy for BSL_VARIANT_FULL_IMPLEMENTATION which is unset
587 // at the end of bslstl_variant.h
588template <class t_OUT, class t_CHAR>
589template <class t_VISITOR>
590inline
592 t_VISITOR&& v)
593{
594 auto thisCopy(*this);
595 return bsl::visit(std::forward<t_VISITOR>(v), thisCopy.d_value);
596}
597#else
598template <class t_OUT, class t_CHAR>
599template <class t_VISITOR>
600inline
603{
604 basic_format_arg thisCopy(*this);
605 return bsl::visit(v, thisCopy.d_value);
606}
607#endif
608
609// PRIVATE CREATORS
610template <class t_OUT, class t_CHAR>
611inline
613 bool value) BSLS_KEYWORD_NOEXCEPT
614: d_value(value)
615{
616}
617
618template <class t_OUT, class t_CHAR>
619inline
620basic_format_arg<basic_format_context<t_OUT, t_CHAR> >::basic_format_arg(
621 char_type value) BSLS_KEYWORD_NOEXCEPT
622: d_value(value)
623{
624}
625
626template <class t_OUT, class t_CHAR>
627template <class t_TYPE>
628inline
629basic_format_arg<basic_format_context<t_OUT, t_CHAR> >::basic_format_arg(
630 t_TYPE value,
633 int>::type) BSLS_KEYWORD_NOEXCEPT
634{
635 static const std::ctype<wchar_t>& ct =
636 std::use_facet<std::ctype<wchar_t> >(std::locale::classic());
637 d_value = ct.widen(value);
638}
639
640template <class t_OUT, class t_CHAR>
641template <class t_TYPE>
642inline
643basic_format_arg<basic_format_context<t_OUT, t_CHAR> >::basic_format_arg(
644 t_TYPE value,
648 (sizeof(t_TYPE) <= sizeof(long long)),
649 int>::type) BSLS_KEYWORD_NOEXCEPT
650{
651 if (static_cast<t_TYPE>(-1) < static_cast<t_TYPE>(0)) {
652 // `t_TYPE` is signed
653 if (sizeof(t_TYPE) <= sizeof(int)) {
654 d_value.template emplace<int>(static_cast<int>(value));
655 }
656 else {
657 d_value.template emplace<long long>(value);
658 }
659 }
660 else {
661 // `t_TYPE` is unsigned
662 if (sizeof(t_TYPE) <= sizeof(int)) {
663 d_value.template emplace<unsigned int>(
664 static_cast<unsigned int>(value));
665 }
666 else {
667 d_value.template emplace<unsigned long long>(value);
668 }
669 }
670}
671
672template <class t_OUT, class t_CHAR>
673template <class t_TYPE>
674inline
675basic_format_arg<basic_format_context<t_OUT, t_CHAR> >::basic_format_arg(
676 const t_TYPE& value,
679 (sizeof(t_TYPE) > sizeof(long long)),
680 int>::type) BSLS_KEYWORD_NOEXCEPT
681: d_value(handle(value))
682{
683}
684
685template <class t_OUT, class t_CHAR>
686inline
687basic_format_arg<basic_format_context<t_OUT, t_CHAR> >::basic_format_arg(
688 float value) BSLS_KEYWORD_NOEXCEPT
689: d_value(value)
690{
691}
692
693template <class t_OUT, class t_CHAR>
694inline
695basic_format_arg<basic_format_context<t_OUT, t_CHAR> >::basic_format_arg(
696 double value) BSLS_KEYWORD_NOEXCEPT
697: d_value(value)
698{
699}
700
701template <class t_OUT, class t_CHAR>
702template <class t_TYPE>
703inline
704basic_format_arg<basic_format_context<t_OUT, t_CHAR> >::basic_format_arg(
705 t_TYPE value,
707 int>::type) BSLS_KEYWORD_NOEXCEPT
708: d_value(static_cast<long double>(value))
709{
710#ifdef BSLS_COMPILERFEATURES_SUPPORT_STATIC_ASSERT
712 "long double not supported by bsl::format");
713#else
715#endif
716}
717
718template <class t_OUT, class t_CHAR>
719template <class t_TRAITS>
720inline
721basic_format_arg<basic_format_context<t_OUT, t_CHAR> >::basic_format_arg(
723: d_value(static_cast<bsl::basic_string_view<char_type> >(value))
724{
725}
726
727#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
728#ifndef BSLSTL_STRING_VIEW_IS_ALIASED
729template <class t_OUT, class t_CHAR>
730template <class t_TRAITS>
731inline
732basic_format_arg<basic_format_context<t_OUT, t_CHAR> >::basic_format_arg(
733 std::basic_string_view<char_type, t_TRAITS> value) BSLS_KEYWORD_NOEXCEPT
734: d_value(static_cast<bsl::basic_string_view<char_type> >(value))
735{
736}
737#endif
738#endif
739
740template <class t_OUT, class t_CHAR>
741template <class t_TRAITS, class t_ALLOC>
742inline
743basic_format_arg<basic_format_context<t_OUT, t_CHAR> >::basic_format_arg(
745: d_value(static_cast<bsl::basic_string_view<char_type> >(value))
746{
747}
748
749template <class t_OUT, class t_CHAR>
750template <class t_TRAITS, class t_ALLOC>
751inline
752basic_format_arg<basic_format_context<t_OUT, t_CHAR> >::basic_format_arg(
755: d_value(static_cast<bsl::basic_string_view<char_type> >(value))
756{
757}
758
759template <class t_OUT, class t_CHAR>
760template <class t_TRAITS, class t_ALLOC>
761inline
762basic_format_arg<basic_format_context<t_OUT, t_CHAR> >::basic_format_arg(
763 std::basic_string<char_type, t_TRAITS, t_ALLOC>& value) BSLS_KEYWORD_NOEXCEPT
764: d_value(static_cast<bsl::basic_string_view<char_type> >(value))
765{
766}
767
768template <class t_OUT, class t_CHAR>
769template <class t_TRAITS, class t_ALLOC>
770inline
771basic_format_arg<basic_format_context<t_OUT, t_CHAR> >::basic_format_arg(
772 const std::basic_string<char_type, t_TRAITS, t_ALLOC>& value)
774: d_value(static_cast<bsl::basic_string_view<char_type> >(value))
775{
776}
777
778template <class t_OUT, class t_CHAR>
779inline
780basic_format_arg<basic_format_context<t_OUT, t_CHAR> >::basic_format_arg(
781 char_type *value) BSLS_KEYWORD_NOEXCEPT
782: d_value(static_cast<const char_type *>(value))
783{
784}
785
786template <class t_OUT, class t_CHAR>
787inline
788basic_format_arg<basic_format_context<t_OUT, t_CHAR> >::basic_format_arg(
789 const char_type *value) BSLS_KEYWORD_NOEXCEPT
790: d_value(value)
791{
792}
793
794template <class t_OUT, class t_CHAR>
795inline
796basic_format_arg<basic_format_context<t_OUT, t_CHAR> >::basic_format_arg(
797 void *value) BSLS_KEYWORD_NOEXCEPT
798: d_value(static_cast<const void *>(value))
799{
800}
801
802template <class t_OUT, class t_CHAR>
803inline
804basic_format_arg<basic_format_context<t_OUT, t_CHAR> >::basic_format_arg(
805 const void *value) BSLS_KEYWORD_NOEXCEPT
806: d_value(value)
807{
808}
809
810template <class t_OUT, class t_CHAR>
811inline
812basic_format_arg<basic_format_context<t_OUT, t_CHAR> >::basic_format_arg(
814
815#if defined(BSLS_COMPILERFEATURES_SUPPORT_NULLPTR)
816: d_value(static_cast<const void *>(nullptr))
817#else
818: d_value(static_cast<const void *>(0))
819#endif
820{
821}
822
823// CREATORS
824template <class t_OUT, class t_CHAR>
825inline
830
831#if !defined(BSLMF_MOVABLEREF_USES_RVALUE_REFERENCES)
832template <class t_OUT, class t_CHAR>
833inline
840#endif // !defined(BSLMF_MOVABLEREF_USES_RVALUE_REFERENCES)
841
842// ACCESSORS
843template <class t_OUT, class t_CHAR>
844inline
847{
848 return UnspecifiedBoolType::makeValue(
849 !bsl::holds_alternative<bsl::monostate>(d_value));
850}
851
852// MANIPULATORS
853#if !defined(BSLMF_MOVABLEREF_USES_RVALUE_REFERENCES)
854template <class t_OUT, class t_CHAR>
855inline
864#endif // !defined(BSLMF_MOVABLEREF_USES_RVALUE_REFERENCES)
865
866 // --------------------
867 // class Format_ArgUtil
868 // --------------------
869
870// CLASS METHODS
871
872#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
873template <class t_CONTEXT, class... t_FMTARGS>
874inline
876 bsl::array<basic_format_arg<t_CONTEXT>, sizeof...(t_FMTARGS)> *out,
877 t_FMTARGS&... fmt_args)
878{
879#ifndef BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS
880 // Use the form of braced initialization that is valid in C++03
881 bsl::array<basic_format_arg<t_CONTEXT>, sizeof...(t_FMTARGS)> tmp = {
882 {basic_format_arg<t_CONTEXT>(fmt_args)...}};
883 *out = bslmf::MovableRefUtil::move(tmp);
884#else
885 *out = { {basic_format_arg<t_CONTEXT>(fmt_args)...} };
886#endif
887}
888#endif
889
890// FREE FUNCTIONS
891
892#if defined(BSLS_LIBRARYFEATURES_HAS_CPP14_BASELINE_LIBRARY) && \
893 defined(BSLS_LIBRARYFEATURES_HAS_CPP14_INTEGER_SEQUENCE)
894 // This check is a proxy for BSL_VARIANT_FULL_IMPLEMENTATION which is unset
895 // at the end of bslstl_variant.h
896template <class t_VISITOR, class t_CONTEXT>
897inline
898decltype(auto) visit_format_arg(t_VISITOR&& visitor,
900{
901 return arg.visit(std::forward<t_VISITOR>(visitor));
902}
903#else
904template <class t_VISITOR, class t_CONTEXT>
905inline
908{
909 return arg.visit(visitor);
910}
911#endif
912
913} // close package namespace
914
915
916#endif // End C++11 code
917
918#endif // INCLUDED_BSLFMT_FORMAT_ARG
919
920// ----------------------------------------------------------------------------
921// Copyright 2023 Bloomberg Finance L.P.
922//
923// Licensed under the Apache License, Version 2.0 (the "License");
924// you may not use this file except in compliance with the License.
925// You may obtain a copy of the License at
926//
927// http://www.apache.org/licenses/LICENSE-2.0
928//
929// Unless required by applicable law or agreed to in writing, software
930// distributed under the License is distributed on an "AS IS" BASIS,
931// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
932// See the License for the specific language governing permissions and
933// limitations under the License.
934// ----------------------------- END-OF-FILE ----------------------------------
935
936/** @} */
937/** @} */
938/** @} */
Definition bslstl_stringview.h:471
Definition bslstl_string.h:1252
Definition bslmf_invokeresult.h:362
Definition bslstl_variant.h:3806
Definition bslfmt_format_arg.h:480
static void makeFormatArgArray(bsl::array< basic_format_arg< t_CONTEXT >, sizeof...(t_FMTARGS)> *out, t_FMTARGS &... fmt_args)
Definition bslfmt_format_arg.h:875
Definition bslfmt_format_context.h:262
BloombergLP::bsls::UnspecifiedBool< basic_format_arg > UnspecifiedBoolType
Definition bslfmt_format_arg.h:246
friend void swap(basic_format_arg &lhs, basic_format_arg &rhs)
Exchange the values of the specified lhs and rhs.
Definition bslfmt_format_arg.h:464
UnspecifiedBoolType::BoolType BoolType
Definition bslfmt_format_arg.h:247
Definition bslfmt_format_arg.h:162
Definition bslfmt_format_context.h:316
void advance_to(iterator it)
Update the contained iterator to that specified by it.
Definition bslfmt_format_context.h:506
Definition bslfmt_formatparsecontext.h:86
BSLS_KEYWORD_CONSTEXPR_CPP20 void advance_to(const_iterator it)
Definition bslfmt_formatparsecontext.h:215
Definition bslmf_movableref.h:752
#define BSLMF_ASSERT(expr)
Definition bslmf_assert.h:231
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
#define BSLS_KEYWORD_DELETED
Definition bsls_keyword.h:651
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:674
#define BSLS_UTIL_ADDRESSOF(OBJ)
Definition bsls_util.h:296
Definition bdlat_valuetypefunctions.h:939
BloombergLP::bsls::Nullptr_Impl::Type nullptr_t
Definition bsls_nullptr.h:283
bsl::invoke_result< t_VISITOR &, typenamebsl::variant_alternative< 0, t_VARIANT >::type & >::type visit(t_VISITOR &visitor, t_VARIANT &variant)
Definition bslstl_variant.h:2359
Definition bslfmt_enablestreamedformatter.h:130
basic_format_context< Format_ContextOutputIteratorRef< char >, char > format_context
Definition bslfmt_format_arg.h:170
bsl::invoke_result< t_VISITOR &, bsl::monostate & >::type visit_format_arg(t_VISITOR &visitor, basic_format_arg< t_CONTEXT > arg)
Definition bslfmt_format_arg.h:907
basic_format_context< Format_ContextOutputIteratorRef< wchar_t >, wchar_t > wformat_context
Definition bslfmt_format_arg.h:173
bsl::string format(BSLFMT_FORMAT_STRING_PARAMETER fmtStr, const t_ARGS &... args)
Definition bslfmt_format_imp.h:1085
Definition bslstl_array.h:293
Definition bslmf_enableif.h:530
Definition bslfmt_formatterbase.h:426
Definition bslmf_isintegral.h:140
Definition bslmf_issame.h:146
Definition bslstl_monostate.h:77
static MovableRef< t_TYPE > move(t_TYPE &reference) BSLS_KEYWORD_NOEXCEPT
Definition bslmf_movableref.h:1067
static t_TYPE & access(t_TYPE &ref) BSLS_KEYWORD_NOEXCEPT
Definition bslmf_movableref.h:1039