HiPipe  0.6.0
C++17 data pipeline with Python bindings.
drop.hpp
1 /****************************************************************************
2  * hipipe library
3  * Copyright (c) 2017, Cognexa Solutions s.r.o.
4  * Copyright (c) 2018, Iterait a.s.
5  * Author(s) Filip Matzner
6  *
7  * This file is distributed under the MIT License.
8  * See the accompanying file LICENSE.txt for the complete license agreement.
9  ****************************************************************************/
10 
11 #pragma once
12 
13 #include <hipipe/core/stream/stream_t.hpp>
14 
15 #include <range/v3/view/transform.hpp>
16 
17 
18 namespace hipipe::stream {
19 
20 namespace detail {
21 
22  template<typename... Columns>
23  class drop_fn {
24  private:
25  friend ranges::view::view_access;
26 
27  static auto bind(drop_fn<Columns...> fun)
28  {
29  return ranges::make_pipeable(std::bind(fun, std::placeholders::_1));
30  }
31 
32  public:
33  template<typename Rng, CONCEPT_REQUIRES_(ranges::InputRange<Rng>())>
34  forward_stream_t operator()(Rng&& rng) const
35  {
36  return ranges::view::transform(std::forward<Rng>(rng),
37  [](batch_t batch) -> batch_t {
38  ((batch.erase<Columns>()), ...);
39  return batch;
40  });
41  }
42 
44  template<typename Rng, CONCEPT_REQUIRES_(!ranges::InputRange<Rng>())>
45  void operator()(Rng&&) const
46  {
47  CONCEPT_ASSERT_MSG(ranges::InputRange<Rng>(),
48  "stream::drop only works on ranges satisfying the InputRange concept.");
49  }
51  };
52 
53 } // namespace detail
54 
55 
66 template <typename... Columns>
67 ranges::view::view<detail::drop_fn<Columns...>> drop{};
68 
69 } // end namespace hipipe::stream
ranges::any_view< batch_t, ranges::category::forward > forward_stream_t
The stream itself, i.e., a range of batches.
Definition: stream_t.hpp:24
auto transform(from_t< FromColumns... > f, to_t< ToColumns... > t, Fun fun, dim_t< Dim > d=dim_t< 1 >{})
Transform a subset of hipipe columns to a different subset of hipipe columns.
Definition: transform.hpp:187
Definition: ndim.hpp:144
ranges::view::view< detail::drop_fn< Columns... > > drop
Drops columns from a stream.
Definition: drop.hpp:67