-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint_format.hh
58 lines (49 loc) · 1.36 KB
/
print_format.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef __OICOMPARE_PRINT_FORMAT_HH__
#define __OICOMPARE_PRINT_FORMAT_HH__
#include <utility>
#include <fmt/format.h>
namespace
{
template <typename CharT, typename Func> struct basic_print_format
{
constexpr explicit basic_print_format (Func &&func)
: func{std::forward<Func> (func)}
{
}
Func func;
};
template <typename Func>
constexpr auto
print_format (Func &&func)
{
return basic_print_format<char, Func> (std::forward<Func> (func));
}
}
template <typename CharT, typename Func>
struct fmt::formatter<basic_print_format<CharT, Func>>
{
template <typename OutputIt>
constexpr fmt::basic_format_context<OutputIt, CharT>::iterator
format (basic_print_format<CharT, Func> &&obj,
fmt::basic_format_context<OutputIt, CharT> &ctx) const
{
return std::move (obj).func (ctx);
}
template <typename OutputIt>
constexpr fmt::basic_format_context<OutputIt, CharT>::iterator
format (basic_print_format<CharT, Func> &obj,
fmt::basic_format_context<OutputIt, CharT> &ctx) const
{
return format (std::move (obj), ctx);
}
constexpr auto
parse (basic_format_parse_context<CharT> &ctx) const
-> format_parse_context::iterator
{
auto it = ctx.begin (), end = ctx.end ();
if (it != end && *it != CharT{'}'})
throw format_error{"invalid format"};
return it;
}
};
#endif /* __OICOMPARE_PRINT_FORMAT_HH__*/