libfly  6.2.2
C++20 utility library for Linux, macOS, and Windows
format_context.hpp
1 #pragma once
2 
3 #include "fly/types/string/concepts.hpp"
4 #include "fly/types/string/detail/format_parameters.hpp"
5 #include "fly/types/string/formatters.hpp"
6 
7 #include <cstddef>
8 #include <type_traits>
9 
10 namespace fly::detail {
11 
19 template <typename OutputIterator, fly::StandardCharacter CharType>
21 {
23 
24 public:
25  using char_type = CharType;
26 
27  template <typename T>
29 
36  template <typename... Parameters>
37  constexpr BasicFormatContext(
38  OutputIterator out,
40 
49  FormatParameter arg(std::size_t index) const;
50 
54  OutputIterator &out();
55 
56 private:
57  BasicFormatContext(const BasicFormatContext &) = delete;
58  BasicFormatContext &operator=(const BasicFormatContext &) = delete;
59 
60  OutputIterator m_out;
61 
62  const FormatParameter *m_parameters;
63  const std::size_t m_parameters_size;
64 };
65 
66 //==================================================================================================
67 template <typename OutputIterator, fly::StandardCharacter CharType>
68 template <typename... Parameters>
70  OutputIterator out,
72  m_out(std::move(out)),
73  m_parameters(parameters.m_parameters.data()),
74  m_parameters_size(parameters.m_parameters.size())
75 {
76 }
77 
78 //==================================================================================================
79 template <typename OutputIterator, fly::StandardCharacter CharType>
80 inline auto BasicFormatContext<OutputIterator, CharType>::arg(std::size_t index) const
82 {
83  if (index < m_parameters_size)
84  {
85  return m_parameters[index];
86  }
87 
88  return {};
89 }
90 
91 //==================================================================================================
92 template <typename OutputIterator, fly::StandardCharacter CharType>
94 {
95  return m_out;
96 }
97 
98 } // namespace fly::detail
Definition: format_context.hpp:21
FormatParameter arg(std::size_t index) const
Definition: format_context.hpp:80
OutputIterator & out()
Definition: format_context.hpp:93
constexpr BasicFormatContext(OutputIterator out, const BasicFormatParameters< BasicFormatContext, Parameters... > &parameters) noexcept
Definition: format_context.hpp:69
Definition: format_parameters.hpp:139
Definition: format_parameters.hpp:271
Definition: formatters.hpp:42