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