MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Format.hpp
Go to the documentation of this file.
1#pragma once
2
3#if MAYAFLUX_USE_STD_FORMAT
4#include <format>
5namespace MayaFlux::Journal::fmt {
6using std::format;
7using std::format_string;
8using std::make_format_args;
9using std::vformat;
10}
11#elif MAYAFLUX_USE_FMT
12#include <fmt/core.h>
13#include <fmt/format.h>
14namespace MayaFlux::Journal::fmt {
15using ::fmt::format;
16using ::fmt::format_string;
17using ::fmt::make_format_args;
18using ::fmt::vformat;
19}
20#else
21#error "No formatting library available. Either std::format or fmt is required."
22#endif
23
24namespace MayaFlux::Journal {
25
26template <typename... Args>
27using format_string = fmt::format_string<Args...>;
28
29template <typename... Args>
30inline std::string format(format_string<std::remove_cvref_t<Args>...> fmt_str, Args&&... args)
31{
32 return fmt::format(fmt_str, std::forward<Args>(args)...);
33}
34
35template <typename... Args>
36inline std::string format_runtime(std::string_view fmt_str, Args&&... args)
37{
38#if MAYAFLUX_USE_STD_FORMAT
39 return std::vformat(fmt_str, std::make_format_args(args...));
40#elif MAYAFLUX_USE_FMT
41 return fmt::vformat(fmt_str, fmt::make_format_args(args...));
42#endif
43}
44
45inline std::string vformat(std::string_view fmt_str, auto fmt_args)
46{
47 return fmt::vformat(fmt_str, fmt_args);
48}
49
50} // namespace MayaFlux::Journal
std::string vformat(std::string_view fmt_str, auto fmt_args)
Definition Format.hpp:45
fmt::format_string< Args... > format_string
Definition Format.hpp:27
std::string format_runtime(std::string_view fmt_str, Args &&... args)
Definition Format.hpp:36
std::string format(format_string< std::remove_cvref_t< Args >... > fmt_str, Args &&... args)
Definition Format.hpp:30