HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
delayed_format.hpp
1// Copyright Take Vos 2021-2022.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "../utility/utility.hpp"
8#include "../macros.hpp"
9#include <format>
10#include <tuple>
11
12hi_export_module(hikogui.telemetry.delayed_format);
13
14hi_export namespace hi::inline v1 {
15
20template<fixed_string Fmt, typename... Values>
22public:
23 static_assert(std::is_same_v<typename decltype(Fmt)::value_type, char>, "Fmt must be a fixed_string<char>");
24
25 delayed_format(delayed_format &&) noexcept = default;
26 delayed_format(delayed_format const &) noexcept = default;
27 delayed_format &operator=(delayed_format &&) noexcept = default;
28 delayed_format &operator=(delayed_format const &) noexcept = default;
29
43 template<typename... Args>
44 delayed_format(Args const &...args) noexcept : _values(args...)
45 {
46 }
47
51 [[nodiscard]] std::string operator()() const noexcept
52 {
53 return std::apply(format_wrapper<Values const &...>, _values);
54 }
55
60 [[nodiscard]] std::string operator()(std::locale const &loc) const noexcept
61 {
62 return std::apply(format_locale_wrapper<Values const &...>, _values);
63 }
64
65private:
66 std::tuple<Values...> _values;
67
68 template<typename... Args>
69 static std::string format_wrapper(Args const &...args)
70 {
71 return std::format(static_cast<std::string_view>(Fmt), args...);
72 }
73
74 template<typename... Args>
75 static std::string format_locale_wrapper(std::locale const &loc, Args const &...args)
76 {
77 return std::format(loc, static_cast<std::string_view>(Fmt), args...);
78 }
79};
80
81} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Delayed formatting.
Definition delayed_format.hpp:21
delayed_format(Args const &...args) noexcept
Construct a delayed format.
Definition delayed_format.hpp:44
std::string operator()(std::locale const &loc) const noexcept
Format now.
Definition delayed_format.hpp:60
std::string operator()() const noexcept
Format now.
Definition delayed_format.hpp:51