tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
basic_format_arg.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2023 Tobias Hienzsch
3
4#ifndef TETL_FORMAT_BASIC_FORMAT_ARG_HPP
5#define TETL_FORMAT_BASIC_FORMAT_ARG_HPP
6
7#include <etl/_cstddef/nullptr_t.hpp>
8#include <etl/_cstddef/size_t.hpp>
9#include <etl/_format/basic_format_parse_context.hpp>
10#include <etl/_string/basic_inplace_string.hpp>
11#include <etl/_string_view/basic_string_view.hpp>
12#include <etl/_utility/forward.hpp>
13#include <etl/_variant/monostate.hpp>
14#include <etl/_variant/variant.hpp>
15namespace etl {
16
17template <typename Context>
18struct basic_format_arg;
19
20namespace detail {
21template <typename Context, typename T>
22[[nodiscard]] constexpr auto make_arg(T&& value) -> basic_format_arg<Context>;
23} // namespace detail
24
25template <typename Context>
26struct basic_format_arg {
27private:
28 using char_type = typename Context::char_type;
29
30 template <typename ContextType, typename T>
31 friend constexpr auto detail::make_arg(T&& value) -> basic_format_arg<ContextType>;
32
33public:
34 struct handle {
35 auto format(basic_format_parse_context<char_type>&, Context& ctx) const -> void;
36
37 private:
38 friend struct basic_format_arg<Context>;
39
40 template <typename T>
41 explicit handle(T&& val) noexcept;
42
43 void const* _ptr;
44 void (*_format)(basic_format_parse_context<char_type>&, Context&, void const*);
45 };
46
47 basic_format_arg() noexcept = default;
48
49 explicit operator bool() const noexcept
50 {
51 return holds_alternative<monostate>(value);
52 }
53
54 template <typename T>
55 explicit basic_format_arg(T&& v) noexcept;
56 explicit basic_format_arg(float n) noexcept;
57 explicit basic_format_arg(double n) noexcept;
58 explicit basic_format_arg(long double n) noexcept;
59 explicit basic_format_arg(char_type const* s);
60
61 template <typename Traits>
62 explicit basic_format_arg(basic_string_view<char_type, Traits> s) noexcept;
63
64 template <etl::size_t Capacity, typename Traits>
65 explicit basic_format_arg(basic_inplace_string<char_type, Capacity, Traits> const& s) noexcept;
66
67 explicit basic_format_arg(nullptr_t) noexcept;
68
69 template <typename T>
70 explicit basic_format_arg(T* p) noexcept;
71
72 variant< // variant< // monostate, //
73 bool, //
74 char_type, //
75 int, //
76 unsigned int, //
77 long long int, //
78 unsigned long long int, //
79 float, //
80 double, //
81 long double, //
82 char_type const*, //
83 basic_string_view<char_type>, //
84 void const*, //
85 handle //
86 >
88};
89
90namespace detail {
91template <typename Context, typename T>
92[[nodiscard]] constexpr auto make_arg(T&& value) -> basic_format_arg<Context>
93{
94 return {etl::forward<T>(value)};
95}
96} // namespace detail
97
98} // namespace etl
99
100#endif // TETL_FORMAT_BASIC_FORMAT_ARG_HPP
Definition adjacent_find.hpp:9
Definition basic_format_arg.hpp:34
auto format(basic_format_parse_context< char_type > &, Context &ctx) const -> void
basic_format_arg(double n) noexcept
variant< bool, char_type, int, unsigned int, long long int, unsigned long long int, float, double, long double, char_type const *, basic_string_view< char_type >, void const *, handle > value
Definition basic_format_arg.hpp:87
basic_format_arg(T &&v) noexcept
operator bool() const noexcept
Definition basic_format_arg.hpp:49
basic_format_arg(float n) noexcept
basic_format_arg(char_type const *s)
basic_format_arg() noexcept=default
basic_format_arg(basic_string_view< char_type, Traits > s) noexcept
basic_format_arg(nullptr_t) noexcept
basic_format_arg(long double n) noexcept
basic_format_arg(T *p) noexcept
basic_format_arg(basic_inplace_string< char_type, Capacity, Traits > const &s) noexcept
Definition basic_format_parse_context.hpp:14
basic_inplace_string class with fixed size capacity.
Definition basic_inplace_string.hpp:42
The class template basic_string_view describes an object that can refer to a constant contiguous sequ...
Definition basic_string_view.hpp:35
Unit type intended for use as a well-behaved empty alternative in etl::variant. In particular,...
Definition monostate.hpp:17
Definition variant.hpp:99