cxtream  0.5.1
C++17 data pipeline with Python bindings.
drop.hpp
1 /****************************************************************************
2  * cxtream library
3  * Copyright (c) 2017, Cognexa Solutions s.r.o.
4  * Author(s) Filip Matzner
5  *
6  * This file is distributed under the MIT License.
7  * See the accompanying file LICENSE.txt for the complete license agreement.
8  ****************************************************************************/
9 
10 #ifndef CXTREAM_CORE_STREAM_DROP_HPP
11 #define CXTREAM_CORE_STREAM_DROP_HPP
12 
13 #include <cxtream/core/utility/tuple.hpp>
14 
15 #include <range/v3/view/transform.hpp>
16 
17 namespace cxtream::stream {
18 
19 namespace detail {
20 
21  template<typename Source, typename... DropColumns>
22  struct drop_impl;
23 
24  template<typename... SourceColumns, typename... DropColumns>
25  struct drop_impl<std::tuple<SourceColumns...>, DropColumns...> {
26 
27  constexpr decltype(auto) operator()(std::tuple<SourceColumns...> source) const
28  {
29  return utility::tuple_remove<DropColumns...>(std::move(source));
30  }
31 
32  };
33 
34  template<typename... Columns>
35  class drop_fn {
36  private:
37  friend ranges::view::view_access;
38 
39  static auto bind(drop_fn<Columns...> fun)
40  {
41  return ranges::make_pipeable(std::bind(fun, std::placeholders::_1));
42  }
43 
44  public:
45  template<typename Rng, CONCEPT_REQUIRES_(ranges::ForwardRange<Rng>())>
46  constexpr auto operator()(Rng&& rng) const
47  {
48  using StreamType = ranges::range_value_type_t<Rng>;
50  std::forward<Rng>(rng),
51  drop_impl<StreamType, Columns...>{});
52  }
53 
55  template<typename Rng, CONCEPT_REQUIRES_(!ranges::ForwardRange<Rng>())>
56  void operator()(Rng&&) const
57  {
58  CONCEPT_ASSERT_MSG(ranges::ForwardRange<Rng>(),
59  "stream::drop only works on ranges satisfying the ForwardRange concept.");
60  }
62  };
63 
64 } // namespace detail
65 
76 template <typename... Columns>
77 constexpr ranges::view::view<detail::drop_fn<Columns...>> drop{};
78 
79 } // end namespace cxtream::stream
80 #endif
constexpr auto transform(from_t< FromColumns... > f, to_t< ToColumns... > t, Fun fun, dim_t< Dim > d=dim_t< 1 >{})
Transform a subset of cxtream columns to a different subset of cxtream columns.
Definition: transform.hpp:177
STL namespace.
constexpr ranges::view::view< detail::drop_fn< Columns... > > drop
Drops columns from a stream.
Definition: drop.hpp:77
constexpr auto tuple_remove(Tuple tuple)
Remove types from a tuple.
Definition: tuple.hpp:334