1#ifndef HALCHECK_GEN_FORWARD_SHRINKS_HPP
2#define HALCHECK_GEN_FORWARD_SHRINKS_HPP
4#include <halcheck/gen/shrink.hpp>
5#include <halcheck/lib/effect.hpp>
6#include <halcheck/lib/functional.hpp>
7#include <halcheck/lib/iterator.hpp>
8#include <halcheck/lib/optional.hpp>
9#include <halcheck/lib/pp.hpp>
10#include <halcheck/lib/type_traits.hpp>
11#include <halcheck/lib/utility.hpp>
22namespace halcheck {
namespace gen {
26struct forward_shrink_append {
36struct forward_shrink_handler : lib::effect::handler<forward_shrink_handler, gen::shrink_effect> {
38 :
data(new data_t{
std::move(input), 0, 0}), origin(
std::this_thread::
get_id()) {}
40 lib::optional<std::uintmax_t> operator()(gen::shrink_effect args)
final {
44 if (
data->index >=
data->input.size()) {
45 data->remaining += args.size;
49 if (
data->input[
data->index] >= args.size) {
50 data->input[
data->index] -= args.size;
70struct forward_shrinks {
72 template<
typename F,
typename... Args,
HALCHECK_REQUIRE(lib::is_invocable_r<T, F, Args...>())>
74 : forward_shrinks(detail::forward_shrink_handler(input), input,
std::move(func),
std::
forward<Args>(args)...) {}
79 using children_view = lib::transform_view<lib::iota_view<std::uintmax_t>, detail::forward_shrink_append>;
81 const children_view &children()
const {
return _children; }
84 template<
typename F,
typename... Args>
85 forward_shrinks(detail::forward_shrink_handler handler,
std::vector<uintmax_t> input, F func, Args &&...args)
86 : _value(handler.handle([&] {
return lib::make_result_holder(func,
std::forward<Args>(args)...); })),
87 _children(
lib::transform(lib::iota(handler.data->remaining), detail::forward_shrink_append{std::move(input)})) {
90 lib::result_holder<T> _value;
91 children_view _children;
95 template<
typename F,
typename... Args,
HALCHECK_REQUIRE(lib::is_invocable<F, Args...>())>
104 template<
typename F,
typename... Args,
HALCHECK_REQUIRE(lib::is_invocable<F, Args...>())>
105 gen::forward_shrinks<
lib::invoke_result_t<F, Args...>> operator()(F func, Args &&...args)
const {
111} make_forward_shrinks;
decltype(lib::invoke(std::declval< F >(), std::declval< Args >()...)) invoke_result_t
An implementation of std::invoke_result_t.
Definition invoke.hpp:42
HALCHECK_INLINE_CONSTEXPR struct halcheck::lib::@31 transform
Constructs a transform_view.
static constexpr nullopt_t nullopt
An implementation of std::nullopt.
Definition optional.hpp:41
#define HALCHECK_INLINE_CONSTEXPR
A backwards-compatible substitute for inline constexpr.
Definition pp.hpp:70
typename std::add_lvalue_reference< T >::type add_lvalue_reference_t
An implementation of std::add_lvalue_reference_t.
Definition type_traits.hpp:199
#define HALCHECK_REQUIRE(...)
Expands to a template argument that is only valid if the given argument evaluates to true.
Definition type_traits.hpp:24
lib::variant< std::integral_constant< std::size_t, Ints >... > index(lib::atom id, lib::index_sequence< Ints... >={})
Generates a random std::integral_constant from the given set of indices.
Definition variant.hpp:39