Vcsn  2.0
Be Rational
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
union.hh
Go to the documentation of this file.
1 #ifndef VCSN_ALGOS_UNION_HH
2 # define VCSN_ALGOS_UNION_HH
3 
4 # include <unordered_map>
5 
6 # include <vcsn/algos/copy.hh>
7 # include <vcsn/algos/product.hh> // join_automata
9 # include <vcsn/dyn/automaton.hh> // dyn::make_automaton
10 
11 namespace vcsn
12 {
13  /*----------.
14  | union_a. |
15  `----------*/
16 
20  template <typename A, typename B>
21  inline
22  A&
23  union_here(A& res, const B& b)
24  {
25  ::vcsn::copy_into(b, res);
26  return res;
27  }
28 
30  template <typename A, typename B>
31  inline
32  auto
33  union_a(const A& lhs, const B& rhs)
34  -> decltype(join_automata(lhs, rhs))
35  {
36  auto res = join_automata(lhs, rhs);
37  union_here(res, lhs);
38  union_here(res, rhs);
39  return res;
40  }
41 
42  namespace dyn
43  {
44  namespace detail
45  {
46  /*---------------.
47  | dyn::union_a. |
48  `---------------*/
49 
50  template <typename Lhs, typename Rhs>
51  inline
52  automaton
53  union_a(const automaton& lhs, const automaton& rhs)
54  {
55  const auto& l = lhs->as<Lhs>();
56  const auto& r = rhs->as<Rhs>();
57  return make_automaton(::vcsn::union_a(l, r));
58  }
59 
61  (const automaton&, const automaton&) -> automaton);
62  }
63  }
64 }
65 
66 #endif // !VCSN_ALGOS_UNION_HH
REGISTER_DECLARE(accessible,(const automaton &) -> automaton)
std::shared_ptr< detail::automaton_base > automaton
Definition: automaton.hh:71
automaton make_automaton(const Aut &aut)
Build a dyn::automaton.
Definition: automaton.hh:77
auto join_automata(Auts &&...auts) -> decltype(make_mutable_automaton(join(auts->context()...)))
Join between automata.
Definition: product.hh:24
A & union_here(A &res, const B &b)
Merge transitions of b into those of res.
Definition: union.hh:23
auto union_a(const A &lhs, const B &rhs) -> decltype(join_automata(lhs, rhs))
Union of two automata.
Definition: union.hh:33
Provide a variadic mul on top of a binary mul(), and one().
Definition: fwd.hh:36
void copy_into(const AutIn &in, AutOut &out, Pred keep_state)
Copy an automaton.
Definition: copy.hh:101
automaton union_a(const automaton &lhs, const automaton &rhs)
Definition: union.hh:53