halcheck 1.0
Loading...
Searching...
No Matches
optional.hpp
1#ifndef HALCHECK_GEN_OPTIONAL_HPP
2#define HALCHECK_GEN_OPTIONAL_HPP
3
10#include <halcheck/gen/label.hpp>
11#include <halcheck/gen/sample.hpp>
12#include <halcheck/gen/shrink.hpp>
13#include <halcheck/gen/size.hpp>
14#include <halcheck/lib/atom.hpp>
15#include <halcheck/lib/functional.hpp>
16#include <halcheck/lib/optional.hpp>
17#include <halcheck/lib/pp.hpp>
18#include <halcheck/lib/type_traits.hpp>
19
20namespace halcheck { namespace gen {
21
30 template<typename F, HALCHECK_REQUIRE(lib::is_invocable<F, lib::atom>())>
31 lib::optional<lib::invoke_result_t<F, lib::atom>> operator()(lib::atom id, F gen) const {
32 using namespace lib::literals;
33
34 auto _ = gen::label(id);
35 if (gen::sample("cond"_s, gen::size()) > 0 && !gen::shrink("shrink"_s))
36 return lib::invoke(std::move(gen), "gen"_s);
37 else
38 return lib::nullopt;
39 }
41
42}} // namespace halcheck::gen
43
44#endif
static struct halcheck::gen::@9 label
Extends the unique identifiers passed to other random generation functions.
HALCHECK_INLINE_CONSTEXPR struct halcheck::gen::@11 sample
Obtains a random value.
std::uintmax_t size()
Gets the maximum size of value that should be generated.
Definition size.hpp:35
lib::variant< lib::symbol, lib::number > atom
An atom is either a symbol or a number.
Definition atom.hpp:194
HALCHECK_INLINE_CONSTEXPR struct halcheck::lib::@20 invoke
An implementation of std::invoke.
decltype(lib::invoke(std::declval< F >(), std::declval< Args >()...)) invoke_result_t
An implementation of std::invoke_result_t.
Definition invoke.hpp:42
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
HALCHECK_INLINE_CONSTEXPR struct halcheck::gen::@10 optional
Generates a lib::optional.