Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / include / __format / format_args.h
blobdefb42a4ab0067fc48246d8480a2ba49da4bef01
1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___FORMAT_FORMAT_ARGS_H
11 #define _LIBCPP___FORMAT_FORMAT_ARGS_H
13 #include <__availability>
14 #include <__config>
15 #include <__format/format_arg.h>
16 #include <__format/format_arg_store.h>
17 #include <__format/format_fwd.h>
18 #include <cstddef>
19 #include <cstdint>
21 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22 # pragma GCC system_header
23 #endif
25 _LIBCPP_BEGIN_NAMESPACE_STD
27 #if _LIBCPP_STD_VER >= 20
29 template <class _Context>
30 class _LIBCPP_TEMPLATE_VIS basic_format_args {
31 public:
32 basic_format_args() noexcept = default;
34 template <class... _Args>
35 _LIBCPP_HIDE_FROM_ABI basic_format_args(const __format_arg_store<_Context, _Args...>& __store) noexcept
36 : __size_(sizeof...(_Args)) {
37 if constexpr (sizeof...(_Args) != 0) {
38 if constexpr (__format::__use_packed_format_arg_store(sizeof...(_Args))) {
39 __values_ = __store.__storage.__values_;
40 __types_ = __store.__storage.__types_;
41 } else
42 __args_ = __store.__storage.__args_;
46 _LIBCPP_HIDE_FROM_ABI
47 basic_format_arg<_Context> get(size_t __id) const noexcept {
48 if (__id >= __size_)
49 return basic_format_arg<_Context>{};
51 if (__format::__use_packed_format_arg_store(__size_))
52 return basic_format_arg<_Context>{__format::__get_packed_type(__types_, __id), __values_[__id]};
54 return __args_[__id];
57 _LIBCPP_HIDE_FROM_ABI size_t __size() const noexcept { return __size_; }
59 private:
60 size_t __size_{0};
61 // [format.args]/5
62 // [Note 1: Implementations are encouraged to optimize the representation of
63 // basic_format_args for small number of formatting arguments by storing
64 // indices of type alternatives separately from values and packing the
65 // former. - end note]
66 union {
67 struct {
68 const __basic_format_arg_value<_Context>* __values_;
69 uint64_t __types_;
71 const basic_format_arg<_Context>* __args_;
75 template <class _Context, class... _Args>
76 basic_format_args(__format_arg_store<_Context, _Args...>) -> basic_format_args<_Context>;
78 #endif //_LIBCPP_STD_VER >= 20
80 _LIBCPP_END_NAMESPACE_STD
82 #endif // _LIBCPP___FORMAT_FORMAT_ARGS_H