transducer_impl.hpp
Go to the documentation of this file.
1 //
2 // Copyright (C) 2014, 2015 Ableton AG, Berlin. All rights reserved.
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a
5 // copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 // and/or sell copies of the Software, and to permit persons to whom the
9 // Software is furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
21 //
22 
27 #pragma once
28 
30 #include <atria/estd/utility.hpp>
31 #include <tuple>
32 
33 namespace atria {
34 namespace xform {
35 
58 template<typename ReducingFnGenT,
59  typename ...ParamTs>
60 struct transducer_impl : std::tuple<ParamTs...>
61 {
62  using base_t = std::tuple<ParamTs...>;
63 
64  // Constructors need to be semi-manually defined. Otherwise
65  // confusion arises because of the way Clang's std::tuple uses
66  // enable_if to dispatch to the right move constructors.
67  //
68  // using base_t::base_t;
69 
70  transducer_impl() = default;
71  transducer_impl(const transducer_impl&) = default;
72  transducer_impl(transducer_impl&&) = default;
73  transducer_impl& operator=(const transducer_impl&) = default;
74  transducer_impl& operator=(transducer_impl&&) = default;
75 
76  template <typename ...Ts>
77  transducer_impl(Ts ...ts)
78  : base_t(std::move(ts)...)
79  {}
80 
81  template<typename ReducingFnT>
82  constexpr auto operator() (ReducingFnT&& step) const
83  -> typename ReducingFnGenT::template apply<
86  >
87  {
88  using indexes_t = estd::make_index_sequence<sizeof...(ParamTs)>;
89  return this->make(std::forward<ReducingFnT>(step), indexes_t());
90  }
91 
92  template<typename ReducingFnT, std::size_t...indexes_t>
93  constexpr auto make(ReducingFnT&& step, estd::index_sequence<indexes_t...>) const
94  -> typename ReducingFnGenT::template apply<
95  estd::decay_t<ReducingFnT>,
97  >
98  {
99  return { std::forward<ReducingFnT>(step),
100  std::get<indexes_t>(*this)... };
101  }
102 };
103 
104 } // namespace xform
105 } // namespace atria
typename std::decay< T >::type decay_t
Similar to C++14 std::decay_t.
Definition: type_traits.hpp:54
Utility to write simple transducers easily.
C++ amazing templates and reusable implementations awesomeness.
Definition: _doc.hpp:35
Fork me on GitHub