halcheck 1.0
Loading...
Searching...
No Matches
dag.hpp
1#ifndef HALCHECK_GEN_DAG_HPP
2#define HALCHECK_GEN_DAG_HPP
3
9#include <halcheck/gen/container.hpp>
10#include <halcheck/gen/label.hpp>
11#include <halcheck/lib/atom.hpp>
12#include <halcheck/lib/dag.hpp>
13#include <halcheck/lib/functional.hpp>
14#include <halcheck/lib/iterator.hpp>
15#include <halcheck/lib/type_traits.hpp>
16
17#include <unordered_map>
18#include <vector>
19
20namespace halcheck { namespace gen {
21
37template<
38 typename F,
39 HALCHECK_REQUIRE(lib::is_invocable<F, lib::atom>()),
47 using namespace lib::literals;
48
51
52 using dag = lib::dag<result>;
54
55 auto _ = gen::label(id);
56
57 map state;
58 dag output;
59
60 for (auto _ : gen::repeat("labels"_s)) {
61 auto pair = lib::invoke(func, "func"_s);
62
64 for (auto &&key : std::get<0>(pair)) {
65 auto it = state.find(key);
66 if (it != state.end())
67 parents.push_back(it->second);
68 }
69
70 auto it = output.emplace(std::move(parents), std::move(std::get<1>(pair)));
71 for (auto &&key : std::get<0>(pair))
72 state[key] = it;
73 }
74
75 return output;
76}
77
78}} // namespace halcheck::gen
79
80#endif
Directed acyclic graphs with labelled nodes.
Definition dag.hpp:33
T emplace(T... args)
lib::dag< lib::tuple_element_t< 1, lib::invoke_result_t< F, lib::atom > > > schedule(lib::atom id, F func)
Generates a random lib::dag.
Definition dag.hpp:46
static struct halcheck::gen::@9 label
Extends the unique identifiers passed to other random generation functions.
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
lib::iter_value_t< lib::iterator_t< R > > range_value_t
The type of element contained in a range.
Definition range.hpp:332
typename std::tuple_element< I, T >::type tuple_element_t
Provides compile-time access the the types of the elements of a tuple.
Definition type_traits.hpp:167
#define HALCHECK_REQUIRE(...)
Expands to a template argument that is only valid if the given argument evaluates to true.
Definition type_traits.hpp:24
T push_back(T... args)