Euphoria
pch.public.h
Go to the documentation of this file.
1// public header file for the precompiled header
2
3#include <fmt/core.h>
4#include <fmt/format.h>
5#include <fmt/ranges.h>
6
7// todo(Gustav): add macros should use EU_FMT prefix
8
9// ----------------------------------------------------------------------------
10// Format forwarder for classes
11#define ADD_DEFAULT_FORMATTER(TYPE, STRING, TO_STRING) \
12template <> struct fmt::formatter<TYPE>: fmt::formatter<STRING> \
13{ \
14 template <typename FormatContext> \
15 auto format(const TYPE& c, FormatContext& ctx) const \
16 { \
17 return fmt::formatter<STRING>::format(TO_STRING(c), ctx); \
18 } \
19}
20
21// ----------------------------------------------------------------------------
22// Format enum classes
23#define EU_FMT_ENUM_BEGIN(T, DEF) \
24template <> struct fmt::formatter<T> : fmt::formatter<std::string_view> {\
25 template <typename FormatContext>\
26 auto format(T c, FormatContext& ctx) const {\
27 using EnumType = T;\
28 std::string_view name = DEF;\
29 switch (c) {
30#define EU_FMT_ENUM_VAL(V)\
31 case EnumType::V: name = #V; break
32#define EU_FMT_ENUM_END()\
33 }\
34 return formatter<string_view>::format(name, ctx);\
35 }\
36};
37
38
39// ----------------------------------------------------------------------------
40// catch formatter
41
42#define ADD_CATCH_FORMATTER_DEF(TYPE) \
43std::ostream& \
44operator<<(std::ostream& stream, const TYPE& v);
45
46#define ADD_CATCH_FORMATTER_IMPL(TYPE) \
47std::ostream& \
48operator<<(std::ostream& stream, const TYPE& v) \
49{ \
50 return stream << ::eu::string_from(v); \
51}