RxCpp
The Reactive Extensions for Native (RxCpp) is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators in both C and C++.
linq_select.hpp
Go to the documentation of this file.
1 // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
2 
3 #if !defined(CPPLINQ_LINQ_SELECT_HPP)
4 #define CPPLINQ_LINQ_SELECT_HPP
5 #pragma once
6 
7 #include <cstddef>
8 
9 namespace cpplinq
10 {
11  template <class Collection, class Selector>
13  {
14  typedef typename Collection::cursor
15  inner_cursor;
16  public:
17  struct cursor {
18  typedef typename util::result_of<Selector(typename inner_cursor::element_type)>::type
20  typedef typename std::remove_reference<reference_type>::type
22  typedef typename inner_cursor::cursor_category
24 
25  cursor(const inner_cursor& cur, Selector sel) : cur(cur), sel(std::move(sel)) {}
26 
27  void forget() { cur.forget(); }
28  bool empty() const { return cur.empty(); }
29  void inc() { cur.inc(); }
30  reference_type get() const { return sel(cur.get()); }
31 
32  bool atbegin() const { return cur.atbegin(); }
33  void dec() { cur.dec(); }
34 
35  void skip(std::size_t n) { cur.skip(n); }
36  std::size_t position() const { return cur.position(); }
37  std::size_t size() const { return cur.size(); }
38  private:
39  inner_cursor cur;
40  Selector sel;
41  };
42 
43  linq_select(const Collection& c, Selector sel) : c(c), sel(sel) {}
44 
45  cursor get_cursor() const { return cursor(c.get_cursor(), sel); }
46 
47  private:
48  Collection c;
49  Selector sel;
50  };
51 
52 }
53 
54 #endif // defined(CPPLINQ_LINQ_SELECT_HPP)
Definition: linq_select.hpp:12
std::remove_reference< reference_type >::type element_type
Definition: linq_select.hpp:21
bool atbegin() const
Definition: linq_select.hpp:32
cursor get_cursor() const
Definition: linq_select.hpp:45
void skip(std::size_t n)
Definition: linq_select.hpp:35
cursor(const inner_cursor &cur, Selector sel)
Definition: linq_select.hpp:25
Definition: linq.hpp:186
inner_cursor::cursor_category cursor_category
Definition: linq_select.hpp:23
void dec()
Definition: linq_select.hpp:33
std::size_t size() const
Definition: linq_select.hpp:37
linq_select(const Collection &c, Selector sel)
Definition: linq_select.hpp:43
void inc()
Definition: linq_select.hpp:29
util::result_of< Selector(typename inner_cursor::element_type)>::type reference_type
Definition: linq_select.hpp:19
void forget()
Definition: linq_select.hpp:27
std::size_t position() const
Definition: linq_select.hpp:36
Definition: linq_select.hpp:17
bool empty() const
Definition: linq_select.hpp:28