HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
delayed_format.hpp
1// Copyright Take Vos 2021.
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 <fmt/format.h>
6#include <tuple>
7#include "forward_value.hpp"
8#include "fixed_string.hpp"
9
10#pragma once
11
12namespace tt {
13
18template<basic_fixed_string Fmt, typename... Values>
20public:
21 static_assert(std::is_same_v<decltype(Fmt)::value_type, char>, "Fmt must be a basic_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 &&...args) noexcept : _values(forward_value<Args>{}(args)...)
43 {
44 }
45
49 [[nodiscard]] std::string operator()() const noexcept
50 {
51 auto tmp = std::tuple_cat(std::tuple{static_cast<char const *>(Fmt)}, _values);
52 return std::apply(fmt::format<char const *,Values const &...>, std::move(tmp));
53 }
54
59 [[nodiscard]] std::string operator()(std::locale const &loc) const noexcept
60 {
61 tt_not_implemented();
62 }
63
64private:
65 std::tuple<Values...> _values;
66};
67
68template<fixed_string Fmt, typename... Args>
69delayed_format(Args &&...) -> delayed_format<Fmt, forward_value_t<Args>...>;
70
71} // namespace tt
Delayed formatting.
Definition delayed_format.hpp:19
delayed_format(Args &&...args) noexcept
Construct a delayed format.
Definition delayed_format.hpp:42
std::string operator()() const noexcept
Format now.
Definition delayed_format.hpp:49
std::string operator()(std::locale const &loc) const noexcept
Format now.
Definition delayed_format.hpp:59
Functor for forwarding an forwarding-reference to variable.
Definition forward_value.hpp:29
T move(T... args)
T tuple_cat(T... args)