HiPipe  0.7.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 rgv = ranges::views;
21 
22 namespace detail {
23 
24  template<typename... Columns>
25  class drop_fn {
26  private:
27  friend rgv::view_access;
28 
29  static auto bind(drop_fn<Columns...> fun)
30  {
31  return ranges::make_pipeable(std::bind(fun, std::placeholders::_1));
32  }
33 
34  public:
35  CPP_template(class Rng)(requires ranges::input_range<Rng>)
36  forward_stream_t operator()(Rng&& rng) const
37  {
38  return rgv::transform(std::forward<Rng>(rng),
39  [](batch_t batch) -> batch_t {
40  ((batch.erase<Columns>()), ...);
41  return batch;
42  });
43  }
44 
46  CPP_template(class Rng)(requires !ranges::input_range<Rng>)
47  void operator()(Rng&&) const
48  {
49  CONCEPT_ASSERT_MSG(ranges::input_range<Rng>(),
50  "stream::drop only works on ranges satisfying the input_range concept.");
51  }
53  };
54 
55 } // namespace detail
56 
57 
68 template <typename... Columns>
69 rgv::view<detail::drop_fn<Columns...>> drop{};
70 
71 } // end namespace hipipe::stream
hipipe::utility::CPP_template
CPP_template(class Rng)(requires ranges
Unzips a range of tuples to a tuple of std::vectors.
Definition: tuple.hpp:255
hipipe::stream::forward_stream_t
ranges::any_view< batch_t, ranges::category::forward > forward_stream_t
The stream itself, i.e., a range of batches.
Definition: stream_t.hpp:29
hipipe::stream::drop
rgv::view< detail::drop_fn< Columns... > > drop
Drops columns from a stream.
Definition: drop.hpp:75
hipipe::stream::transform
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:218