Awali
Another Weighted Automata library
weightset.hh
Go to the documentation of this file.
1 // This file is part of Awali.
2 // Copyright 2016-2022 Sylvain Lombardy, Victor Marsault, Jacques Sakarovitch
3 //
4 // Awali is a free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef AWALI_WEIGHTSET_WEIGHTSET_HH
18 # define AWALI_WEIGHTSET_WEIGHTSET_HH
19 
20 # include <iostream>
21 
22 // It is much simpler and saner in C++ to put types and functions on
23 // these types in the same namespace. Since "using q =
24 // internal::variadic_mul_mixin<q_impl>" would just create an alias of
25 // q, its original namespace, internal::, would still be the namespace
26 // used in ADL.
27 //
28 // This is really troublesome to implement free-functions such as join.
29 //
30 // Therefore, although this wrapper should be hidden as a internal::, it
31 // will remain in sttc::, where join and the like will find it.
32 
33 namespace awali { namespace sttc {
34 
36  template <typename WeightSet>
37  struct variadic_mul_mixin : WeightSet
38  {
39  using super = WeightSet;
40  using typename super::value_t;
41 
42  // Inherit the constructors.
43  using super::super;
44 
45  // Provide a variadic mul.
46  using super::mul;
47 
48  template <typename... Ts>
49  value_t mul(const Ts&... ts) const
50  {
51  value_t res = this->one();
52  // FIXME: Remove once GCC is fixed.
53  using swallow = int[];
54  (void) swallow
55  {
56  ((res = super::mul(res, ts)), 0)...
57  };
58  return res;
59  }
60  };
61 
62 }}//end of ns awali::stc
63 
64 #endif // !AWALI_WEIGHTSET_WEIGHTSET_HH
Main namespace of Awali.
Definition: ato.hh:22
Provide a variadic mul on top of a binary mul(), and one().
Definition: weightset.hh:38
value_t mul(const Ts &... ts) const
Definition: weightset.hh:49
WeightSet super
Definition: weightset.hh:39