rename chapters
This commit is contained in:
72
Chapter17/cib/libs/flow/detail/par.hpp
Normal file
72
Chapter17/cib/libs/flow/detail/par.hpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
|
||||
#include <flow/detail/walk.hpp>
|
||||
#include <flow/subgraph_identity.hpp>
|
||||
|
||||
#include <stdx/tuple_algorithms.hpp>
|
||||
|
||||
namespace flow::dsl {
|
||||
template <subgraph Lhs, subgraph Rhs,
|
||||
subgraph_identity Identity = subgraph_identity::REFERENCE>
|
||||
struct par {
|
||||
Lhs lhs;
|
||||
Rhs rhs;
|
||||
|
||||
using is_subgraph = void;
|
||||
|
||||
constexpr auto operator*() const {
|
||||
return par<Lhs, Rhs, subgraph_identity::VALUE>{Lhs{}, Rhs{}};
|
||||
}
|
||||
|
||||
private:
|
||||
friend constexpr auto tag_invoke(get_initials_t, par const &p) {
|
||||
return stdx::tuple_cat(get_initials(p.lhs), get_initials(p.rhs));
|
||||
}
|
||||
|
||||
friend constexpr auto tag_invoke(get_finals_t, par const &p) {
|
||||
return stdx::tuple_cat(get_finals(p.lhs), get_finals(p.rhs));
|
||||
}
|
||||
|
||||
friend constexpr auto tag_invoke(get_nodes_t, par const &p) {
|
||||
if constexpr (Identity == subgraph_identity::VALUE) {
|
||||
auto all_nodes = stdx::to_unsorted_set(
|
||||
stdx::tuple_cat(get_all_mentioned_nodes(p.lhs),
|
||||
get_all_mentioned_nodes(p.rhs)));
|
||||
|
||||
return stdx::transform([](auto const &n) { return *n; }, all_nodes);
|
||||
|
||||
} else {
|
||||
return stdx::tuple_cat(get_nodes(p.lhs), get_nodes(p.rhs));
|
||||
}
|
||||
}
|
||||
|
||||
friend constexpr auto tag_invoke(get_all_mentioned_nodes_t, par const &p) {
|
||||
return stdx::tuple_cat(get_all_mentioned_nodes(p.lhs),
|
||||
get_all_mentioned_nodes(p.rhs));
|
||||
}
|
||||
|
||||
friend constexpr auto tag_invoke(get_edges_t, par const &p) {
|
||||
return stdx::tuple_cat(get_edges(p.lhs), get_edges(p.rhs));
|
||||
}
|
||||
};
|
||||
|
||||
template <subgraph Lhs, subgraph Rhs> par(Lhs, Rhs) -> par<Lhs, Rhs>;
|
||||
} // namespace flow::dsl
|
||||
|
||||
template <flow::dsl::subgraph Lhs, flow::dsl::subgraph Rhs>
|
||||
[[nodiscard]] constexpr auto operator&&(Lhs const &lhs, Rhs const &rhs) {
|
||||
return flow::dsl::par{lhs, rhs};
|
||||
}
|
||||
|
||||
template <typename Cond, flow::dsl::subgraph Lhs, flow::dsl::subgraph Rhs,
|
||||
flow::subgraph_identity Identity>
|
||||
constexpr auto make_runtime_conditional(Cond,
|
||||
flow::dsl::par<Lhs, Rhs, Identity>) {
|
||||
auto lhs = make_runtime_conditional(Cond{}, Lhs{});
|
||||
auto rhs = make_runtime_conditional(Cond{}, Rhs{});
|
||||
|
||||
using lhs_t = decltype(lhs);
|
||||
using rhs_t = decltype(rhs);
|
||||
|
||||
return flow::dsl::par<lhs_t, rhs_t, Identity>{lhs, rhs};
|
||||
}
|
||||
86
Chapter17/cib/libs/flow/detail/seq.hpp
Normal file
86
Chapter17/cib/libs/flow/detail/seq.hpp
Normal file
@@ -0,0 +1,86 @@
|
||||
#pragma once
|
||||
|
||||
#include <cib/detail/runtime_conditional.hpp>
|
||||
#include <flow/detail/walk.hpp>
|
||||
#include <flow/subgraph_identity.hpp>
|
||||
|
||||
#include <stdx/tuple_algorithms.hpp>
|
||||
|
||||
namespace flow::dsl {
|
||||
template <subgraph Lhs, subgraph Rhs,
|
||||
subgraph_identity Identity = subgraph_identity::REFERENCE,
|
||||
typename Cond = cib::detail::always_condition_t>
|
||||
struct seq {
|
||||
Lhs lhs;
|
||||
Rhs rhs;
|
||||
|
||||
using is_subgraph = void;
|
||||
|
||||
constexpr auto operator*() const {
|
||||
return seq<Lhs, Rhs, subgraph_identity::VALUE, Cond>{Lhs{}, Rhs{}};
|
||||
}
|
||||
|
||||
private:
|
||||
friend constexpr auto tag_invoke(get_initials_t, seq const &s) {
|
||||
return get_initials(s.lhs);
|
||||
}
|
||||
|
||||
friend constexpr auto tag_invoke(get_finals_t, seq const &s) {
|
||||
return get_finals(s.rhs);
|
||||
}
|
||||
|
||||
friend constexpr auto tag_invoke(get_nodes_t, seq const &s) {
|
||||
if constexpr (Identity == subgraph_identity::VALUE) {
|
||||
auto all_nodes = stdx::to_unsorted_set(
|
||||
stdx::tuple_cat(get_all_mentioned_nodes(s.lhs),
|
||||
get_all_mentioned_nodes(s.rhs)));
|
||||
|
||||
return stdx::transform([](auto const &n) { return *n; }, all_nodes);
|
||||
|
||||
} else {
|
||||
return stdx::tuple_cat(get_nodes(s.lhs), get_nodes(s.rhs));
|
||||
}
|
||||
}
|
||||
|
||||
friend constexpr auto tag_invoke(get_all_mentioned_nodes_t, seq const &s) {
|
||||
return stdx::tuple_cat(get_all_mentioned_nodes(s.lhs),
|
||||
get_all_mentioned_nodes(s.rhs));
|
||||
}
|
||||
|
||||
friend constexpr auto tag_invoke(get_edges_t, seq const &s) {
|
||||
auto is = get_initials(s.rhs);
|
||||
auto fs = get_finals(s.lhs);
|
||||
|
||||
return stdx::tuple_cat(
|
||||
get_edges(s.lhs), get_edges(s.rhs),
|
||||
transform(
|
||||
[]<typename P>(P const &) {
|
||||
return edge<stdx::tuple_element_t<0, P>,
|
||||
stdx::tuple_element_t<1, P>, Cond>{};
|
||||
},
|
||||
cartesian_product_copy(fs, is)));
|
||||
}
|
||||
};
|
||||
|
||||
template <subgraph Lhs, subgraph Rhs> seq(Lhs, Rhs) -> seq<Lhs, Rhs>;
|
||||
|
||||
} // namespace flow::dsl
|
||||
|
||||
template <flow::dsl::subgraph Lhs, flow::dsl::subgraph Rhs>
|
||||
[[nodiscard]] constexpr auto operator>>(Lhs const &lhs, Rhs const &rhs) {
|
||||
return flow::dsl::seq{lhs, rhs};
|
||||
}
|
||||
|
||||
template <typename Cond, flow::dsl::subgraph Lhs, flow::dsl::subgraph Rhs,
|
||||
flow::subgraph_identity Identity, typename EdgeCond>
|
||||
constexpr auto
|
||||
make_runtime_conditional(Cond, flow::dsl::seq<Lhs, Rhs, Identity, EdgeCond>) {
|
||||
auto lhs = make_runtime_conditional(Cond{}, Lhs{});
|
||||
auto rhs = make_runtime_conditional(Cond{}, Rhs{});
|
||||
|
||||
using lhs_t = decltype(lhs);
|
||||
using rhs_t = decltype(rhs);
|
||||
using cond_t = decltype(EdgeCond{} and Cond{});
|
||||
|
||||
return flow::dsl::seq<lhs_t, rhs_t, Identity, cond_t>{lhs, rhs};
|
||||
}
|
||||
103
Chapter17/cib/libs/flow/detail/walk.hpp
Normal file
103
Chapter17/cib/libs/flow/detail/walk.hpp
Normal file
@@ -0,0 +1,103 @@
|
||||
#pragma once
|
||||
|
||||
#include <flow/subgraph_identity.hpp>
|
||||
|
||||
#include <stdx/concepts.hpp>
|
||||
#include <stdx/tuple.hpp>
|
||||
#include <stdx/type_traits.hpp>
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace flow::dsl {
|
||||
template <typename T>
|
||||
concept subgraph = requires { typename stdx::remove_cvref_t<T>::is_subgraph; };
|
||||
|
||||
template <typename Source, typename Dest, typename Cond> struct edge {
|
||||
using source_t = Source;
|
||||
using dest_t = Dest;
|
||||
using cond_t = Cond;
|
||||
};
|
||||
|
||||
constexpr inline class get_initials_t {
|
||||
template <subgraph N>
|
||||
friend constexpr auto tag_invoke(get_initials_t, N &&n) {
|
||||
return stdx::make_tuple(std::forward<N>(n));
|
||||
}
|
||||
|
||||
public:
|
||||
template <typename... Ts>
|
||||
constexpr auto operator()(Ts &&...ts) const
|
||||
noexcept(noexcept(tag_invoke(std::declval<get_initials_t>(),
|
||||
std::forward<Ts>(ts)...)))
|
||||
-> decltype(tag_invoke(*this, std::forward<Ts>(ts)...)) {
|
||||
return tag_invoke(*this, std::forward<Ts>(ts)...);
|
||||
}
|
||||
} get_initials{};
|
||||
|
||||
constexpr inline class get_finals_t {
|
||||
template <subgraph N>
|
||||
friend constexpr auto tag_invoke(get_finals_t, N &&n) {
|
||||
return stdx::make_tuple(std::forward<N>(n));
|
||||
}
|
||||
|
||||
public:
|
||||
template <typename... Ts>
|
||||
constexpr auto operator()(Ts &&...ts) const
|
||||
noexcept(noexcept(tag_invoke(std::declval<get_finals_t>(),
|
||||
std::forward<Ts>(ts)...)))
|
||||
-> decltype(tag_invoke(*this, std::forward<Ts>(ts)...)) {
|
||||
return tag_invoke(*this, std::forward<Ts>(ts)...);
|
||||
}
|
||||
} get_finals{};
|
||||
|
||||
constexpr inline class get_nodes_t {
|
||||
template <subgraph N> friend constexpr auto tag_invoke(get_nodes_t, N &&n) {
|
||||
if constexpr (std::remove_cvref_t<N>::identity ==
|
||||
subgraph_identity::REFERENCE) {
|
||||
return stdx::tuple{};
|
||||
} else {
|
||||
return stdx::make_tuple(std::forward<N>(n));
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
template <typename... Ts>
|
||||
constexpr auto operator()(Ts &&...ts) const
|
||||
noexcept(noexcept(tag_invoke(std::declval<get_nodes_t>(),
|
||||
std::forward<Ts>(ts)...)))
|
||||
-> decltype(tag_invoke(*this, std::forward<Ts>(ts)...)) {
|
||||
return tag_invoke(*this, std::forward<Ts>(ts)...);
|
||||
}
|
||||
} get_nodes{};
|
||||
|
||||
constexpr inline class get_all_mentioned_nodes_t {
|
||||
template <subgraph N>
|
||||
friend constexpr auto tag_invoke(get_all_mentioned_nodes_t, N &&n) {
|
||||
return stdx::make_tuple(std::forward<N>(n));
|
||||
}
|
||||
|
||||
public:
|
||||
template <typename... Ts>
|
||||
constexpr auto operator()(Ts &&...ts) const
|
||||
noexcept(noexcept(tag_invoke(std::declval<get_all_mentioned_nodes_t>(),
|
||||
std::forward<Ts>(ts)...)))
|
||||
-> decltype(tag_invoke(*this, std::forward<Ts>(ts)...)) {
|
||||
return tag_invoke(*this, std::forward<Ts>(ts)...);
|
||||
}
|
||||
} get_all_mentioned_nodes{};
|
||||
|
||||
constexpr inline class get_edges_t {
|
||||
friend constexpr auto tag_invoke(get_edges_t, subgraph auto const &) {
|
||||
return stdx::tuple{};
|
||||
}
|
||||
|
||||
public:
|
||||
template <typename... Ts>
|
||||
constexpr auto operator()(Ts &&...ts) const
|
||||
noexcept(noexcept(tag_invoke(std::declval<get_edges_t>(),
|
||||
std::forward<Ts>(ts)...)))
|
||||
-> decltype(tag_invoke(*this, std::forward<Ts>(ts)...)) {
|
||||
return tag_invoke(*this, std::forward<Ts>(ts)...);
|
||||
}
|
||||
} get_edges{};
|
||||
} // namespace flow::dsl
|
||||
Reference in New Issue
Block a user