Vcsn  2.0
Be Rational
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
weightset.hh
Go to the documentation of this file.
1 #ifndef VCSN_WEIGHTSET_WEIGHTSET_HH
2 # define VCSN_WEIGHTSET_WEIGHTSET_HH
3 
4 # include <iostream>
5 
6 // It is much simpler and saner in C++ to put types and functions on
7 // these types in the same namespace. Since "using q =
8 // detail::variadic_mul_mixin<q_impl>" would just create an alias of
9 // q, its original namespace, detail::, would still be the namespace
10 // used in ADL.
11 //
12 // This is really troublesome to implement free-functions such as join.
13 //
14 // Therefore, although this wrapper should be hidden as a detail::, it
15 // will remain in vcsn::, where join and the like will find it.
16 
17 namespace vcsn
18 {
20  template <typename WeightSet>
21  struct variadic_mul_mixin : WeightSet
22  {
23  using super_t = WeightSet;
24  using typename super_t::value_t;
25 
26  // Inherit the constructors.
27  using super_t::super_t;
28 
29  // Provide a variadic mul.
30  using super_t::mul;
31 
32  template <typename... Ts>
33  value_t mul(const Ts&... ts) const
34  {
35  value_t res = this->one();
36  // FIXME: Remove once GCC is fixed.
37  using swallow = int[];
38  (void) swallow
39  {
40  ((res = super_t::mul(res, ts)), 0)...
41  };
42  return res;
43  }
44  };
45 }
46 
47 #endif // !VCSN_WEIGHTSET_WEIGHTSET_HH
value_t mul(const Ts &...ts) const
Definition: weightset.hh:33