Vcsn  2.3
Be Rational
project.hh
Go to the documentation of this file.
1 #pragma once
2 
4 #include <vcsn/dyn/context.hh>
5 #include <vcsn/dyn/value.hh>
7 #include <vcsn/dyn/name.hh> // integral_constant
8 #include <vcsn/dyn/value.hh>
9 
10 namespace vcsn
11 {
12  /*--------------------.
13  | project(context). |
14  `--------------------*/
15 
16  namespace dyn
17  {
18  namespace detail
19  {
21  template <typename Context, typename Tape>
22  context
24  {
25  auto& c = ctx->as<Context>();
26  return vcsn::detail::project<Tape::value>(c);
27  }
28  }
29  }
30 
31 
32  /*--------------------------.
33  | project(expressionset). |
34  `--------------------------*/
35 
36  namespace detail
37  {
39  template <size_t Tape, typename Context>
41  {
42  // Weirdly enough, GCC enters an endless loop of instantiation
43  // if we use this type as explicit function return type.
44  return make_expressionset(project<Tape>(rs.context()), rs.identities());
45  }
46  }
47 
48  /*----------------------.
49  | project(expansion). |
50  `----------------------*/
51 
52  namespace detail
53  {
57  template <size_t Tape, typename ValueSet>
58  auto project(const ValueSet& vs,
59  const typename ValueSet::value_t& v)
60  {
61  static_assert(Tape < labelset_t_of<ValueSet>::size(),
62  "project: invalid tape number");
63  return vs.template project<Tape>(v);
64  }
65  }
66 
67  namespace dyn
68  {
69  namespace detail
70  {
72  template <typename ExpansionSet, typename Tape>
73  expansion
75  {
76  constexpr auto tape = Tape::value;
77  auto& x = exp->as<ExpansionSet>();
78  const auto& xs_in = x.valueset();
79  auto xs_out = xs_in.template project<tape>();
80  return {xs_out, vcsn::detail::project<tape>(xs_in, x.value())};
81  }
82  }
83  }
84 
85  /*-----------------------.
86  | project(expression). |
87  `-----------------------*/
88 
89  namespace dyn
90  {
91  namespace detail
92  {
94  template <typename ExpressionSet, typename Tape>
97  {
98  constexpr auto tape = Tape::value;
99  auto& r = exp->as<ExpressionSet>();
100  const auto& rs_in = r.valueset();
101  auto rs_out = vcsn::detail::project<tape>(rs_in);
102  return {rs_out, vcsn::detail::project<tape>(rs_in, r.value())};
103  }
104  }
105  }
106 
107  /*-----------------------.
108  | project(polynomial). |
109  `-----------------------*/
110 
111  namespace detail
112  {
114  template <size_t Tape, typename Context, wet_kind_t Kind>
116  {
117  static_assert(Tape < labelset_t_of<Context>::size(),
118  "project: invalid tape number");
119  auto ctx_out = vcsn::detail::project<Tape>(ps.context());
120  return make_polynomialset(ctx_out);
121  }
122  }
123 
124  namespace dyn
125  {
126  namespace detail
127  {
129  template <typename PolynomialSet, typename Tape>
130  polynomial
132  {
133  constexpr auto tape = Tape::value;
134  auto& p = poly->as<PolynomialSet>();
135  const auto& ps_in = p.valueset();
136  auto ps_out = vcsn::detail::project<tape>(ps_in);
137  return {ps_out, vcsn::detail::project<tape>(ps_in, p.value())};
138  }
139  }
140  }
141 
142  /*------------------.
143  | project(label). |
144  `------------------*/
145 
146  namespace dyn
147  {
148  namespace detail
149  {
151  template <typename Label, typename Tape>
152  label
154  {
155  constexpr auto tape = Tape::value;
156  const auto& l = lbl->as<Label>();
157  const auto& ls = l.valueset();
158  return {ls.template set<tape>(), std::get<tape>(l.value())};
159  }
160  }
161  }
162 }
label project_label(const label &lbl, integral_constant)
Bridge (project).
Definition: project.hh:153
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
Definition: traits.hh:63
auto project(const expressionset< Context > &rs)
Project an expressionset to one tape.
Definition: project.hh:40
auto & as()
Downcast to the exact type.
Definition: context.hh:36
A dyn Value/ValueSet.
Definition: fwd.hh:23
value_impl< detail::label_tag > label
Definition: fwd.hh:26
Template-less root for contexts.
Definition: context.hh:16
auto rs
Definition: lift.hh:152
Definition: a-star.hh:8
value_impl< detail::polynomial_tag > polynomial
Definition: fwd.hh:27
polynomial project_polynomial(const polynomial &poly, integral_constant)
Bridge (project).
Definition: project.hh:131
A simple placeholder for integral constants.
Definition: name.hh:196
value_impl< detail::expansion_tag > expansion
Definition: fwd.hh:24
expansion project_expansion(const expansion &exp, integral_constant)
Bridge (project).
Definition: project.hh:74
auto make_expressionset(const context< LabelSet, WeightSet > &ctx, rat::identities ids={}) -> expressionset< context< LabelSet, WeightSet >>
Shorthand to expressionset constructor.
automaton project(const automaton &aut, unsigned tape)
Keep a single tape from a multiple-tape automaton.
Definition: others.cc:113
polynomialset< Context, Kind > make_polynomialset(const Context &context)
auto & as()
Extract wrapped typed value.
Definition: value.hh:53
expression project_expression(const expression &exp, integral_constant)
Bridge (project).
Definition: project.hh:96
context project_context(const context &ctx, integral_constant)
Bridge (project).
Definition: project.hh:23
Provide a variadic mul on top of a binary mul(), and one().
Definition: fwd.hh:46
value_impl< detail::expression_tag > expression
Definition: fwd.hh:25