10 template <
typename T,
bool Printable,
typename... Gens>
11 class BuildsGenerator :
public detail::Structural<T, Printable> {
13 explicit BuildsGenerator(Gens... gens)
14 : gens_(std::move(gens)...),
15 label_(internal::label(internal::LabelName::Composite)) {}
17 uint64_t label()
const override {
return label_; }
20 T draw_printing(
const TestCase& tc, Printer& printer)
const override {
22 if (printer.should_print()) {
23 open = internal::cpp_type_name<T>() +
"(";
25 printer.begin_group(open.size(), open);
26 Arguments arguments = std::apply(
27 [&](
const auto&... gens) {
28 std::size_t index = 0;
30 draw_argument(tc, printer, gens, index++)...};
33 printer.end_group(
")");
34 return std::make_from_tuple<T>(std::move(arguments));
38 using Arguments = std::tuple<
typename Gens::value_type...>;
41 static typename G::value_type
42 draw_argument(
const TestCase& tc, Printer& printer,
const G& gen,
47 return detail::draw_component(tc, gen, printer);
50 std::tuple<Gens...> gens_;
83 template <
typename T,
typename... Gens>
auto builds(Gens... gens) {
84 constexpr bool printable = (detail::is_printable_handle_v<Gens> && ...);
85 return detail::handle_t<printable, T>(
86 std::make_shared<BuildsGenerator<T, printable, Gens...>>(
96 template <auto MemberPtr,
typename Gen>
struct Field {
118 template <auto MemberPtr,
typename Gen>
150 template <
typename T,
typename... Fields>
152 auto gen_tuple = std::make_tuple(std::move(fields)...);
157 [&result, &tc](
auto&... fs) {
159 (std::remove_reference_t<
decltype(fs)>::member_ptr) =
Handle to the currently-executing test case.
Definition test_case.h:46
T draw_silent(const generators::AnyGenerator< T > &gen) const
Draw a random value from any generator, without printing it.
Definition core.h:1053
Hegel generators.
Definition core.h:25
Field< MemberPtr, Gen > field(Gen gen)
Create a field specification for builds_agg().
Definition builds.h:119
auto compose(F &&fn)
Build a generator from imperative code that draws from a TestCase.
Definition core.h:979
auto builds(Gens... gens)
Construct objects using positional constructor arguments.
Definition builds.h:83
auto builds_agg(Fields... fields)
Construct aggregates using named field initialization.
Definition builds.h:151
Helper for named field initialization in builds_agg().
Definition builds.h:96
static constexpr auto member_ptr
The member pointer.
Definition builds.h:97
Gen generator
Generator for the field value.
Definition builds.h:98