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#include <format>
6#include <tuple>
7#include "forward_value.hpp"
8#include "fixed_string.hpp"
9
10#pragma once
11
12namespace hi::inline v1 {
13
18template<fixed_string Fmt, typename... Values>
20public:
21 static_assert(std::is_same_v<typename decltype(Fmt)::value_type, char>, "Fmt must be a fixed_string<char>");
22
23 delayed_format(delayed_format &&) noexcept = default;
24 delayed_format(delayed_format const &) noexcept = default;
25 delayed_format &operator=(delayed_format &&) noexcept = default;
26 delayed_format &operator=(delayed_format const &) noexcept = default;
27
41 template<typename... Args>
42 delayed_format(Args const &...args) noexcept : _values(args...)
43 {
44 }
45
49 [[nodiscard]] std::string operator()() const noexcept
50 {
51 return std::apply(format_wrapper<Values const &...>, _values);
52 }
53
58 [[nodiscard]] std::string operator()(std::locale const &loc) const noexcept
59 {
60 return std::apply(format_locale_wrapper<Values const &...>, _values);
61 }
62
63private:
64 std::tuple<Values...> _values;
65
66 template<typename... Args>
67 static std::string format_wrapper(Args const &...args)
68 {
69 return std::format(static_cast<std::string_view>(Fmt), args...);
70 //return std::vformat(static_cast<std::string_view>(Fmt), std::make_format_args(args...));
71 }
72
73 template<typename... Args>
74 static std::string format_locale_wrapper(std::locale const &loc, Args const &...args)
75 {
76 return std::format(loc, static_cast<std::string_view>(Fmt), args...);
77 //return std::vformat(loc, static_cast<std::string_view>(Fmt), std::make_format_args(args...));
78 }
79};
80
81} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm.hpp:15
Delayed formatting.
Definition delayed_format.hpp:19
delayed_format(Args const &...args) noexcept
Construct a delayed format.
Definition delayed_format.hpp:42
std::string operator()(std::locale const &loc) const noexcept
Format now.
Definition delayed_format.hpp:58
std::string operator()() const noexcept
Format now.
Definition delayed_format.hpp:49