Vcsn  2.4
Be Rational
tuple.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vcsn/core/rat/fwd.hh>
4 #include <vcsn/dyn/context.hh>
5 #include <vcsn/dyn/value.hh>
7 
8 namespace vcsn
9 {
10  /*-----------------------------.
11  | tuple_context(context...). |
12  `-----------------------------*/
13 
14  template <typename... Ctx>
15  auto
16  tuple_context(Ctx&&... ctx)
19  {
20  auto ls = make_tupleset(*ctx.labelset()...);
21  auto ws = join(*ctx.weightset()...);
22  return {ls, ws};
23  }
24 
25  /*-----------------------.
26  | tuple(expansion...). |
27  `-----------------------*/
28 
29  namespace dyn
30  {
31  namespace detail
32  {
34  template <typename Contexts, size_t... I>
35  context
36  tuple_(const std::vector<context>& cs,
38  {
39  return tuple_context(cs[I]->template as<tuple_element_t<I, Contexts>>()
40  ...);
41  }
42 
44  template <typename Contexts>
45  context
46  tuple_context(const std::vector<context>& cs)
47  {
48  auto indices
50  return tuple_<Contexts>(cs, indices);
51  }
52  }
53  }
54 
55  /*---------------------------------------.
56  | tuple_expansionset(expansionset...). |
57  `---------------------------------------*/
58 
59  template <typename... ExpansionSets>
60  auto
61  tuple_expansionset(const ExpansionSets&... ess)
62  -> rat::expansionset<decltype(tuple_expressionset(ess.expressionset()...))>
63  {
64  return {tuple_expressionset(ess.expressionset()...)};
65  }
66 
67  /*------------------------.
68  | tuple(expression...). |
69  `------------------------*/
70 
71  template <typename ValueSet, typename... ValueSets>
72  typename ValueSet::value_t
73  tuple(const ValueSet& vs,
74  const typename ValueSets::value_t&... v)
75  {
76  return vs.tuple(v...);
77  }
78 
79  /*-----------------------------------------.
80  | tuple_expressionset(expressionset...). |
81  `-----------------------------------------*/
82 
83  template <typename... ExpSets>
84  auto
85  tuple_expressionset(const ExpSets&... rss)
86  -> expressionset<decltype(tuple_context(rss.context()...))>
87  {
88  auto ctx = tuple_context(rss.context()...);
89  auto ids = join(rss.identities()...);
90  return {ctx, ids};
91  }
92 
93  /*-----------------------.
94  | tuple(expansion...). |
95  `-----------------------*/
96 
97  namespace dyn
98  {
99  namespace detail
100  {
102  template <typename ExpansionSets, size_t... I>
103  expansion
104  tuple_(const std::vector<expansion>& es,
106  {
107  auto xs
109  (es[I]
110  ->template as<tuple_element_t<I, ExpansionSets>>()
111  .valueset()...);
112  return
113  {xs,
114  vcsn::tuple<decltype(xs), tuple_element_t<I, ExpansionSets>...>
115  (xs,
116  es[I]->template as<tuple_element_t<I, ExpansionSets>>()
117  .value()...)};
118  }
119 
121  template <typename ExpansionSets>
122  expansion
123  tuple_expansion(const std::vector<expansion>& es)
124  {
125  auto indices
127  return tuple_<ExpansionSets>(es, indices);
128  }
129  }
130  }
131 
132  /*------------------------.
133  | tuple(expression...). |
134  `------------------------*/
135 
136  namespace dyn
137  {
138  namespace detail
139  {
141  template <typename ExpSets, size_t... I>
142  expression
143  tuple_(const std::vector<expression>& es,
145  {
146  auto rs
148  (es[I]->template as<tuple_element_t<I, ExpSets>>().valueset()...);
149  return
150  {rs,
151  vcsn::tuple<decltype(rs), tuple_element_t<I, ExpSets>...>
152  (rs,
153  es[I]
154  ->template as<tuple_element_t<I, ExpSets>>().value()...)};
155  }
156 
158  template <typename ExpSets>
159  expression
160  tuple_expression(const std::vector<expression>& es)
161  {
162  auto indices
164  return tuple_<ExpSets>(es, indices);
165  }
166  }
167  }
168 
169 
170  /*-----------------------------------------.
171  | tuple_polynomialset(polynomialset...). |
172  `-----------------------------------------*/
173 
174  template <typename... PolynomialSets>
175  auto
176  tuple_polynomialset(const PolynomialSets&... pss)
177  -> polynomialset<decltype(tuple_context(pss.context()...))>
178  {
179  auto ctx = tuple_context(pss.context()...);
180  return {ctx};
181  }
182 
183 
184  /*------------------------.
185  | tuple(polynomial...). |
186  `------------------------*/
187 
188  namespace dyn
189  {
190  namespace detail
191  {
193  template <typename PolynomialSet, size_t... I>
194  polynomial
195  tuple_(const std::vector<polynomial>& polys,
197  {
198  auto ps
200  (polys[I]->template as<tuple_element_t<I, PolynomialSet>>().valueset()...);
201  return
202  {ps,
203  vcsn::tuple<decltype(ps), tuple_element_t<I, PolynomialSet>...>
204  (ps,
205  polys[I]
206  ->template as<tuple_element_t<I, PolynomialSet>>().value()...)};
207  }
208 
210  template <typename PolynomialSets>
211  polynomial
212  tuple_polynomial(const std::vector<polynomial>& ps)
213  {
214  auto indices
216  return tuple_<PolynomialSets>(ps, indices);
217  }
218  }
219  }
220 }
value_impl< detail::expansion_tag > expansion
Definition: fwd.hh:24
expression tuple_expression(const std::vector< expression > &es)
Bridge (tuple).
Definition: tuple.hh:160
auto rs
Definition: lift.hh:152
static identities ids(const driver &d)
Get the identities of the driver.
Definition: parse.cc:89
auto tuple_polynomialset(const PolynomialSets &...pss) -> polynomialset< decltype(tuple_context(pss.context()...))>
Definition: tuple.hh:176
ValueSet::value_t tuple(const ValueSet &vs, const typename ValueSets::value_t &...v)
Definition: tuple.hh:73
decltype(join(std::declval< ValueSets >()...)) join_t
The type of the join of the ValueSets.
Definition: join.hh:78
Provide a variadic mul on top of a binary mul(), and one().
Definition: fwd.hh:46
context tuple_context(const std::vector< context > &cs)
Bridge (tuple).
Definition: tuple.hh:46
tupleset< ValueSets... > make_tupleset(const ValueSets &...vss)
Definition: tupleset.hh:1152
Definition: a-star.hh:8
Template-less root for contexts.
Definition: context.hh:16
automaton tuple_(const std::vector< automaton > &as, vcsn::detail::index_sequence< I... >)
Bridge helper.
auto tuple_expansionset(const ExpansionSets &...ess) -> rat::expansionset< decltype(tuple_expressionset(ess.expressionset()...))>
Definition: tuple.hh:61
return v
Definition: multiply.hh:361
typename std::tuple_element< I, T >::type tuple_element_t
C++14.
Definition: tuple.hh:14
auto tuple_expressionset(const ExpSets &...rss) -> expressionset< decltype(tuple_context(rss.context()...))>
Definition: tuple.hh:85
A dyn Value/ValueSet.
Definition: fwd.hh:23
auto join(const ValueSet &vs) -> ValueSet
The join of a single valueset.
Definition: join.hh:44
value_impl< detail::expression_tag > expression
Definition: fwd.hh:25
auto tuple_context(Ctx &&...ctx) -> context< tupleset< labelset_t_of< Ctx >... >, join_t< weightset_t_of< Ctx >... >>
Definition: tuple.hh:16
polynomial tuple_polynomial(const std::vector< polynomial > &ps)
Bridge (tuple).
Definition: tuple.hh:212
value_impl< detail::polynomial_tag > polynomial
Definition: fwd.hh:27
expansion tuple_expansion(const std::vector< expansion > &es)
Bridge (tuple).
Definition: tuple.hh:123