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++.
Classes | Namespaces | Macros | Functions
linq.hpp File Reference
#include <functional>
#include <iterator>
#include <algorithm>
#include <numeric>
#include <list>
#include <map>
#include <set>
#include <memory>
#include <utility>
#include <type_traits>
#include <vector>
#include <cstddef>
#include "util.hpp"
#include "linq_cursor.hpp"
#include "linq_iterators.hpp"
#include "linq_select.hpp"
#include "linq_take.hpp"
#include "linq_skip.hpp"
#include "linq_groupby.hpp"
#include "linq_where.hpp"
#include "linq_last.hpp"
#include "linq_selectmany.hpp"
Include dependency graph for linq.hpp:

Go to the source code of this file.

Classes

class  cpplinq::linq_driver< Collection >
 

Namespaces

 cpplinq
 

Macros

#define LINQ_USE_RTTI   1
 

Functions

template<class TContainer >
linq_driver< iter_cursor< typename util::container_traits< TContainer >::iterator > > cpplinq::from (TContainer &c)
 
template<class T >
const linq_driver< T > & cpplinq::from (const linq_driver< T > &c)
 
template<class Iter >
linq_driver< iter_cursor< Iter > > cpplinq::from (Iter start, Iter finish)
 
template<class TContainer >
linq_driver< TContainer > cpplinq::from_value (const TContainer &c)
 

Macro Definition Documentation

#define LINQ_USE_RTTI   1

namespace cpplinq

Defines a number of range-based composable operators for enumerating and modifying collections

The general design philosophy is to (1) emulate the composable query patterns introduced in C# Linq (2) preserve iterator category and writability where possible For instance, like C# Linq we have a select operator to project one sequence into a new one. Unlike Linq, invoking Select on a random access sequence will yield you a random access sequence.

The general workflow begins with 'from()' which normally only takes a reference the the collection in question. However, from that point on, all operators function by value, so that the range can store any necessary state, rather than duplicating it onto iterator pairs.

In subsequent documentation, "powers" lists which powers that the operator attempts to preserve if available on on the input sequence. Some iterator powers may be skipped - in such a case, round down to the next supported power (e.g. if 'fwd' and 'rnd', an input of 'bidi' will round down to a 'fwd' result).

class linq_query

from(container&)

  • Result: Query

Construct a new query, from an lvalue reference to a collection. Does not copy the collection

from(iter, iter)

  • Result: Query

Construct a new query, from an iterator pair.

query.select(map)

  • Result: Query
  • Powers: input, forward, bidirectional, random access

For each element x in the input sequences, computes map(x) for the result sequence.

query.where(pred) -> query

  • Result: Query
  • Powers: input, forward, bidirectional

Each element x in the input appears in the output if pred(x) is true.

The expression pred(x) is evaluated only when moving iterators (op++, op–). Dereferencing (op*) does not invoke the predicate.

query.groupby(keymap [, keyequal])

Result: Query of groups. Each group has a 'key' field, and is a query of elements from the input. Powers: forward

query.any([pred])

  • Result: bool

(No argument) Returns true if sequence is non-empty. Equivalent to query.begin()!=query.end()

(One argument) Returns true if the sequence contains any elements for which pred(element) is true. Equivalent to query.where(pred).any().

query.all(pred)

  • Result: bool

Returns true if pred holds for all elements in the sequence. Equivalent to !query.any(std::not1(pred))

query.take(n)

  • Result: query
  • Powers: input, forward, random access (not bidirectional)

Returns a sequence that contains up to n items from the original sequence.

query.skip(n)

  • Result: query
  • Powers: input, forward, random access (not bidirectional)

Returns a sequence that skips the first n items from the original sequence, or an empty sequence if fewer than n were available on input.

Note: begin() takes O(n) time when input iteration power is weaker than random access.

query.count([pred])

  • Result: std::size_t

TODO: should use inner container's iterator distance type instead.

(Zero-argument) Returns the number of elements in the range. Equivalent to std::distance(query.begin(), query.end())

(One-argument) Returns the number of elements for whicht pred(element) is true. Equivalent to query.where(pred).count()