mimic++
v10.0.1
Toggle main menu visibility
Loading...
Searching...
No Matches
Print.hpp
Go to the documentation of this file.
1
// Copyright Dominic (DNKpp) Koepke 2024-2026.
2
// Distributed under the Boost Software License, Version 1.0.
3
// (See accompanying file LICENSE_1_0.txt or copy at
4
// https://www.boost.org/LICENSE_1_0.txt)
5
6
#ifndef MIMICPP_PRINTING_STATE_PRINT_HPP
7
#define MIMICPP_PRINTING_STATE_PRINT_HPP
8
9
#pragma once
10
11
#include "
mimic++/Fwd.hpp
"
12
#include "
mimic++/config/Config.hpp
"
13
#include "
mimic++/printing/Format.hpp
"
14
#include "
mimic++/printing/Fwd.hpp
"
15
#include "
mimic++/utilities/PriorityTag.hpp
"
16
17
#ifndef MIMICPP_DETAIL_IS_MODULE
18
#include <functional>
19
#include <iterator>
20
#include <type_traits>
21
#include <utility>
22
#endif
23
24
namespace
mimicpp::printing::detail::state
25
{
26
template
<
27
print_iterator OutIter,
28
typename
T,
29
printer_for<OutIter, T> Printer = custom::Printer<std::remove_const_t<T>>>
30
constexpr
OutIter print(
31
[[maybe_unused]] util::priority_tag<4>
const
,
32
OutIter out,
33
T& value)
34
{
35
return
Printer::print(
36
std::move(out),
37
value);
38
}
39
40
template
<
41
print_iterator OutIter,
42
typename
T,
43
printer_for<OutIter, T> Printer = state::common_type_printer<std::remove_const_t<T>>>
44
constexpr
OutIter print(
45
[[maybe_unused]] util::priority_tag<3>
const
,
46
OutIter out,
47
T& value)
48
{
49
return
Printer::print(
50
std::move(out),
51
value);
52
}
53
54
template
<
55
print_iterator OutIter,
56
typename
T,
57
printer_for<OutIter, T> Printer = state::cxx23_backport_printer<std::remove_const_t<T>>>
58
constexpr
OutIter print(
59
[[maybe_unused]] util::priority_tag<2>
const
,
60
OutIter out,
61
T& value)
62
{
63
return
Printer::print(
64
std::move(out),
65
value);
66
}
67
68
template
<pr
int
_iterator OutIter, format::formattable T>
69
constexpr
OutIter print(
70
[[maybe_unused]] util::priority_tag<1>
const
,
71
OutIter out,
72
T& value)
73
{
74
return
format::format_to
(
75
std::move(out),
76
"{}"
,
77
value);
78
}
79
80
template
<pr
int
_iterator OutIter>
81
constexpr
OutIter print(
82
[[maybe_unused]] util::priority_tag<0>
const
,
83
OutIter out,
84
auto
&)
85
{
86
return
format::format_to
(
87
std::move(out),
88
"{{?}}"
);
89
}
90
91
inline
constexpr
util::priority_tag<4> maxStatePrinterTag{};
92
}
93
94
MIMICPP_DETAIL_MODULE_EXPORT
namespace
mimicpp::printing
95
{
96
class
PrintFn
97
{
98
public
:
99
template
<pr
int
_iterator OutIter>
100
constexpr
OutIter
operator()
(OutIter out,
auto
&& value)
const
101
{
102
static_assert
(
103
requires
{
104
{
105
detail::state::print(detail::state::maxStatePrinterTag, out, value)
106
} -> std::convertible_to<OutIter>; },
107
"The given type is not printable. "
);
108
109
return
detail::state::print(
110
detail::state::maxStatePrinterTag,
111
std::move(out),
112
value);
113
}
114
115
[[nodiscard]]
116
StringT
operator()
(
auto
&& value)
const
117
{
118
StringStreamT
stream{};
119
std::invoke(*
this
, std::ostreambuf_iterator{stream}, value);
120
121
return
std::move(stream).str();
122
}
123
};
124
}
125
126
MIMICPP_DETAIL_MODULE_EXPORT
namespace
mimicpp
127
{
132
179
183
[[maybe_unused]]
inline
constexpr
printing::PrintFn
print
{};
184
188
}
189
190
#endif
Config.hpp
MIMICPP_DETAIL_MODULE_EXPORT
#define MIMICPP_DETAIL_MODULE_EXPORT
Definition
Config.hpp:19
Format.hpp
Fwd.hpp
PriorityTag.hpp
mimicpp::printing::PrintFn
Definition
Print.hpp:97
mimicpp::printing::PrintFn::operator()
constexpr OutIter operator()(OutIter out, auto &&value) const
Definition
Print.hpp:100
mimicpp::printing::PrintFn::operator()
StringT operator()(auto &&value) const
Definition
Print.hpp:116
mimicpp::print
constexpr printing::PrintFn print
Functional object, converting the given object to its textual representation.
Definition
Print.hpp:183
mimicpp::format::format_to
OutIter format_to(OutIter out, format_string< Args... > const fmt, Args &&... args)
Definition
Format.hpp:175
mimicpp::printing
Definition
Fwd.hpp:31
mimicpp
Definition
Call.hpp:24
mimicpp::StringStreamT
std::basic_ostringstream< CharT, CharTraitsT > StringStreamT
Definition
Format.hpp:38
mimicpp::StringT
std::basic_string< CharT, CharTraitsT > StringT
Definition
Fwd.hpp:397
Fwd.hpp
mimic++
printing
state
Print.hpp
Generated on
for mimic++ by
1.18.0