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
3#ifndef TETL_FORMAT_BASIC_FORMAT_ARG_HPP
4#define TETL_FORMAT_BASIC_FORMAT_ARG_HPP
5
14namespace etl {
15
16template <typename Context>
17struct basic_format_arg;
18
19namespace detail {
20template <typename Context, typename T>
21[[nodiscard]] constexpr auto make_arg(T&& value) -> basic_format_arg<Context>;
22}
23
24template <typename Context>
26private:
27 using char_type = typename Context::char_type;
28
29 template <typename ContextType, typename T>
30 friend constexpr auto detail::make_arg(T&& value) -> basic_format_arg<ContextType>;
31
32public:
33 struct handle {
34 auto format(basic_format_parse_context<char_type>&, Context& ctx) const -> void;
35
36 private:
37 friend struct basic_format_arg<Context>;
38
39 template <typename T>
40 explicit handle(T&& val) noexcept;
41
42 void const* _ptr;
43 void (*_format)(basic_format_parse_context<char_type>&, Context&, void const*);
44 };
45
46 basic_format_arg() noexcept = default;
47
48 explicit operator bool() const noexcept { return holds_alternative<monostate>(value); }
49
50 template <typename T>
51 explicit basic_format_arg(T&& v) noexcept;
52 explicit basic_format_arg(float n) noexcept;
53 explicit basic_format_arg(double n) noexcept;
54 explicit basic_format_arg(long double n) noexcept;
55 explicit basic_format_arg(char_type const* s);
56
57 template <typename Traits>
59
60 template <etl::size_t Capacity, typename Traits>
62
63 explicit basic_format_arg(nullptr_t) noexcept;
64
65 template <typename T>
66 explicit basic_format_arg(T* p) noexcept;
67
68 variant< // variant< // monostate, //
69 bool, //
70 char_type, //
71 int, //
72 unsigned int, //
73 long long int, //
74 unsigned long long int, //
75 float, //
76 double, //
77 long double, //
78 char_type const*, //
80 void const*, //
81 handle //
82 >
84};
85
86namespace detail {
87template <typename Context, typename T>
88[[nodiscard]] constexpr auto make_arg(T&& value) -> basic_format_arg<Context>
89{
90 return {etl::forward<T>(value)};
91}
92} // namespace detail
93
94} // namespace etl
95
96#endif // TETL_FORMAT_BASIC_FORMAT_ARG_HPP
Definition adjacent_find.hpp:8
constexpr auto forward(remove_reference_t< T > &param) noexcept -> T &&
Forwards lvalues as either lvalues or as rvalues, depending on T. When t is a forwarding reference (a...
Definition forward.hpp:18
decltype(nullptr) nullptr_t
etl::nullptr_t is the type of the null pointer literal, nullptr. It is a distinct type that is not it...
Definition nullptr_t.hpp:13
Definition basic_format_arg.hpp:33
auto format(basic_format_parse_context< char_type > &, Context &ctx) const -> void
Definition basic_format_arg.hpp:25
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:83
basic_format_arg(T &&v) noexcept
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:13
basic_inplace_string class with fixed size capacity.
Definition basic_inplace_string.hpp:41
The class template basic_string_view describes an object that can refer to a constant contiguous sequ...
Definition basic_string_view.hpp:34
Unit type intended for use as a well-behaved empty alternative in etl::variant. In particular,...
Definition monostate.hpp:16
Definition variant.hpp:98
constexpr auto holds_alternative(variant< Ts... > const &v) noexcept -> bool
Checks if the variant v holds the alternative T. The call is ill-formed if T does not appear exactly ...
Definition variant.hpp:384