AsmGrader 0.0.0
Loading...
Searching...
No Matches
macros.hpp
Go to the documentation of this file.
1#pragma once
2
7
8#include <boost/preprocessor/punctuation/comma_if.hpp>
9#include <boost/preprocessor/seq/for_each_i.hpp>
10#include <boost/preprocessor/stringize.hpp>
11#include <boost/preprocessor/tuple/size.hpp>
12#include <boost/preprocessor/tuple/to_seq.hpp>
13#include <fmt/base.h>
14#include <fmt/format.h>
15#include <fmt/ranges.h>
16#include <range/v3/algorithm/copy.hpp>
17#include <range/v3/view/transform.hpp>
18
19#define FMT_SERIALIZE_CLASS_MEMBER_IMPL(r, class_name, i, ident) \
20 BOOST_PP_COMMA_IF(i)::asmgrader::pair { \
21 ::asmgrader::StaticString{BOOST_PP_STRINGIZE(ident)}, &class_name::ident \
22 }
23
24#define FMT_SERIALIZE_CLASS(class_name, ... /*members*/) \
25 template <> \
26 struct fmt::formatter<class_name> \
27 : ::asmgrader::detail::AggregateFormatter< \
28 class_name, \
29 #class_name __VA_OPT__(, BOOST_PP_SEQ_FOR_EACH_I( \
30 FMT_SERIALIZE_CLASS_MEMBER_IMPL, class_name, \
31 BOOST_PP_TUPLE_TO_SEQ(BOOST_PP_TUPLE_SIZE((__VA_ARGS__)), (__VA_ARGS__))))> \
32 { \
33 }
34
35#define FMT_SERIALIZE_ENUMERATOR_IMPL(r, enum_name, i, ident) \
36 BOOST_PP_COMMA_IF(i)::asmgrader::pair { \
37 ::asmgrader::StaticString{BOOST_PP_STRINGIZE(ident)}, enum_name::ident \
38 }
39
40#define FMT_SERIALIZE_ENUM(enum_name, ... /*enumerators*/) \
41 template <> \
42 struct fmt::formatter<enum_name> \
43 : ::asmgrader::detail::EnumFormatter< \
44 enum_name, \
45 #enum_name __VA_OPT__(, BOOST_PP_SEQ_FOR_EACH_I( \
46 FMT_SERIALIZE_ENUMERATOR_IMPL, enum_name, \
47 BOOST_PP_TUPLE_TO_SEQ(BOOST_PP_TUPLE_SIZE((__VA_ARGS__)), (__VA_ARGS__))))> \
48 { \
49 }