Hegel 0.18.3
Property-based testing for C++
Loading...
Searching...
No Matches
repr.h
1#pragma once
2
3#include "config.h"
4#include "generators/temporal_types.h"
5#include "printer.h"
6
7#include <array>
8#include <chrono>
9#include <cmath>
10#include <cstddef>
11#include <cstdint>
12#include <cstdio>
13#include <limits>
14#include <map>
15#include <optional>
16#include <set>
17#include <sstream>
18#include <string>
19#include <string_view>
20#include <tuple>
21#include <type_traits>
22#include <utility>
23#include <variant>
24#include <vector>
25
26#if HEGEL_HAS_REFLECTION
27#include <rfl.hpp>
28#endif
29
31namespace hegel::internal {
32
33 template <typename T> std::string cpp_type_name();
34 template <typename T>
35 void print_value(hegel::Printer& printer, const T& value);
36
37 // Best-effort type name sliced from the compiler's pretty function
38 // string. Used for placeholder output and for types with no clean
39 // spelling of their own.
40 template <typename T> constexpr std::string_view compiler_type_name() {
41#if defined(__clang__)
42 std::string_view p = __PRETTY_FUNCTION__;
43 auto start = p.find("T = ");
44 auto end = p.rfind(']');
45 if (start == std::string_view::npos || end == std::string_view::npos) {
46 return "?"; // GCOVR_EXCL_LINE - guards a compiler format change
47 }
48 start += 4;
49 return p.substr(start, end - start);
50#elif defined(__GNUC__)
51 std::string_view p = __PRETTY_FUNCTION__;
52 auto start = p.find("T = ");
53 if (start == std::string_view::npos) {
54 return "?";
55 }
56 start += 4;
57 auto end = p.find(';', start);
58 if (end == std::string_view::npos) {
59 end = p.rfind(']');
60 }
61 if (end == std::string_view::npos) {
62 return "?";
63 }
64 return p.substr(start, end - start);
65#elif defined(_MSC_VER)
66 std::string_view p = __FUNCSIG__;
67 constexpr std::string_view marker = "compiler_type_name<";
68 auto start = p.find(marker);
69 auto end = p.rfind(">(");
70 if (start == std::string_view::npos || end == std::string_view::npos) {
71 return "?";
72 }
73 start += marker.size();
74 return p.substr(start, end - start);
75#else
76 return "?";
77#endif
78 }
79
80 namespace repr_detail {
81
82 template <typename T> struct is_vector : std::false_type {};
83 template <typename T>
84 struct is_vector<std::vector<T>> : std::true_type {};
85
86 template <typename T> struct is_set : std::false_type {};
87 template <typename T> struct is_set<std::set<T>> : std::true_type {};
88
89 template <typename T> struct is_map : std::false_type {};
90 template <typename K, typename V>
91 struct is_map<std::map<K, V>> : std::true_type {};
92
93 template <typename T> struct is_optional : std::false_type {};
94 template <typename T>
95 struct is_optional<std::optional<T>> : std::true_type {};
96
97 template <typename T> struct is_pair : std::false_type {};
98 template <typename A, typename B>
99 struct is_pair<std::pair<A, B>> : std::true_type {};
100
101 template <typename T> struct is_tuple : std::false_type {};
102 template <typename... Ts>
103 struct is_tuple<std::tuple<Ts...>> : std::true_type {};
104
105 template <typename T> struct is_variant : std::false_type {};
106 template <typename... Ts>
107 struct is_variant<std::variant<Ts...>> : std::true_type {};
108
109 template <typename T> struct is_std_array : std::false_type {};
110 template <typename E, std::size_t N>
111 struct is_std_array<std::array<E, N>> : std::true_type {};
112
113 template <typename T> struct array_traits;
114 template <typename E, std::size_t N>
115 struct array_traits<std::array<E, N>> {
116 using element_type = E;
117 static constexpr std::size_t size = N;
118 };
119
120 // The date and time values print as their type around the engine's
121 // text in quotes, rather than field by field: the text alone, such
122 // as 2024-03-10, reads as arithmetic in a C++ expression.
123 template <typename T>
124 using is_temporal_value =
125 hegel::generators::temporal::detail::is_value<T>;
126
127 template <typename T> struct is_chrono_duration : std::false_type {};
128 template <typename Rep, typename Period>
129 struct is_chrono_duration<std::chrono::duration<Rep, Period>>
130 : std::true_type {};
131
132 template <typename T>
133 using is_system_time_point =
134 hegel::generators::temporal::detail::is_system_time_point<T>;
135
136 // A system_clock time point that converts to an Instant prints as
137 // its type around the engine's text of that instant.
138 template <typename T>
139 using is_instant_time_point =
140 hegel::generators::temporal::detail::holds_instants<T>;
141
142 template <typename T, typename = void>
143 struct prints_itself : std::false_type {};
144 template <typename T>
145 struct prints_itself<
146 T, std::void_t<decltype(std::declval<const T&>().print_to(
147 std::declval<hegel::Printer&>()))>> : std::true_type {};
148
149 template <typename T, typename = void>
150 struct has_ostream_operator : std::false_type {};
151 template <typename T>
152 struct has_ostream_operator<
153 T, std::void_t<decltype(std::declval<std::ostream&>()
154 << std::declval<const T&>())>>
155 : std::true_type {};
156
157#if HEGEL_HAS_REFLECTION
158 template <typename T, typename = void>
159 struct is_reflectable_impl : std::false_type {};
160 template <typename T>
161 struct is_reflectable_impl<
162 T, std::void_t<decltype(rfl::to_view(std::declval<T&>()))>>
163 : std::true_type {};
164
165 // The aggregate check must come first: rfl::to_view hard-errors on
166 // non-aggregates instead of failing substitution.
167 template <typename T>
168 struct is_reflectable
169 : std::conjunction<std::is_aggregate<T>, is_reflectable_impl<T>> {};
170#endif
171
172 template <typename... Ts> std::string type_name_list() {
173 if constexpr (sizeof...(Ts) == 0) {
174 return "";
175 } else {
176 std::string names[] = {cpp_type_name<Ts>()...};
177 std::string out;
178 for (std::size_t i = 0; i < sizeof...(Ts); ++i) {
179 if (i != 0) {
180 out += ", ";
181 }
182 out += names[i];
183 }
184 return out;
185 }
186 }
187
188 template <typename T> struct template_args;
189 template <typename... Ts> struct template_args<std::tuple<Ts...>> {
190 static std::string names() { return type_name_list<Ts...>(); }
191 };
192 template <typename... Ts> struct template_args<std::variant<Ts...>> {
193 static std::string names() { return type_name_list<Ts...>(); }
194 };
195
196 // Appends one byte as it must appear inside a char or string
197 // literal: named escapes, printable ASCII verbatim, all other
198 // bytes as a fixed three-digit octal escape (a following literal
199 // digit can never extend a three-digit octal escape).
200 inline void append_escaped(std::string& out, unsigned char c,
201 bool in_string) {
202 switch (c) {
203 case '\n':
204 out += "\\n";
205 return;
206 case '\t':
207 out += "\\t";
208 return;
209 case '\r':
210 out += "\\r";
211 return;
212 case '\\':
213 out += "\\\\";
214 return;
215 case '"':
216 if (in_string) {
217 out += "\\\"";
218 return;
219 }
220 break;
221 case '\'':
222 if (!in_string) {
223 out += "\\'";
224 return;
225 }
226 break;
227 default:
228 break;
229 }
230 if (c >= 0x20 && c < 0x7f) {
231 out += static_cast<char>(c);
232 return;
233 }
234 char buf[8];
235 std::snprintf(buf, sizeof(buf), "\\%03o", c);
236 out += buf;
237 }
238
239 // `text` as a string literal. The bytes of a UTF-8 character
240 // outside ASCII stay as they are.
241 inline std::string quoted(const std::string& text) {
242 std::string out = "\"";
243 for (char c : text) {
244 auto byte = static_cast<unsigned char>(c);
245 if (byte >= 0x80) {
246 out += c;
247 } else {
248 append_escaped(out, byte, /*in_string=*/true);
249 }
250 }
251 out += "\"";
252 return out;
253 }
254
255 } // namespace repr_detail
256
257 // C++ source spelling of T, for use inside rendered expressions.
258 template <typename T> std::string cpp_type_name() {
259 if constexpr (std::is_same_v<T, bool>) {
260 return "bool";
261 } else if constexpr (std::is_same_v<T, char>) {
262 return "char";
263 } else if constexpr (std::is_same_v<T, signed char>) {
264 return "signed char";
265 } else if constexpr (std::is_same_v<T, unsigned char>) {
266 return "unsigned char";
267 } else if constexpr (std::is_same_v<T, short>) {
268 return "short";
269 } else if constexpr (std::is_same_v<T, unsigned short>) {
270 return "unsigned short";
271 } else if constexpr (std::is_same_v<T, int>) {
272 return "int";
273 } else if constexpr (std::is_same_v<T, unsigned int>) {
274 return "unsigned int";
275 } else if constexpr (std::is_same_v<T, long>) {
276 return "long";
277 } else if constexpr (std::is_same_v<T, unsigned long>) {
278 return "unsigned long";
279 } else if constexpr (std::is_same_v<T, long long>) {
280 return "long long";
281 } else if constexpr (std::is_same_v<T, unsigned long long>) {
282 return "unsigned long long";
283 } else if constexpr (std::is_same_v<T, float>) {
284 return "float";
285 } else if constexpr (std::is_same_v<T, double>) {
286 return "double";
287 } else if constexpr (std::is_same_v<T, long double>) {
288 return "long double";
289 } else if constexpr (std::is_same_v<T, std::string>) {
290 return "std::string";
291 } else if constexpr (std::is_same_v<T, std::monostate>) {
292 return "std::monostate";
293 } else if constexpr (repr_detail::is_vector<T>::value) {
294 return "std::vector<" + cpp_type_name<typename T::value_type>() +
295 ">";
296 } else if constexpr (repr_detail::is_set<T>::value) {
297 return "std::set<" + cpp_type_name<typename T::value_type>() + ">";
298 } else if constexpr (repr_detail::is_map<T>::value) {
299 return "std::map<" + cpp_type_name<typename T::key_type>() + ", " +
300 cpp_type_name<typename T::mapped_type>() + ">";
301 } else if constexpr (repr_detail::is_optional<T>::value) {
302 return "std::optional<" + cpp_type_name<typename T::value_type>() +
303 ">";
304 } else if constexpr (repr_detail::is_pair<T>::value) {
305 return "std::pair<" + cpp_type_name<typename T::first_type>() +
306 ", " + cpp_type_name<typename T::second_type>() + ">";
307 } else if constexpr (repr_detail::is_tuple<T>::value) {
308 return "std::tuple<" + repr_detail::template_args<T>::names() + ">";
309 } else if constexpr (repr_detail::is_variant<T>::value) {
310 return "std::variant<" + repr_detail::template_args<T>::names() +
311 ">";
312 } else if constexpr (repr_detail::is_std_array<T>::value) {
313 using traits = repr_detail::array_traits<T>;
314 return "std::array<" +
315 cpp_type_name<typename traits::element_type>() + ", " +
316 std::to_string(traits::size) + ">";
317 } else if constexpr (std::is_same_v<T, std::chrono::nanoseconds>) {
318 return "std::chrono::nanoseconds";
319 } else if constexpr (std::is_same_v<T, std::chrono::microseconds>) {
320 return "std::chrono::microseconds";
321 } else if constexpr (std::is_same_v<T, std::chrono::milliseconds>) {
322 return "std::chrono::milliseconds";
323 } else if constexpr (std::is_same_v<T, std::chrono::seconds>) {
324 return "std::chrono::seconds";
325 } else if constexpr (std::is_same_v<T, std::chrono::minutes>) {
326 return "std::chrono::minutes";
327 } else if constexpr (std::is_same_v<T, std::chrono::hours>) {
328 return "std::chrono::hours";
329 } else if constexpr (repr_detail::is_system_time_point<T>::value) {
330 return "std::chrono::sys_time<" +
331 cpp_type_name<typename T::duration>() + ">";
332 } else if constexpr (repr_detail::is_chrono_duration<T>::value) {
333 using period = typename T::period;
334 return "std::chrono::duration<" + cpp_type_name<typename T::rep>() +
335 ", std::ratio<" + std::to_string(period::num) + ", " +
336 std::to_string(period::den) + ">>";
337 } else {
338 return std::string(compiler_type_name<T>());
339 }
340 }
341
342 namespace repr_detail {
343
344 template <typename Items>
345 void print_sequence(hegel::Printer& printer, const std::string& open,
346 const Items& items) {
347 printer.seq(open, "}", items,
348 [](hegel::Printer& p, const auto& item) {
349 print_value(p, item);
350 });
351 }
352
353 template <typename Tuple>
354 void print_tuple(hegel::Printer& printer, const std::string& open,
355 const Tuple& value) {
356 printer.begin_block(open);
357 bool first = true;
358 std::apply(
359 [&](const auto&... elems) {
360 ((first ? void(first = false) : printer.separator(),
361 print_value(printer, elems)),
362 ...);
363 },
364 value);
365 printer.end_block("}");
366 }
367
368 // Decimal digits of an integer of any width.
369 template <typename T> std::string integer_digits(T value) {
370 using U = std::make_unsigned_t<T>;
371 auto magnitude = static_cast<U>(value);
372 bool negative = false;
373 if constexpr (std::is_signed_v<T>) {
374 negative = value < 0;
375 if (negative) {
376 magnitude = static_cast<U>(U{0} - magnitude);
377 }
378 }
379 std::string reversed;
380 do {
381 reversed.push_back(static_cast<char>('0' + magnitude % 10));
382 magnitude /= 10;
383 } while (magnitude != 0);
384 if (negative) {
385 reversed.push_back('-');
386 }
387 return std::string(reversed.rbegin(), reversed.rend());
388 }
389
390 // The text of a value with no inner structure.
391 template <typename T> std::string scalar_text(const T& value) {
392 if constexpr (std::is_same_v<T, bool>) {
393 return value ? "true" : "false";
394 } else if constexpr (std::is_same_v<T, char>) {
395 std::string out = "'";
396 append_escaped(out, static_cast<unsigned char>(value),
397 /*in_string=*/false);
398 out += "'";
399 return out;
400 } else if constexpr (std::is_same_v<T, signed char> ||
401 std::is_same_v<T, unsigned char>) {
402 return "static_cast<" + cpp_type_name<T>() + ">(" +
403 std::to_string(static_cast<int>(value)) + ")";
404 } else if constexpr (std::is_same_v<T, int>) {
405 return std::to_string(value);
406 } else if constexpr (std::is_same_v<T, unsigned int>) {
407 return std::to_string(value) + "u";
408 } else if constexpr (std::is_same_v<T, long>) {
409 return std::to_string(value) + "l";
410 } else if constexpr (std::is_same_v<T, unsigned long>) {
411 return std::to_string(value) + "ul";
412 } else if constexpr (std::is_same_v<T, long long>) {
413 return std::to_string(value) + "ll";
414 } else if constexpr (std::is_same_v<T, unsigned long long>) {
415 return std::to_string(value) + "ull";
416 } else if constexpr (std::is_integral_v<T>) {
417 // Integral types with no literal suffix of their own.
418 return "static_cast<" + cpp_type_name<T>() + ">(" +
419 integer_digits(value) + ")";
420 } else if constexpr (std::is_enum_v<T>) {
421 using underlying = std::underlying_type_t<T>;
422 return "static_cast<" + cpp_type_name<T>() + ">(" +
423 scalar_text(static_cast<underlying>(value)) + ")";
424 } else if constexpr (std::is_floating_point_v<T>) {
425 if (std::isnan(value)) {
426 return "std::numeric_limits<" + cpp_type_name<T>() +
427 ">::quiet_NaN()";
428 }
429 if (std::isinf(value)) {
430 std::string inf = "std::numeric_limits<" +
431 cpp_type_name<T>() + ">::infinity()";
432 return value < 0 ? "-" + inf : inf;
433 }
434 char buf[64];
435 constexpr int digits = std::numeric_limits<T>::max_digits10;
436 if constexpr (std::is_same_v<T, long double>) {
437 std::snprintf(buf, sizeof(buf), "%.*Lg", digits, value);
438 } else {
439 std::snprintf(buf, sizeof(buf), "%.*g", digits,
440 static_cast<double>(value));
441 }
442 std::string out = buf;
443 // keep integral-valued float rendering as float since %g
444 // drops decimal when it isn't needed.
445 if (out.find('.') == std::string::npos &&
446 out.find('e') == std::string::npos &&
447 out.find('E') == std::string::npos) {
448 out += ".0";
449 }
450 if constexpr (std::is_same_v<T, float>) {
451 out += "f";
452 } else if constexpr (std::is_same_v<T, long double>) {
453 out += "L";
454 }
455 return out;
456 } else if constexpr (std::is_same_v<T, std::string>) {
457 bool has_nul = value.find('\0') != std::string::npos;
458 std::string out = "std::string(\"";
459 for (char c : value) {
460 append_escaped(out, static_cast<unsigned char>(c),
461 /*in_string=*/true);
462 }
463 out += "\"";
464 if (has_nul) {
465 // The pointer constructor would stop at the first NUL.
466 out += ", " + std::to_string(value.size());
467 }
468 out += ")";
469 return out;
470 } else {
471 static_assert(std::is_same_v<T, std::monostate>);
472 return "std::monostate{}";
473 }
474 }
475
476 template <typename T>
477 inline constexpr bool is_scalar_v =
478 std::is_arithmetic_v<T> || std::is_enum_v<T> ||
479 std::is_same_v<T, std::string> || std::is_same_v<T, std::monostate>;
480
481 } // namespace repr_detail
482
483 // Prints a value as one C++ expression, or as a pseudo-expression for
484 // types with no renderable form. A compound value gives the printer its
485 // structure, so the engine can lay it out across lines.
486 template <typename T>
487 void print_value(hegel::Printer& printer, const T& value) {
488 if constexpr (repr_detail::is_scalar_v<T>) {
489 printer.text(repr_detail::scalar_text(value));
490 } else if constexpr (repr_detail::prints_itself<T>::value) {
491 value.print_to(printer);
492 } else if constexpr (repr_detail::is_pair<T>::value ||
493 repr_detail::is_tuple<T>::value) {
494 repr_detail::print_tuple(printer, cpp_type_name<T>() + "{", value);
495 } else if constexpr (repr_detail::is_optional<T>::value) {
496 std::string name = cpp_type_name<T>();
497 if (!value.has_value()) {
498 printer.text(name + "{}");
499 return;
500 }
501 printer.begin_block(name + "{");
502 print_value(printer, *value);
503 printer.end_block("}");
504 } else if constexpr (repr_detail::is_variant<T>::value) {
505 // in_place_index keeps variants with repeated alternative types
506 // unambiguous.
507 printer.begin_block(cpp_type_name<T>() + "{");
508 printer.text("std::in_place_index<" +
509 std::to_string(value.index()) + ">");
510 printer.separator();
511 std::visit([&printer](const auto& v) { print_value(printer, v); },
512 value);
513 printer.end_block("}");
514 } else if constexpr (repr_detail::is_vector<T>::value ||
515 repr_detail::is_set<T>::value ||
516 repr_detail::is_std_array<T>::value) {
517 repr_detail::print_sequence(printer, cpp_type_name<T>() + "{",
518 value);
519 } else if constexpr (repr_detail::is_map<T>::value) {
520 printer.seq(cpp_type_name<T>() + "{", "}", value,
521 [](hegel::Printer& p, const auto& entry) {
522 p.begin_block("{");
523 print_value(p, entry.first);
524 p.separator();
525 print_value(p, entry.second);
526 p.end_block("}");
527 });
528 } else if constexpr (repr_detail::is_temporal_value<T>::value) {
529 printer.text(cpp_type_name<T>() + "{" +
530 repr_detail::quoted(to_string(value)) + "}");
531 } else if constexpr (repr_detail::is_chrono_duration<T>::value) {
532 printer.text(cpp_type_name<T>() + "{");
533 print_value(printer, value.count());
534 printer.text("}");
535 } else if constexpr (repr_detail::is_instant_time_point<T>::value) {
536 std::optional<hegel::generators::temporal::Instant> instant =
537 hegel::generators::temporal::Instant::from_chrono(value);
538 if (instant.has_value()) {
539 printer.text(cpp_type_name<T>() + "{" +
540 repr_detail::quoted(to_string(*instant)) + "}");
541 return;
542 }
543 printer.text(cpp_type_name<T>() + "{");
544 print_value(printer, value.time_since_epoch());
545 printer.text("}");
546 }
547#if HEGEL_HAS_REFLECTION
548 else if constexpr (repr_detail::is_reflectable<T>::value) {
549 printer.begin_block(cpp_type_name<T>() + "{");
550 bool first = true;
551 auto view = rfl::to_view(const_cast<T&>(value));
552 view.apply([&printer, &first](const auto& field) {
553 if (!first) {
554 printer.separator();
555 }
556 first = false;
557 printer.text("." + std::string(field.name()) + " = ");
558 print_value(printer, *field.value());
559 });
560 printer.end_block("}");
561 }
562#endif
563 else if constexpr (repr_detail::has_ostream_operator<T>::value) {
564 std::ostringstream os;
565 os << value;
566 printer.reflow(os.str());
567 } else {
568 printer.text("<unprintable " +
569 std::string(compiler_type_name<T>()) + ">");
570 }
571 }
572
573 // Renders a value as one C++ expression laid out within `width`
574 // columns.
575 template <typename T>
576 std::string render(const T& value, std::size_t width) {
577 hegel::Document document(width);
578 print_value(document.printer(), value);
579 return std::move(document).finish();
580 }
581
582 // Renders a value as one C++ expression on a single line.
583 template <typename T> std::string repr(const T& value) {
584 return render(value, unbounded_width);
585 }
586
587 namespace repr_detail {
588
589 template <typename T, typename = void>
590 struct is_representable : std::false_type {};
591
592 template <typename T>
593 struct is_representable<
594 T, std::enable_if_t<is_scalar_v<T> || prints_itself<T>::value>>
595 : std::true_type {};
596
597 template <typename A, typename B>
598 struct is_representable<
599 std::pair<A, B>,
600 std::enable_if_t<!prints_itself<std::pair<A, B>>::value>>
601 : std::conjunction<is_representable<A>, is_representable<B>> {};
602
603 template <typename... Ts>
604 struct is_representable<
605 std::tuple<Ts...>,
606 std::enable_if_t<!prints_itself<std::tuple<Ts...>>::value>>
607 : std::conjunction<is_representable<Ts>...> {};
608
609 template <typename... Ts>
610 struct is_representable<
611 std::variant<Ts...>,
612 std::enable_if_t<!prints_itself<std::variant<Ts...>>::value>>
613 : std::conjunction<is_representable<Ts>...> {};
614
615 template <typename T>
616 struct is_representable<
617 std::optional<T>,
618 std::enable_if_t<!prints_itself<std::optional<T>>::value>>
619 : is_representable<T> {};
620
621 template <typename T>
622 struct is_representable<
623 std::vector<T>,
624 std::enable_if_t<!prints_itself<std::vector<T>>::value>>
625 : is_representable<T> {};
626
627 template <typename T>
628 struct is_representable<
629 std::set<T>, std::enable_if_t<!prints_itself<std::set<T>>::value>>
630 : is_representable<T> {};
631
632 template <typename T, std::size_t N>
633 struct is_representable<
634 std::array<T, N>,
635 std::enable_if_t<!prints_itself<std::array<T, N>>::value>>
636 : is_representable<T> {};
637
638 template <typename K, typename V>
639 struct is_representable<
640 std::map<K, V>,
641 std::enable_if_t<!prints_itself<std::map<K, V>>::value>>
642 : std::conjunction<is_representable<K>, is_representable<V>> {};
643
644 template <typename Rep, typename Period>
645 struct is_representable<std::chrono::duration<Rep, Period>,
646 std::enable_if_t<!prints_itself<
647 std::chrono::duration<Rep, Period>>::value>>
648 : is_representable<Rep> {};
649
650 template <typename T>
651 struct is_representable<
652 T, std::enable_if_t<is_instant_time_point<T>::value &&
653 !prints_itself<T>::value>> : std::true_type {};
654
655 template <typename T>
656 inline constexpr bool is_std_compound_v =
657 is_pair<T>::value || is_tuple<T>::value || is_variant<T>::value ||
658 is_optional<T>::value || is_vector<T>::value || is_set<T>::value ||
659 is_std_array<T>::value || is_map<T>::value;
660
661 template <typename T>
662 struct is_representable<
663 T, std::enable_if_t<!is_scalar_v<T> && !prints_itself<T>::value &&
664 !is_std_compound_v<T> &&
665 !is_chrono_duration<T>::value &&
666 !is_instant_time_point<T>::value &&
667 (has_ostream_operator<T>::value
668#if HEGEL_HAS_REFLECTION
669 || is_reflectable<T>::value
670#endif
671 )>> : std::true_type {
672 };
673
674 } // namespace repr_detail
675
676} // namespace hegel::internal
677
679
680namespace hegel {
681
700 template <typename T>
701 inline constexpr bool is_representable_v =
702 internal::repr_detail::is_representable<T>::value;
703
704#if defined(__cpp_concepts) && __cpp_concepts >= 201907L
709 template <typename T>
710 concept Representable = is_representable_v<T>;
711#endif
712
713 template <typename T> void Printer::repr(const T& value) {
714 if (should_print()) {
715 internal::print_value(*this, value);
716 }
717 }
718
719} // namespace hegel
Generator< std::variant< Ts... > > variant(Generator< Ts >... gens)
Generate std::variant from heterogeneous generators.
Definition combinators.h:306
Generator< std::optional< T > > optional(Generator< T > gen)
Generate optional values (present or absent).
Definition combinators.h:341