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 //===----------------------------------------------------------------------===//
9 
10 #ifndef _LIBCPP___FORMAT_FORMAT_ARGS_H
11 #define _LIBCPP___FORMAT_FORMAT_ARGS_H
12 
13 #include <__availability>
14 #include <__config>
15 #include <__format/format_fwd.h>
16 #include <cstddef>
17 
18 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19 #  pragma GCC system_header
20 #endif
21 
22 _LIBCPP_BEGIN_NAMESPACE_STD
23 
24 #if _LIBCPP_STD_VER > 17
25 
26 // TODO FMT Remove this once we require compilers with proper C++20 support.
27 // If the compiler has no concepts support, the format header will be disabled.
28 // Without concepts support enable_if needs to be used and that too much effort
29 // to support compilers with partial C++20 support.
30 #if !defined(_LIBCPP_HAS_NO_CONCEPTS)
31 
32 template <class _Context>
33 class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FORMAT basic_format_args {
34 public:
35   // TODO FMT Implement [format.args]/5
36   // [Note 1: Implementations are encouraged to optimize the representation of
37   // basic_format_args for small number of formatting arguments by storing
38   // indices of type alternatives separately from values and packing the
39   // former. - end note]
40   // Note: Change  __format_arg_store to use a built-in array.
41   _LIBCPP_HIDE_FROM_ABI basic_format_args() noexcept = default;
42 
43   template <class... _Args>
44   _LIBCPP_HIDE_FROM_ABI basic_format_args(
45       const __format_arg_store<_Context, _Args...>& __store) noexcept
46       : __size_(sizeof...(_Args)), __data_(__store.__args.data()) {}
47 
48   _LIBCPP_HIDE_FROM_ABI
49   basic_format_arg<_Context> get(size_t __id) const noexcept {
50     return __id < __size_ ? __data_[__id] : basic_format_arg<_Context>{};
51   }
52 
53   _LIBCPP_HIDE_FROM_ABI size_t __size() const noexcept { return __size_; }
54 
55 private:
56   size_t __size_{0};
57   const basic_format_arg<_Context>* __data_{nullptr};
58 };
59 
60 #endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
61 
62 #endif //_LIBCPP_STD_VER > 17
63 
64 _LIBCPP_END_NAMESPACE_STD
65 
66 #endif // _LIBCPP___FORMAT_FORMAT_ARGS_H
67