forked from cubicdaiya/dtl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathses_display_simple.hpp
71 lines (61 loc) · 1.83 KB
/
ses_display_simple.hpp
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
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef DTL_MODERN_EXTRA_SES_DISPLAY_SIMPLE_HPP
#define DTL_MODERN_EXTRA_SES_DISPLAY_SIMPLE_HPP
#include "dtl_modern/ses.hpp"
namespace dtl_modern::extra
{
/**
* @struct SesDisplaySimple
*
* @brief Wrapper type for displaying SES in a simple format.
*/
template <Diffable E>
struct SesDisplaySimple
{
const Ses<E>& m_ses;
// only checks whether it points to the same ses
bool operator==(const SesDisplaySimple& other) const { return &m_ses == &other.m_ses; }
};
/**
* @brief Create a wrapper for displaying SES in a simple format.
*
* @param ses The SES to display.
* @return The wrapper for displaying SES in a simple format.
*/
template <Diffable E>
SesDisplaySimple<E> display(const Ses<E>& ses)
{
return { ses };
}
}
#ifdef DTL_MODERN_DISPLAY_FMTLIB
# define DTL_MODERN_FMT fmt
# include <fmt/core.h>
#else
# define DTL_MODERN_FMT std
# include <format>
#endif
template <dtl_modern::Diffable E>
struct DTL_MODERN_FMT::formatter<dtl_modern::extra::SesDisplaySimple<E>>
: public DTL_MODERN_FMT::formatter<std::string_view>
{
auto format(const dtl_modern::extra::SesDisplaySimple<E>& ses_display, auto& fmt) const
{
for (const dtl_modern::SesElem<E>& ses_elem : ses_display.m_ses.get()) {
const auto& [elem, info] = ses_elem;
DTL_MODERN_FMT::format_to(fmt.out(), "{}{}\n", dtl_modern::ses_mark(info.m_type), elem);
}
return fmt.out();
}
};
#include <ostream>
namespace dtl_modern::extra
{
template <Diffable E>
std::ostream& operator<<(std::ostream& os, const SesDisplaySimple<E>& ses)
{
os << DTL_MODERN_FMT::format("{}", ses);
return os;
}
}
#undef DTL_MODERN_FMT
#endif /* end of include guard: DTL_MODERN_EXTRA_SES_DISPLAY_SIMPLE_HPP */