tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
basic_format_context.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2021 Tobias Hienzsch
3
4#ifndef TETL_FORMAT_BASIC_FORMAT_CONTEXT_HPP
5#define TETL_FORMAT_BASIC_FORMAT_CONTEXT_HPP
6
7#include <etl/_format/fmt_buffer.hpp>
8#include <etl/_iterator/back_insert_iterator.hpp>
9
10namespace etl {
11template <typename T, typename CharT>
12struct formatter;
13
14/// \brief Provides access to formatting state consisting of the formatting
15/// arguments and the output iterator.
16///
17/// The behavior is undefined if OutputIt does not model output_iterator<const
18/// CharT&>.
19///
20/// https://en.cppreference.com/w/cpp/utility/format/basic_format_context
21template <typename OutputIt, typename CharT>
23 using iterator = OutputIt;
24 using char_type = CharT;
25
26 explicit constexpr basic_format_context(OutputIt pos) noexcept
27 : _pos{pos}
28 {
29 }
30
31 template <typename T>
32 using formatter_type = formatter<T, CharT>;
33
34 /// \brief Returns the iterator to the output buffer.
35 [[nodiscard]] constexpr auto out() noexcept -> iterator
36 {
37 return _pos;
38 }
39
40 /// \brief Sets the output iterator to it. After a call to advance_to,
41 /// subsequent calls to out() will return a copy of it.
42 constexpr auto advance_to(iterator it) noexcept -> void
43 {
44 _pos = it;
45 }
46
47private:
48 OutputIt _pos;
49};
50
51/// \brief Provides access to formatting state consisting of the formatting
52/// arguments and the output iterator.
53///
54/// \details The first template argument is an output iterator that appends to
55/// etl::inplace_string, such as etl::back_insert_iterator<etl::inplace_string>.
56/// Implementations are encouraged to use an iterator to type-erased buffer type
57/// that supports appending to any contiguous and resizable container.
58///
59/// The behavior is undefined if OutputIt does not model output_iterator<const CharT&>.
60///
61/// https://en.cppreference.com/w/cpp/utility/format/basic_format_context
62using format_context = basic_format_context<back_insert_iterator<detail::fmt_buffer<char>>, char>;
63using wformat_context = basic_format_context<back_insert_iterator<detail::fmt_buffer<wchar_t>>, wchar_t>;
64
65} // namespace etl
66
67#endif // TETL_FORMAT_BASIC_FORMAT_CONTEXT_HPP
Definition adjacent_find.hpp:9
etl::back_insert_iterator is a LegacyOutputIterator that appends to a container for which it was cons...
Definition back_insert_iterator.hpp:19
Provides access to formatting state consisting of the formatting arguments and the output iterator.
Definition basic_format_context.hpp:22
constexpr basic_format_context(OutputIt pos) noexcept
Definition basic_format_context.hpp:26
constexpr auto advance_to(iterator it) noexcept -> void
Sets the output iterator to it. After a call to advance_to, subsequent calls to out() will return a c...
Definition basic_format_context.hpp:42
constexpr auto out() noexcept -> iterator
Returns the iterator to the output buffer.
Definition basic_format_context.hpp:35