halcheck 1.0
Loading...
Searching...
No Matches
size.hpp
1#ifndef HALCHECK_GEN_SIZE_HPP
2#define HALCHECK_GEN_SIZE_HPP
3
10#include <halcheck/lib/effect.hpp>
11#include <halcheck/lib/functional.hpp>
12#include <halcheck/lib/pp.hpp>
13
14#include <cstdint>
15
16namespace halcheck { namespace gen {
17
27 std::uintmax_t fallback() const { return 0; }
28};
29
36
58private:
59 struct handler : lib::effect::handler<handler, gen::size_effect> {
60 explicit handler(double amount) : amount(amount) {}
61 std::uintmax_t operator()(size_effect) final { return std::uintmax_t(double(gen::size()) * amount); }
62 double amount;
63 };
64
65public:
66 handler::owning_scope operator()(double amount) const { return handler(amount).handle(); }
67
68 template<typename F, typename... Args>
69 lib::invoke_result_t<F, Args...> operator()(double amount, F func, Args &&...args) const {
70 return handler(amount).handle(std::move(func), std::forward<Args>(args)...);
71 }
73
74}} // namespace halcheck::gen
75
76#endif
An effect handler defines the behaviour of a set of effects.
Definition effect.hpp:158
static lib::effect_result_t< T > invoke(T args)
Invokes an effect.
Definition effect.hpp:118
T forward(T... args)
HALCHECK_INLINE_CONSTEXPR struct halcheck::gen::@17 scale
Applies a multiplier to the result of gen::size.
std::uintmax_t size()
Gets the maximum size of value that should be generated.
Definition size.hpp:35
decltype(lib::invoke(std::declval< F >(), std::declval< Args >()...)) invoke_result_t
An implementation of std::invoke_result_t.
Definition invoke.hpp:42
#define HALCHECK_INLINE_CONSTEXPR
A backwards-compatible substitute for inline constexpr.
Definition pp.hpp:70
std::uintmax_t fallback() const
The default size is zero.
Definition size.hpp:27
An effect for obtaining a size parameter.
Definition size.hpp:22