/*
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2015 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
RangeSource<Iterator>> {
Range<Iterator> range_;
public:
- RangeSource() {}
+ RangeSource() = default;
explicit RangeSource(Range<Iterator> range)
: range_(std::move(range))
{}
void foreach(Body&&) const {}
};
-template<class Value>
-class Just : public GenImpl<const Value&, Just<Value>> {
+template <class Value>
+class SingleReference : public GenImpl<Value&, SingleReference<Value>> {
+ static_assert(!std::is_reference<Value>::value,
+ "SingleReference requires non-ref types");
+ Value* ptr_;
+ public:
+ explicit SingleReference(Value& ref) : ptr_(&ref) {}
+
+ template <class Handler>
+ bool apply(Handler&& handler) const {
+ return handler(*ptr_);
+ }
+
+ template <class Body>
+ void foreach(Body&& body) const {
+ body(*ptr_);
+ }
+};
+
+template <class Value>
+class SingleCopy : public GenImpl<const Value&, SingleCopy<Value>> {
static_assert(!std::is_reference<Value>::value,
- "Just requires non-ref types");
- const Value value_;
+ "SingleCopy requires non-ref types");
+ Value value_;
public:
- explicit Just(Value value) : value_(std::forward<Value>(value)) {}
+ explicit SingleCopy(Value value) : value_(std::forward<Value>(value)) {}
template <class Handler>
bool apply(Handler&& handler) const {
class Map : public Operator<Map<Predicate>> {
Predicate pred_;
public:
- Map() {}
+ Map() = default;
explicit Map(Predicate pred)
: pred_(std::move(pred))
class Filter : public Operator<Filter<Predicate>> {
Predicate pred_;
public:
- Filter() {}
+ Filter() = default;
explicit Filter(Predicate pred)
: pred_(std::move(pred))
{ }
class Until : public Operator<Until<Predicate>> {
Predicate pred_;
public:
- Until() {}
+ Until() = default;
explicit Until(Predicate pred)
: pred_(std::move(pred))
{}
Selector selector_;
Comparer comparer_;
public:
- Order() {}
+ Order() = default;
explicit Order(Selector selector)
: selector_(std::move(selector))
class Distinct : public Operator<Distinct<Selector>> {
Selector selector_;
public:
- Distinct() {}
+ Distinct() = default;
explicit Distinct(Selector selector)
: selector_(std::move(selector))
Seed seed_;
Fold fold_;
public:
- FoldLeft() {}
+ FoldLeft() = default;
FoldLeft(Seed seed,
Fold fold)
: seed_(std::move(seed))
*/
class First : public Operator<First> {
public:
- First() { }
+ First() = default;
template<class Source,
class Value,
*/
class Any : public Operator<Any> {
public:
- Any() { }
+ Any() = default;
template<class Source,
class Value>
class All : public Operator<All<Predicate>> {
Predicate pred_;
public:
- All() {}
+ All() = default;
explicit All(Predicate pred)
: pred_(std::move(pred))
{ }
class Reduce : public Operator<Reduce<Reducer>> {
Reducer reducer_;
public:
- Reduce() {}
+ Reduce() = default;
explicit Reduce(Reducer reducer)
: reducer_(std::move(reducer))
{}
*/
class Count : public Operator<Count> {
public:
- Count() { }
+ Count() = default;
template<class Source,
class Value>
Selector selector_;
Comparer comparer_;
public:
- Min() {}
+ Min() = default;
explicit Min(Selector selector)
: selector_(std::move(selector))
template<class Collection>
class Collect : public Operator<Collect<Collection>> {
public:
- Collect() { }
+ Collect() = default;
template<class Value,
class Source,
template<class> class Allocator>
class CollectTemplate : public Operator<CollectTemplate<Container, Allocator>> {
public:
- CollectTemplate() { }
+ CollectTemplate() = default;
template<class Value,
class Source,
*/
class Concat : public Operator<Concat> {
public:
- Concat() { }
+ Concat() = default;
template<class Inner,
class Source,
*/
class RangeConcat : public Operator<RangeConcat> {
public:
- RangeConcat() { }
+ RangeConcat() = default;
template<class Range,
class Source,
*/
class Dereference : public Operator<Dereference> {
public:
- Dereference() {}
+ Dereference() = default;
template<class Value,
class Source,
*/
class Indirect : public Operator<Indirect> {
public:
- Indirect() {}
+ Indirect() = default;
template <class Value,
class Source,
* non-template operators, statically defined to avoid the need for anything but
* the header.
*/
-static const detail::Sum sum;
+static const detail::Sum sum{};
-static const detail::Count count;
+static const detail::Count count{};
-static const detail::First first;
+static const detail::First first{};
/**
* Use directly for detecting any values, or as a function to detect values
* auto nonempty = g | any;
* auto evens = g | any(even);
*/
-static const detail::Any any;
+static const detail::Any any{};
-static const detail::Min<Identity, Less> min;
+static const detail::Min<Identity, Less> min{};
-static const detail::Min<Identity, Greater> max;
+static const detail::Min<Identity, Greater> max{};
-static const detail::Order<Identity> order;
+static const detail::Order<Identity> order{};
-static const detail::Distinct<Identity> distinct;
+static const detail::Distinct<Identity> distinct{};
-static const detail::Map<Move> move;
+static const detail::Map<Move> move{};
-static const detail::Concat concat;
+static const detail::Concat concat{};
-static const detail::RangeConcat rconcat;
+static const detail::RangeConcat rconcat{};
/**
* Use directly for infinite sequences, or as a function to limit cycle count.
* auto forever = g | cycle;
* auto thrice = g | cycle(3);
*/
-static const detail::Cycle cycle;
+static const detail::Cycle cycle{};
-static const detail::Dereference dereference;
+static const detail::Dereference dereference{};
-static const detail::Indirect indirect;
+static const detail::Indirect indirect{};
inline detail::Take take(size_t count) {
return detail::Take(count);