Vcsn  2.1
Be Rational
union.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <unordered_map>
4 
5 #include <vcsn/algos/copy.hh>
8 #include <vcsn/dyn/automaton.hh> // dyn::make_automaton
9 
10 namespace vcsn
11 {
12  /*----------.
13  | union_a. |
14  `----------*/
15 
19  template <typename A, typename B>
20  inline
21  A&
22  union_here(A& res, const B& b)
23  {
24  ::vcsn::copy_into(b, res);
25  return res;
26  }
27 
29  template <typename A, typename B>
30  inline
31  auto
32  union_a(const A& lhs, const B& rhs)
33  -> decltype(join_automata(lhs, rhs))
34  {
35  auto res = join_automata(lhs, rhs);
36  union_here(res, lhs);
37  union_here(res, rhs);
38  return res;
39  }
40 
41  namespace dyn
42  {
43  namespace detail
44  {
46  template <typename Lhs, typename Rhs>
47  inline
48  automaton
49  union_a(const automaton& lhs, const automaton& rhs)
50  {
51  const auto& l = lhs->as<Lhs>();
52  const auto& r = rhs->as<Rhs>();
53  return make_automaton(::vcsn::union_a(l, r));
54  }
55  }
56  }
57 }
automaton union_a(const automaton &lhs, const automaton &rhs)
Bridge.
Definition: union.hh:49
automaton make_automaton(const Aut &aut)
Build a dyn::automaton.
Definition: automaton.hh:75
Provide a variadic mul on top of a binary mul(), and one().
Definition: fwd.hh:46
std::shared_ptr< detail::automaton_base > automaton
Definition: automaton.hh:69
void copy_into(const AutIn &in, AutOut &out, KeepState keep_state, KeepTrans keep_trans)
Copy selected states and transitions of an automaton.
Definition: copy.hh:126
A & union_here(A &res, const B &b)
Merge transitions of b into those of res.
Definition: union.hh:22
auto join_automata(Auts &&...auts) -> decltype(make_mutable_automaton(join(auts->context()...)))
An automaton whose type is the join between those of auts.
auto union_a(const A &lhs, const B &rhs) -> decltype(join_automata(lhs, rhs))
Union of two automata.
Definition: union.hh:32