Commit adb8559d authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Apply clang-format to folly/gen/ (template decls)

Summary: [Folly] Apply `clang-format` to `folly/gen/` (template decls).

Reviewed By: Orvid

Differential Revision: D5216229

fbshipit-source-id: 1659f1944ccde4de39bccd189bb6490395cf29c2
parent 1b0c0d91
...@@ -360,8 +360,7 @@ class InfiniteImpl { ...@@ -360,8 +360,7 @@ class InfiniteImpl {
**/ **/
template <class Value> template <class Value>
struct GeneratorBuilder { struct GeneratorBuilder {
template <class Source, template <class Source, class Yield = detail::Yield<Value, Source>>
class Yield = detail::Yield<Value, Source>>
Yield operator+(Source&& source) { Yield operator+(Source&& source) {
return Yield(std::forward<Source>(source)); return Yield(std::forward<Source>(source));
} }
...@@ -482,7 +481,8 @@ class Map : public Operator<Map<Predicate>> { ...@@ -482,7 +481,8 @@ class Map : public Operator<Map<Predicate>> {
explicit Map(Predicate pred) : pred_(std::move(pred)) {} explicit Map(Predicate pred) : pred_(std::move(pred)) {}
template <class Value, template <
class Value,
class Source, class Source,
class Result = typename ArgumentReference< class Result = typename ArgumentReference<
typename std::result_of<Predicate(Value)>::type>::type> typename std::result_of<Predicate(Value)>::type>::type>
...@@ -510,16 +510,12 @@ class Map : public Operator<Map<Predicate>> { ...@@ -510,16 +510,12 @@ class Map : public Operator<Map<Predicate>> {
static constexpr bool infinite = Source::infinite; static constexpr bool infinite = Source::infinite;
}; };
template <class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(GenImpl<Value, Source>&& source) const { Gen compose(GenImpl<Value, Source>&& source) const {
return Gen(std::move(source.self()), pred_); return Gen(std::move(source.self()), pred_);
} }
template <class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(const GenImpl<Value, Source>& source) const { Gen compose(const GenImpl<Value, Source>& source) const {
return Gen(source.self(), pred_); return Gen(source.self(), pred_);
} }
...@@ -583,16 +579,12 @@ class Filter : public Operator<Filter<Predicate>> { ...@@ -583,16 +579,12 @@ class Filter : public Operator<Filter<Predicate>> {
static constexpr bool infinite = Source::infinite; static constexpr bool infinite = Source::infinite;
}; };
template <class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(GenImpl<Value, Source>&& source) const { Gen compose(GenImpl<Value, Source>&& source) const {
return Gen(std::move(source.self()), pred_); return Gen(std::move(source.self()), pred_);
} }
template <class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(const GenImpl<Value, Source>& source) const { Gen compose(const GenImpl<Value, Source>& source) const {
return Gen(source.self(), pred_); return Gen(source.self(), pred_);
} }
...@@ -644,16 +636,12 @@ class Until : public Operator<Until<Predicate>> { ...@@ -644,16 +636,12 @@ class Until : public Operator<Until<Predicate>> {
static constexpr bool infinite = false; static constexpr bool infinite = false;
}; };
template <class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(GenImpl<Value, Source>&& source) const { Gen compose(GenImpl<Value, Source>&& source) const {
return Gen(std::move(source.self()), pred_); return Gen(std::move(source.self()), pred_);
} }
template <class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(const GenImpl<Value, Source>& source) const { Gen compose(const GenImpl<Value, Source>& source) const {
return Gen(source.self(), pred_); return Gen(source.self(), pred_);
} }
...@@ -704,16 +692,12 @@ class Take : public Operator<Take> { ...@@ -704,16 +692,12 @@ class Take : public Operator<Take> {
static constexpr bool infinite = false; static constexpr bool infinite = false;
}; };
template <class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(GenImpl<Value, Source>&& source) const { Gen compose(GenImpl<Value, Source>&& source) const {
return Gen(std::move(source.self()), count_); return Gen(std::move(source.self()), count_);
} }
template <class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(const GenImpl<Value, Source>& source) const { Gen compose(const GenImpl<Value, Source>& source) const {
return Gen(source.self(), count_); return Gen(source.self(), count_);
} }
...@@ -775,16 +759,12 @@ class Stride : public Operator<Stride> { ...@@ -775,16 +759,12 @@ class Stride : public Operator<Stride> {
static constexpr bool infinite = Source::infinite; static constexpr bool infinite = Source::infinite;
}; };
template <class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(GenImpl<Value, Source>&& source) const { Gen compose(GenImpl<Value, Source>&& source) const {
return Gen(std::move(source.self()), stride_); return Gen(std::move(source.self()), stride_);
} }
template <class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(const GenImpl<Value, Source>& source) const { Gen compose(const GenImpl<Value, Source>& source) const {
return Gen(source.self(), stride_); return Gen(source.self(), stride_);
} }
...@@ -803,7 +783,8 @@ class Sample : public Operator<Sample<Random>> { ...@@ -803,7 +783,8 @@ class Sample : public Operator<Sample<Random>> {
explicit Sample(size_t count, Random rng) explicit Sample(size_t count, Random rng)
: count_(count), rng_(std::move(rng)) {} : count_(count), rng_(std::move(rng)) {}
template <class Value, template <
class Value,
class Source, class Source,
class Rand, class Rand,
class StorageType = typename std::decay<Value>::type> class StorageType = typename std::decay<Value>::type>
...@@ -860,14 +841,16 @@ class Sample : public Operator<Sample<Random>> { ...@@ -860,14 +841,16 @@ class Sample : public Operator<Sample<Random>> {
static constexpr bool infinite = false; static constexpr bool infinite = false;
}; };
template <class Source, template <
class Source,
class Value, class Value,
class Gen = Generator<Value, Source, Random>> class Gen = Generator<Value, Source, Random>>
Gen compose(GenImpl<Value, Source>&& source) const { Gen compose(GenImpl<Value, Source>&& source) const {
return Gen(std::move(source.self()), count_, rng_); return Gen(std::move(source.self()), count_, rng_);
} }
template <class Source, template <
class Source,
class Value, class Value,
class Gen = Generator<Value, Source, Random>> class Gen = Generator<Value, Source, Random>>
Gen compose(const GenImpl<Value, Source>& source) const { Gen compose(const GenImpl<Value, Source>& source) const {
...@@ -934,16 +917,12 @@ class Skip : public Operator<Skip> { ...@@ -934,16 +917,12 @@ class Skip : public Operator<Skip> {
static constexpr bool infinite = Source::infinite; static constexpr bool infinite = Source::infinite;
}; };
template <class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(GenImpl<Value, Source>&& source) const { Gen compose(GenImpl<Value, Source>&& source) const {
return Gen(std::move(source.self()), count_); return Gen(std::move(source.self()), count_);
} }
template <class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(const GenImpl<Value, Source>& source) const { Gen compose(const GenImpl<Value, Source>& source) const {
return Gen(source.self(), count_); return Gen(source.self(), count_);
} }
...@@ -975,7 +954,8 @@ class Order : public Operator<Order<Selector, Comparer>> { ...@@ -975,7 +954,8 @@ class Order : public Operator<Order<Selector, Comparer>> {
Order(Selector selector, Comparer comparer) Order(Selector selector, Comparer comparer)
: selector_(std::move(selector)), comparer_(std::move(comparer)) {} : selector_(std::move(selector)), comparer_(std::move(comparer)) {}
template <class Value, template <
class Value,
class Source, class Source,
class StorageType = typename std::decay<Value>::type, class StorageType = typename std::decay<Value>::type,
class Result = typename std::result_of<Selector(Value)>::type> class Result = typename std::result_of<Selector(Value)>::type>
...@@ -1041,16 +1021,12 @@ class Order : public Operator<Order<Selector, Comparer>> { ...@@ -1041,16 +1021,12 @@ class Order : public Operator<Order<Selector, Comparer>> {
static constexpr bool infinite = false; static constexpr bool infinite = false;
}; };
template <class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(GenImpl<Value, Source>&& source) const { Gen compose(GenImpl<Value, Source>&& source) const {
return Gen(std::move(source.self()), selector_, comparer_); return Gen(std::move(source.self()), selector_, comparer_);
} }
template <class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(const GenImpl<Value, Source>& source) const { Gen compose(const GenImpl<Value, Source>& source) const {
return Gen(source.self(), selector_, comparer_); return Gen(source.self(), selector_, comparer_);
} }
...@@ -1080,7 +1056,8 @@ class GroupBy : public Operator<GroupBy<Selector>> { ...@@ -1080,7 +1056,8 @@ class GroupBy : public Operator<GroupBy<Selector>> {
explicit GroupBy(Selector selector) : selector_(std::move(selector)) {} explicit GroupBy(Selector selector) : selector_(std::move(selector)) {}
template <class Value, template <
class Value,
class Source, class Source,
class ValueDecayed = typename std::decay<Value>::type, class ValueDecayed = typename std::decay<Value>::type,
class Key = typename std::result_of<Selector(Value)>::type, class Key = typename std::result_of<Selector(Value)>::type,
...@@ -1121,16 +1098,12 @@ class GroupBy : public Operator<GroupBy<Selector>> { ...@@ -1121,16 +1098,12 @@ class GroupBy : public Operator<GroupBy<Selector>> {
static constexpr bool infinite = false; static constexpr bool infinite = false;
}; };
template <class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(GenImpl<Value, Source>&& source) const { Gen compose(GenImpl<Value, Source>&& source) const {
return Gen(std::move(source.self()), selector_); return Gen(std::move(source.self()), selector_);
} }
template <class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(const GenImpl<Value, Source>& source) const { Gen compose(const GenImpl<Value, Source>& source) const {
return Gen(source.self(), selector_); return Gen(source.self(), selector_);
} }
...@@ -1228,16 +1201,12 @@ class Distinct : public Operator<Distinct<Selector>> { ...@@ -1228,16 +1201,12 @@ class Distinct : public Operator<Distinct<Selector>> {
static constexpr bool infinite = Source::infinite; static constexpr bool infinite = Source::infinite;
}; };
template <class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(GenImpl<Value, Source>&& source) const { Gen compose(GenImpl<Value, Source>&& source) const {
return Gen(std::move(source.self()), selector_); return Gen(std::move(source.self()), selector_);
} }
template <class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(const GenImpl<Value, Source>& source) const { Gen compose(const GenImpl<Value, Source>& source) const {
return Gen(source.self(), selector_); return Gen(source.self(), selector_);
} }
...@@ -1254,9 +1223,10 @@ class Composer { ...@@ -1254,9 +1223,10 @@ class Composer {
public: public:
explicit Composer(Operators op) : op_(std::move(op)) {} explicit Composer(Operators op) : op_(std::move(op)) {}
template <class Source, template <
class Ret = decltype( class Source,
std::declval<Operators>().compose(std::declval<Source>()))> class Ret =
decltype(std::declval<Operators>().compose(std::declval<Source>()))>
Ret operator()(Source&& source) const { Ret operator()(Source&& source) const {
return op_.compose(std::forward<Source>(source)); return op_.compose(std::forward<Source>(source));
} }
...@@ -1285,7 +1255,8 @@ class Batch : public Operator<Batch> { ...@@ -1285,7 +1255,8 @@ class Batch : public Operator<Batch> {
} }
} }
template <class Value, template <
class Value,
class Source, class Source,
class StorageType = typename std::decay<Value>::type, class StorageType = typename std::decay<Value>::type,
class VectorType = std::vector<StorageType>> class VectorType = std::vector<StorageType>>
...@@ -1325,16 +1296,12 @@ class Batch : public Operator<Batch> { ...@@ -1325,16 +1296,12 @@ class Batch : public Operator<Batch> {
static constexpr bool infinite = Source::infinite; static constexpr bool infinite = Source::infinite;
}; };
template <class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(GenImpl<Value, Source>&& source) const { Gen compose(GenImpl<Value, Source>&& source) const {
return Gen(std::move(source.self()), batchSize_); return Gen(std::move(source.self()), batchSize_);
} }
template <class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(const GenImpl<Value, Source>& source) const { Gen compose(const GenImpl<Value, Source>& source) const {
return Gen(source.self(), batchSize_); return Gen(source.self(), batchSize_);
} }
...@@ -1360,7 +1327,8 @@ class Concat : public Operator<Concat> { ...@@ -1360,7 +1327,8 @@ class Concat : public Operator<Concat> {
public: public:
Concat() = default; Concat() = default;
template <class Inner, template <
class Inner,
class Source, class Source,
class InnerValue = typename std::decay<Inner>::type::ValueType> class InnerValue = typename std::decay<Inner>::type::ValueType>
class Generator class Generator
...@@ -1393,16 +1361,12 @@ class Concat : public Operator<Concat> { ...@@ -1393,16 +1361,12 @@ class Concat : public Operator<Concat> {
Source::infinite || std::decay<Inner>::type::infinite; Source::infinite || std::decay<Inner>::type::infinite;
}; };
template <class Value, template <class Value, class Source, class Gen = Generator<Value, Source>>
class Source,
class Gen = Generator<Value, Source>>
Gen compose(GenImpl<Value, Source>&& source) const { Gen compose(GenImpl<Value, Source>&& source) const {
return Gen(std::move(source.self())); return Gen(std::move(source.self()));
} }
template <class Value, template <class Value, class Source, class Gen = Generator<Value, Source>>
class Source,
class Gen = Generator<Value, Source>>
Gen compose(const GenImpl<Value, Source>& source) const { Gen compose(const GenImpl<Value, Source>& source) const {
return Gen(source.self()); return Gen(source.self());
} }
...@@ -1424,7 +1388,8 @@ class RangeConcat : public Operator<RangeConcat> { ...@@ -1424,7 +1388,8 @@ class RangeConcat : public Operator<RangeConcat> {
public: public:
RangeConcat() = default; RangeConcat() = default;
template <class Range, template <
class Range,
class Source, class Source,
class InnerValue = typename ValueTypeOfRange<Range>::RefType> class InnerValue = typename ValueTypeOfRange<Range>::RefType>
class Generator class Generator
...@@ -1460,16 +1425,12 @@ class RangeConcat : public Operator<RangeConcat> { ...@@ -1460,16 +1425,12 @@ class RangeConcat : public Operator<RangeConcat> {
static constexpr bool infinite = Source::infinite; static constexpr bool infinite = Source::infinite;
}; };
template <class Value, template <class Value, class Source, class Gen = Generator<Value, Source>>
class Source,
class Gen = Generator<Value, Source>>
Gen compose(GenImpl<Value, Source>&& source) const { Gen compose(GenImpl<Value, Source>&& source) const {
return Gen(std::move(source.self())); return Gen(std::move(source.self()));
} }
template <class Value, template <class Value, class Source, class Gen = Generator<Value, Source>>
class Source,
class Gen = Generator<Value, Source>>
Gen compose(const GenImpl<Value, Source>& source) const { Gen compose(const GenImpl<Value, Source>& source) const {
return Gen(source.self()); return Gen(source.self());
} }
...@@ -1530,16 +1491,12 @@ class GuardImpl : public Operator<GuardImpl<Exception, ErrorHandler>> { ...@@ -1530,16 +1491,12 @@ class GuardImpl : public Operator<GuardImpl<Exception, ErrorHandler>> {
static constexpr bool infinite = Source::infinite; static constexpr bool infinite = Source::infinite;
}; };
template <class Value, template <class Value, class Source, class Gen = Generator<Value, Source>>
class Source,
class Gen = Generator<Value, Source>>
Gen compose(GenImpl<Value, Source>&& source) const { Gen compose(GenImpl<Value, Source>&& source) const {
return Gen(std::move(source.self()), handler_); return Gen(std::move(source.self()), handler_);
} }
template <class Value, template <class Value, class Source, class Gen = Generator<Value, Source>>
class Source,
class Gen = Generator<Value, Source>>
Gen compose(const GenImpl<Value, Source>& source) const { Gen compose(const GenImpl<Value, Source>& source) const {
return Gen(source.self(), handler_); return Gen(source.self(), handler_);
} }
...@@ -1557,7 +1514,8 @@ class Dereference : public Operator<Dereference> { ...@@ -1557,7 +1514,8 @@ class Dereference : public Operator<Dereference> {
public: public:
Dereference() = default; Dereference() = default;
template <class Value, template <
class Value,
class Source, class Source,
class Result = decltype(*std::declval<Value>())> class Result = decltype(*std::declval<Value>())>
class Generator : public GenImpl<Result, Generator<Value, Source, Result>> { class Generator : public GenImpl<Result, Generator<Value, Source, Result>> {
...@@ -1589,16 +1547,12 @@ class Dereference : public Operator<Dereference> { ...@@ -1589,16 +1547,12 @@ class Dereference : public Operator<Dereference> {
static constexpr bool infinite = Source::infinite; static constexpr bool infinite = Source::infinite;
}; };
template <class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(GenImpl<Value, Source>&& source) const { Gen compose(GenImpl<Value, Source>&& source) const {
return Gen(std::move(source.self())); return Gen(std::move(source.self()));
} }
template <class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(const GenImpl<Value, Source>& source) const { Gen compose(const GenImpl<Value, Source>& source) const {
return Gen(source.self()); return Gen(source.self());
} }
...@@ -1616,7 +1570,8 @@ class Indirect : public Operator<Indirect> { ...@@ -1616,7 +1570,8 @@ class Indirect : public Operator<Indirect> {
public: public:
Indirect() = default; Indirect() = default;
template <class Value, template <
class Value,
class Source, class Source,
class Result = typename std::remove_reference<Value>::type*> class Result = typename std::remove_reference<Value>::type*>
class Generator : public GenImpl<Result, Generator<Value, Source, Result>> { class Generator : public GenImpl<Result, Generator<Value, Source, Result>> {
...@@ -1645,16 +1600,12 @@ class Indirect : public Operator<Indirect> { ...@@ -1645,16 +1600,12 @@ class Indirect : public Operator<Indirect> {
static constexpr bool infinite = Source::infinite; static constexpr bool infinite = Source::infinite;
}; };
template <class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(GenImpl<Value, Source>&& source) const { Gen compose(GenImpl<Value, Source>&& source) const {
return Gen(std::move(source.self())); return Gen(std::move(source.self()));
} }
template <class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(const GenImpl<Value, Source>& source) const { Gen compose(const GenImpl<Value, Source>& source) const {
return Gen(source.self()); return Gen(source.self());
} }
...@@ -1722,16 +1673,12 @@ class Cycle : public Operator<Cycle<forever>> { ...@@ -1722,16 +1673,12 @@ class Cycle : public Operator<Cycle<forever>> {
static constexpr bool infinite = forever || Source::infinite; static constexpr bool infinite = forever || Source::infinite;
}; };
template <class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(GenImpl<Value, Source>&& source) const { Gen compose(GenImpl<Value, Source>&& source) const {
return Gen(std::move(source.self()), limit_); return Gen(std::move(source.self()), limit_);
} }
template <class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(const GenImpl<Value, Source>& source) const { Gen compose(const GenImpl<Value, Source>& source) const {
return Gen(source.self(), limit_); return Gen(source.self(), limit_);
} }
...@@ -1792,7 +1739,8 @@ class First : public Operator<First> { ...@@ -1792,7 +1739,8 @@ class First : public Operator<First> {
public: public:
First() = default; First() = default;
template <class Source, template <
class Source,
class Value, class Value,
class StorageType = typename std::decay<Value>::type> class StorageType = typename std::decay<Value>::type>
Optional<StorageType> compose(const GenImpl<Value, Source>& source) const { Optional<StorageType> compose(const GenImpl<Value, Source>& source) const {
...@@ -1862,7 +1810,8 @@ class Reduce : public Operator<Reduce<Reducer>> { ...@@ -1862,7 +1810,8 @@ class Reduce : public Operator<Reduce<Reducer>> {
Reduce() = default; Reduce() = default;
explicit Reduce(Reducer reducer) : reducer_(std::move(reducer)) {} explicit Reduce(Reducer reducer) : reducer_(std::move(reducer)) {}
template <class Source, template <
class Source,
class Value, class Value,
class StorageType = typename std::decay<Value>::type> class StorageType = typename std::decay<Value>::type>
Optional<StorageType> compose(const GenImpl<Value, Source>& source) const { Optional<StorageType> compose(const GenImpl<Value, Source>& source) const {
...@@ -1910,7 +1859,8 @@ class Sum : public Operator<Sum> { ...@@ -1910,7 +1859,8 @@ class Sum : public Operator<Sum> {
public: public:
Sum() = default; Sum() = default;
template <class Source, template <
class Source,
class Value, class Value,
class StorageType = typename std::decay<Value>::type> class StorageType = typename std::decay<Value>::type>
StorageType compose(const GenImpl<Value, Source>& source) const { StorageType compose(const GenImpl<Value, Source>& source) const {
...@@ -1937,7 +1887,8 @@ class Contains : public Operator<Contains<Needle>> { ...@@ -1937,7 +1887,8 @@ class Contains : public Operator<Contains<Needle>> {
public: public:
explicit Contains(Needle needle) : needle_(std::move(needle)) {} explicit Contains(Needle needle) : needle_(std::move(needle)) {}
template <class Source, template <
class Source,
class Value, class Value,
class StorageType = typename std::decay<Value>::type> class StorageType = typename std::decay<Value>::type>
bool compose(const GenImpl<Value, Source>& source) const { bool compose(const GenImpl<Value, Source>& source) const {
...@@ -1980,7 +1931,8 @@ class Min : public Operator<Min<Selector, Comparer>> { ...@@ -1980,7 +1931,8 @@ class Min : public Operator<Min<Selector, Comparer>> {
Min(Selector selector, Comparer comparer) Min(Selector selector, Comparer comparer)
: selector_(std::move(selector)), comparer_(std::move(comparer)) {} : selector_(std::move(selector)), comparer_(std::move(comparer)) {}
template <class Value, template <
class Value,
class Source, class Source,
class StorageType = typename std::decay<Value>::type, class StorageType = typename std::decay<Value>::type,
class Key = typename std::decay< class Key = typename std::decay<
...@@ -2047,7 +1999,8 @@ class Collect : public Operator<Collect<Collection>> { ...@@ -2047,7 +1999,8 @@ class Collect : public Operator<Collect<Collection>> {
public: public:
Collect() = default; Collect() = default;
template <class Value, template <
class Value,
class Source, class Source,
class StorageType = typename std::decay<Value>::type> class StorageType = typename std::decay<Value>::type>
Collection compose(const GenImpl<Value, Source>& source) const { Collection compose(const GenImpl<Value, Source>& source) const {
...@@ -2076,13 +2029,15 @@ class Collect : public Operator<Collect<Collection>> { ...@@ -2076,13 +2029,15 @@ class Collect : public Operator<Collect<Collection>> {
* *
* set<string> uniqueNames = from(names) | as<set>(); * set<string> uniqueNames = from(names) | as<set>();
*/ */
template <template <class, class> class Container, template <
template <class, class> class Container,
template <class> class Allocator> template <class> class Allocator>
class CollectTemplate : public Operator<CollectTemplate<Container, Allocator>> { class CollectTemplate : public Operator<CollectTemplate<Container, Allocator>> {
public: public:
CollectTemplate() = default; CollectTemplate() = default;
template <class Value, template <
class Value,
class Source, class Source,
class StorageType = typename std::decay<Value>::type, class StorageType = typename std::decay<Value>::type,
class Collection = Container<StorageType, Allocator<StorageType>>> class Collection = Container<StorageType, Allocator<StorageType>>>
...@@ -2146,7 +2101,8 @@ const T& operator|(const Optional<T>& opt, const UnwrapOr<T>& fallback) { ...@@ -2146,7 +2101,8 @@ const T& operator|(const Optional<T>& opt, const UnwrapOr<T>& fallback) {
} }
// Mixed type unwrapping always returns values, moving where possible // Mixed type unwrapping always returns values, moving where possible
template <class T, template <
class T,
class U, class U,
class R = typename std::enable_if< class R = typename std::enable_if<
!std::is_same<T, U>::value, !std::is_same<T, U>::value,
...@@ -2158,7 +2114,8 @@ R operator|(Optional<T>&& opt, UnwrapOr<U>&& fallback) { ...@@ -2158,7 +2114,8 @@ R operator|(Optional<T>&& opt, UnwrapOr<U>&& fallback) {
return std::move(fallback.value()); return std::move(fallback.value());
} }
template <class T, template <
class T,
class U, class U,
class R = typename std::enable_if< class R = typename std::enable_if<
!std::is_same<T, U>::value, !std::is_same<T, U>::value,
...@@ -2170,7 +2127,8 @@ R operator|(const Optional<T>& opt, UnwrapOr<U>&& fallback) { ...@@ -2170,7 +2127,8 @@ R operator|(const Optional<T>& opt, UnwrapOr<U>&& fallback) {
return std::move(fallback.value()); return std::move(fallback.value());
} }
template <class T, template <
class T,
class U, class U,
class R = typename std::enable_if< class R = typename std::enable_if<
!std::is_same<T, U>::value, !std::is_same<T, U>::value,
...@@ -2182,7 +2140,8 @@ R operator|(Optional<T>&& opt, const UnwrapOr<U>& fallback) { ...@@ -2182,7 +2140,8 @@ R operator|(Optional<T>&& opt, const UnwrapOr<U>& fallback) {
return fallback.value(); return fallback.value();
} }
template <class T, template <
class T,
class U, class U,
class R = typename std::enable_if< class R = typename std::enable_if<
!std::is_same<T, U>::value, !std::is_same<T, U>::value,
......
...@@ -85,8 +85,7 @@ namespace gen { ...@@ -85,8 +85,7 @@ namespace gen {
class Less { class Less {
public: public:
template<class First, template <class First, class Second>
class Second>
auto operator()(const First& first, const Second& second) const -> auto operator()(const First& first, const Second& second) const ->
decltype(first < second) { decltype(first < second) {
return first < second; return first < second;
...@@ -95,26 +94,24 @@ public: ...@@ -95,26 +94,24 @@ public:
class Greater { class Greater {
public: public:
template<class First, template <class First, class Second>
class Second>
auto operator()(const First& first, const Second& second) const -> auto operator()(const First& first, const Second& second) const ->
decltype(first > second) { decltype(first > second) {
return first > second; return first > second;
} }
}; };
template<int n> template <int n>
class Get { class Get {
public: public:
template<class Value> template <class Value>
auto operator()(Value&& value) const -> auto operator()(Value&& value) const ->
decltype(std::get<n>(std::forward<Value>(value))) { decltype(std::get<n>(std::forward<Value>(value))) {
return std::get<n>(std::forward<Value>(value)); return std::get<n>(std::forward<Value>(value));
} }
}; };
template<class Class, template <class Class, class Result>
class Result>
class MemberFunction { class MemberFunction {
public: public:
typedef Result (Class::*MemberPtr)(); typedef Result (Class::*MemberPtr)();
...@@ -138,8 +135,7 @@ class MemberFunction { ...@@ -138,8 +135,7 @@ class MemberFunction {
} }
}; };
template<class Class, template <class Class, class Result>
class Result>
class ConstMemberFunction{ class ConstMemberFunction{
public: public:
typedef Result (Class::*MemberPtr)() const; typedef Result (Class::*MemberPtr)() const;
...@@ -159,8 +155,7 @@ class ConstMemberFunction{ ...@@ -159,8 +155,7 @@ class ConstMemberFunction{
} }
}; };
template<class Class, template <class Class, class FieldType>
class FieldType>
class Field { class Field {
public: public:
typedef FieldType (Class::*FieldPtr); typedef FieldType (Class::*FieldPtr);
...@@ -194,7 +189,7 @@ class Field { ...@@ -194,7 +189,7 @@ class Field {
class Move { class Move {
public: public:
template<class Value> template <class Value>
auto operator()(Value&& value) const -> auto operator()(Value&& value) const ->
decltype(std::move(std::forward<Value>(value))) { decltype(std::move(std::forward<Value>(value))) {
return std::move(std::forward<Value>(value)); return std::move(std::forward<Value>(value));
...@@ -252,18 +247,18 @@ class To<StringPiece> { ...@@ -252,18 +247,18 @@ class To<StringPiece> {
} }
}; };
template<class Key, class Value> template <class Key, class Value>
class Group; class Group;
namespace detail { namespace detail {
template<class Self> template <class Self>
struct FBounded; struct FBounded;
/* /*
* Type Traits * Type Traits
*/ */
template<class Container> template <class Container>
struct ValueTypeOfRange { struct ValueTypeOfRange {
public: public:
using RefType = decltype(*std::begin(std::declval<Container&>())); using RefType = decltype(*std::begin(std::declval<Container&>()));
...@@ -274,15 +269,17 @@ struct ValueTypeOfRange { ...@@ -274,15 +269,17 @@ struct ValueTypeOfRange {
/* /*
* Sources * Sources
*/ */
template<class Container, template <
class Container,
class Value = typename ValueTypeOfRange<Container>::RefType> class Value = typename ValueTypeOfRange<Container>::RefType>
class ReferencedSource; class ReferencedSource;
template<class Value, template <
class Value,
class Container = std::vector<typename std::decay<Value>::type>> class Container = std::vector<typename std::decay<Value>::type>>
class CopiedSource; class CopiedSource;
template<class Value, class SequenceImpl> template <class Value, class SequenceImpl>
class Sequence; class Sequence;
template <class Value> template <class Value>
...@@ -300,52 +297,52 @@ class SeqWithStepImpl; ...@@ -300,52 +297,52 @@ class SeqWithStepImpl;
template <class Value> template <class Value>
class InfiniteImpl; class InfiniteImpl;
template<class Value, class Source> template <class Value, class Source>
class Yield; class Yield;
template<class Value> template <class Value>
class Empty; class Empty;
template<class Value> template <class Value>
class SingleReference; class SingleReference;
template<class Value> template <class Value>
class SingleCopy; class SingleCopy;
/* /*
* Operators * Operators
*/ */
template<class Predicate> template <class Predicate>
class Map; class Map;
template<class Predicate> template <class Predicate>
class Filter; class Filter;
template<class Predicate> template <class Predicate>
class Until; class Until;
class Take; class Take;
class Stride; class Stride;
template<class Rand> template <class Rand>
class Sample; class Sample;
class Skip; class Skip;
template<class Selector, class Comparer = Less> template <class Selector, class Comparer = Less>
class Order; class Order;
template<class Selector> template <class Selector>
class GroupBy; class GroupBy;
template<class Selector> template <class Selector>
class Distinct; class Distinct;
template<class Operators> template <class Operators>
class Composer; class Composer;
template<class Expected> template <class Expected>
class TypeAssertion; class TypeAssertion;
class Concat; class Concat;
...@@ -364,8 +361,7 @@ class Indirect; ...@@ -364,8 +361,7 @@ class Indirect;
/* /*
* Sinks * Sinks
*/ */
template<class Seed, template <class Seed, class Fold>
class Fold>
class FoldLeft; class FoldLeft;
class First; class First;
...@@ -373,33 +369,32 @@ class First; ...@@ -373,33 +369,32 @@ class First;
template <bool result> template <bool result>
class IsEmpty; class IsEmpty;
template<class Reducer> template <class Reducer>
class Reduce; class Reduce;
class Sum; class Sum;
template<class Selector, template <class Selector, class Comparer>
class Comparer>
class Min; class Min;
template<class Container> template <class Container>
class Collect; class Collect;
template<template<class, class> class Collection = std::vector, template <
template<class> class Allocator = std::allocator> template <class, class> class Collection = std::vector,
template <class> class Allocator = std::allocator>
class CollectTemplate; class CollectTemplate;
template<class Collection> template <class Collection>
class Append; class Append;
template<class Value> template <class Value>
struct GeneratorBuilder; struct GeneratorBuilder;
template<class Needle> template <class Needle>
class Contains; class Contains;
template<class Exception, template <class Exception, class ErrorHandler>
class ErrorHandler>
class GuardImpl; class GuardImpl;
template <class T> template <class T>
...@@ -412,80 +407,88 @@ class Unwrap; ...@@ -412,80 +407,88 @@ class Unwrap;
/** /**
* Polymorphic wrapper * Polymorphic wrapper
**/ **/
template<class Value> template <class Value>
class VirtualGen; class VirtualGen;
/* /*
* Source Factories * Source Factories
*/ */
template<class Container, template <
class Container,
class From = detail::ReferencedSource<const Container>> class From = detail::ReferencedSource<const Container>>
From fromConst(const Container& source) { From fromConst(const Container& source) {
return From(&source); return From(&source);
} }
template<class Container, template <class Container, class From = detail::ReferencedSource<Container>>
class From = detail::ReferencedSource<Container>>
From from(Container& source) { From from(Container& source) {
return From(&source); return From(&source);
} }
template<class Container, template <
class Value = class Container,
typename detail::ValueTypeOfRange<Container>::StorageType, class Value = typename detail::ValueTypeOfRange<Container>::StorageType,
class CopyOf = detail::CopiedSource<Value>> class CopyOf = detail::CopiedSource<Value>>
CopyOf fromCopy(Container&& source) { CopyOf fromCopy(Container&& source) {
return CopyOf(std::forward<Container>(source)); return CopyOf(std::forward<Container>(source));
} }
template<class Value, template <class Value, class From = detail::CopiedSource<Value>>
class From = detail::CopiedSource<Value>>
From from(std::initializer_list<Value> source) { From from(std::initializer_list<Value> source) {
return From(source); return From(source);
} }
template<class Container, template <
class From = detail::CopiedSource<typename Container::value_type, class Container,
Container>> class From =
detail::CopiedSource<typename Container::value_type, Container>>
From from(Container&& source) { From from(Container&& source) {
return From(std::move(source)); return From(std::move(source));
} }
template<class Value, class Impl = detail::RangeImpl<Value>, template <
class Value,
class Impl = detail::RangeImpl<Value>,
class Gen = detail::Sequence<Value, Impl>> class Gen = detail::Sequence<Value, Impl>>
Gen range(Value begin, Value end) { Gen range(Value begin, Value end) {
return Gen{std::move(begin), Impl{std::move(end)}}; return Gen{std::move(begin), Impl{std::move(end)}};
} }
template<class Value, class Distance, template <
class Value,
class Distance,
class Impl = detail::RangeWithStepImpl<Value, Distance>, class Impl = detail::RangeWithStepImpl<Value, Distance>,
class Gen = detail::Sequence<Value, Impl>> class Gen = detail::Sequence<Value, Impl>>
Gen range(Value begin, Value end, Distance step) { Gen range(Value begin, Value end, Distance step) {
return Gen{std::move(begin), Impl{std::move(end), std::move(step)}}; return Gen{std::move(begin), Impl{std::move(end), std::move(step)}};
} }
template<class Value, class Impl = detail::SeqImpl<Value>, template <
class Value,
class Impl = detail::SeqImpl<Value>,
class Gen = detail::Sequence<Value, Impl>> class Gen = detail::Sequence<Value, Impl>>
Gen seq(Value first, Value last) { Gen seq(Value first, Value last) {
return Gen{std::move(first), Impl{std::move(last)}}; return Gen{std::move(first), Impl{std::move(last)}};
} }
template<class Value, class Distance, template <
class Value,
class Distance,
class Impl = detail::SeqWithStepImpl<Value, Distance>, class Impl = detail::SeqWithStepImpl<Value, Distance>,
class Gen = detail::Sequence<Value, Impl>> class Gen = detail::Sequence<Value, Impl>>
Gen seq(Value first, Value last, Distance step) { Gen seq(Value first, Value last, Distance step) {
return Gen{std::move(first), Impl{std::move(last), std::move(step)}}; return Gen{std::move(first), Impl{std::move(last), std::move(step)}};
} }
template<class Value, class Impl = detail::InfiniteImpl<Value>, template <
class Value,
class Impl = detail::InfiniteImpl<Value>,
class Gen = detail::Sequence<Value, Impl>> class Gen = detail::Sequence<Value, Impl>>
Gen seq(Value first) { Gen seq(Value first) {
return Gen{std::move(first), Impl{}}; return Gen{std::move(first), Impl{}};
} }
template<class Value, template <class Value, class Source, class Yield = detail::Yield<Value, Source>>
class Source,
class Yield = detail::Yield<Value, Source>>
Yield generator(Source&& source) { Yield generator(Source&& source) {
return Yield(std::forward<Source>(source)); return Yield(std::forward<Source>(source));
} }
...@@ -520,14 +523,12 @@ Just just(Value&& value) { ...@@ -520,14 +523,12 @@ Just just(Value&& value) {
/* /*
* Operator Factories * Operator Factories
*/ */
template<class Predicate, template <class Predicate, class Map = detail::Map<Predicate>>
class Map = detail::Map<Predicate>>
Map mapped(Predicate pred = Predicate()) { Map mapped(Predicate pred = Predicate()) {
return Map(std::move(pred)); return Map(std::move(pred));
} }
template<class Predicate, template <class Predicate, class Map = detail::Map<Predicate>>
class Map = detail::Map<Predicate>>
Map map(Predicate pred = Predicate()) { Map map(Predicate pred = Predicate()) {
return Map(std::move(pred)); return Map(std::move(pred));
} }
...@@ -541,8 +542,7 @@ Map map(Predicate pred = Predicate()) { ...@@ -541,8 +542,7 @@ Map map(Predicate pred = Predicate()) {
* | mapOp(filter(sampleTest) | count) * | mapOp(filter(sampleTest) | count)
* | sum; * | sum;
*/ */
template<class Operator, template <class Operator, class Map = detail::Map<detail::Composer<Operator>>>
class Map = detail::Map<detail::Composer<Operator>>>
Map mapOp(Operator op) { Map mapOp(Operator op) {
return Map(detail::Composer<Operator>(std::move(op))); return Map(detail::Composer<Operator>(std::move(op)));
} }
...@@ -569,19 +569,22 @@ enum MemberType { ...@@ -569,19 +569,22 @@ enum MemberType {
* assignment and comparisons don't work properly without being pulled out * assignment and comparisons don't work properly without being pulled out
* of the template declaration * of the template declaration
*/ */
template <MemberType Constness> struct ExprIsConst { template <MemberType Constness>
struct ExprIsConst {
enum { enum {
value = Constness == Const value = Constness == Const
}; };
}; };
template <MemberType Constness> struct ExprIsMutable { template <MemberType Constness>
struct ExprIsMutable {
enum { enum {
value = Constness == Mutable value = Constness == Mutable
}; };
}; };
template<MemberType Constness = Const, template <
MemberType Constness = Const,
class Class, class Class,
class Return, class Return,
class Mem = ConstMemberFunction<Class, Return>, class Mem = ConstMemberFunction<Class, Return>,
...@@ -591,7 +594,8 @@ member(Return (Class::*member)() const) { ...@@ -591,7 +594,8 @@ member(Return (Class::*member)() const) {
return Map(Mem(member)); return Map(Mem(member));
} }
template<MemberType Constness = Mutable, template <
MemberType Constness = Mutable,
class Class, class Class,
class Return, class Return,
class Mem = MemberFunction<Class, Return>, class Mem = MemberFunction<Class, Return>,
...@@ -616,7 +620,8 @@ member(Return (Class::*member)()) { ...@@ -616,7 +620,8 @@ member(Return (Class::*member)()) {
* | field(&Item::name) * | field(&Item::name)
* | as<vector>(); * | as<vector>();
*/ */
template<class Class, template <
class Class,
class FieldType, class FieldType,
class Field = Field<Class, FieldType>, class Field = Field<Class, FieldType>,
class Map = detail::Map<Field>> class Map = detail::Map<Field>>
...@@ -624,19 +629,18 @@ Map field(FieldType Class::*field) { ...@@ -624,19 +629,18 @@ Map field(FieldType Class::*field) {
return Map(Field(field)); return Map(Field(field));
} }
template <class Predicate = Identity, template <class Predicate = Identity, class Filter = detail::Filter<Predicate>>
class Filter = detail::Filter<Predicate>>
Filter filter(Predicate pred = Predicate()) { Filter filter(Predicate pred = Predicate()) {
return Filter(std::move(pred)); return Filter(std::move(pred));
} }
template<class Predicate, template <class Predicate, class Until = detail::Until<Predicate>>
class Until = detail::Until<Predicate>>
Until until(Predicate pred = Predicate()) { Until until(Predicate pred = Predicate()) {
return Until(std::move(pred)); return Until(std::move(pred));
} }
template<class Selector = Identity, template <
class Selector = Identity,
class Comparer = Less, class Comparer = Less,
class Order = detail::Order<Selector, Comparer>> class Order = detail::Order<Selector, Comparer>>
Order orderBy(Selector selector = Selector(), Order orderBy(Selector selector = Selector(),
...@@ -645,45 +649,43 @@ Order orderBy(Selector selector = Selector(), ...@@ -645,45 +649,43 @@ Order orderBy(Selector selector = Selector(),
std::move(comparer)); std::move(comparer));
} }
template<class Selector = Identity, template <
class Selector = Identity,
class Order = detail::Order<Selector, Greater>> class Order = detail::Order<Selector, Greater>>
Order orderByDescending(Selector selector = Selector()) { Order orderByDescending(Selector selector = Selector()) {
return Order(std::move(selector)); return Order(std::move(selector));
} }
template <class Selector = Identity, template <class Selector = Identity, class GroupBy = detail::GroupBy<Selector>>
class GroupBy = detail::GroupBy<Selector>>
GroupBy groupBy(Selector selector = Selector()) { GroupBy groupBy(Selector selector = Selector()) {
return GroupBy(std::move(selector)); return GroupBy(std::move(selector));
} }
template<class Selector = Identity, template <
class Selector = Identity,
class Distinct = detail::Distinct<Selector>> class Distinct = detail::Distinct<Selector>>
Distinct distinctBy(Selector selector = Selector()) { Distinct distinctBy(Selector selector = Selector()) {
return Distinct(std::move(selector)); return Distinct(std::move(selector));
} }
template<int n, template <int n, class Get = detail::Map<Get<n>>>
class Get = detail::Map<Get<n>>>
Get get() { Get get() {
return Get(); return Get();
} }
// construct Dest from each value // construct Dest from each value
template <class Dest, template <class Dest, class Cast = detail::Map<Cast<Dest>>>
class Cast = detail::Map<Cast<Dest>>>
Cast eachAs() { Cast eachAs() {
return Cast(); return Cast();
} }
// call folly::to on each value // call folly::to on each value
template <class Dest, template <class Dest, class To = detail::Map<To<Dest>>>
class To = detail::Map<To<Dest>>>
To eachTo() { To eachTo() {
return To(); return To();
} }
template<class Value> template <class Value>
detail::TypeAssertion<Value> assert_type() { detail::TypeAssertion<Value> assert_type() {
return {}; return {};
} }
...@@ -712,7 +714,8 @@ detail::TypeAssertion<Value> assert_type() { ...@@ -712,7 +714,8 @@ detail::TypeAssertion<Value> assert_type() {
* from(source) | any(pred) == from(source) | filter(pred) | notEmpty * from(source) | any(pred) == from(source) | filter(pred) | notEmpty
*/ */
template <class Predicate = Identity, template <
class Predicate = Identity,
class Filter = detail::Filter<Predicate>, class Filter = detail::Filter<Predicate>,
class NotEmpty = detail::IsEmpty<false>, class NotEmpty = detail::IsEmpty<false>,
class Composed = detail::Composed<Filter, NotEmpty>> class Composed = detail::Composed<Filter, NotEmpty>>
...@@ -740,7 +743,8 @@ Composed any(Predicate pred = Predicate()) { ...@@ -740,7 +743,8 @@ Composed any(Predicate pred = Predicate()) {
* from(source) | all(pred) == from(source) | filter(negate(pred)) | isEmpty * from(source) | all(pred) == from(source) | filter(negate(pred)) | isEmpty
*/ */
template <class Predicate = Identity, template <
class Predicate = Identity,
class Filter = detail::Filter<Negate<Predicate>>, class Filter = detail::Filter<Negate<Predicate>>,
class IsEmpty = detail::IsEmpty<true>, class IsEmpty = detail::IsEmpty<true>,
class Composed = detail::Composed<Filter, IsEmpty>> class Composed = detail::Composed<Filter, IsEmpty>>
...@@ -748,69 +752,64 @@ Composed all(Predicate pred = Predicate()) { ...@@ -748,69 +752,64 @@ Composed all(Predicate pred = Predicate()) {
return Composed(Filter(std::move(negate(pred))), IsEmpty()); return Composed(Filter(std::move(negate(pred))), IsEmpty());
} }
template<class Seed, template <class Seed, class Fold, class FoldLeft = detail::FoldLeft<Seed, Fold>>
class Fold,
class FoldLeft = detail::FoldLeft<Seed, Fold>>
FoldLeft foldl(Seed seed = Seed(), FoldLeft foldl(Seed seed = Seed(),
Fold fold = Fold()) { Fold fold = Fold()) {
return FoldLeft(std::move(seed), return FoldLeft(std::move(seed),
std::move(fold)); std::move(fold));
} }
template<class Reducer, template <class Reducer, class Reduce = detail::Reduce<Reducer>>
class Reduce = detail::Reduce<Reducer>>
Reduce reduce(Reducer reducer = Reducer()) { Reduce reduce(Reducer reducer = Reducer()) {
return Reduce(std::move(reducer)); return Reduce(std::move(reducer));
} }
template<class Selector = Identity, template <class Selector = Identity, class Min = detail::Min<Selector, Less>>
class Min = detail::Min<Selector, Less>>
Min minBy(Selector selector = Selector()) { Min minBy(Selector selector = Selector()) {
return Min(std::move(selector)); return Min(std::move(selector));
} }
template<class Selector, template <class Selector, class MaxBy = detail::Min<Selector, Greater>>
class MaxBy = detail::Min<Selector, Greater>>
MaxBy maxBy(Selector selector = Selector()) { MaxBy maxBy(Selector selector = Selector()) {
return MaxBy(std::move(selector)); return MaxBy(std::move(selector));
} }
template<class Collection, template <class Collection, class Collect = detail::Collect<Collection>>
class Collect = detail::Collect<Collection>>
Collect as() { Collect as() {
return Collect(); return Collect();
} }
template<template<class, class> class Container = std::vector, template <
template<class> class Allocator = std::allocator, template <class, class> class Container = std::vector,
template <class> class Allocator = std::allocator,
class Collect = detail::CollectTemplate<Container, Allocator>> class Collect = detail::CollectTemplate<Container, Allocator>>
Collect as() { Collect as() {
return Collect(); return Collect();
} }
template<class Collection, template <class Collection, class Append = detail::Append<Collection>>
class Append = detail::Append<Collection>>
Append appendTo(Collection& collection) { Append appendTo(Collection& collection) {
return Append(&collection); return Append(&collection);
} }
template<class Needle, template <
class Needle,
class Contains = detail::Contains<typename std::decay<Needle>::type>> class Contains = detail::Contains<typename std::decay<Needle>::type>>
Contains contains(Needle&& needle) { Contains contains(Needle&& needle) {
return Contains(std::forward<Needle>(needle)); return Contains(std::forward<Needle>(needle));
} }
template<class Exception, template <
class Exception,
class ErrorHandler, class ErrorHandler,
class GuardImpl = class GuardImpl =
detail::GuardImpl< detail::GuardImpl<Exception, typename std::decay<ErrorHandler>::type>>
Exception,
typename std::decay<ErrorHandler>::type>>
GuardImpl guard(ErrorHandler&& handler) { GuardImpl guard(ErrorHandler&& handler) {
return GuardImpl(std::forward<ErrorHandler>(handler)); return GuardImpl(std::forward<ErrorHandler>(handler));
} }
template<class Fallback, template <
class Fallback,
class UnwrapOr = detail::UnwrapOr<typename std::decay<Fallback>::type>> class UnwrapOr = detail::UnwrapOr<typename std::decay<Fallback>::type>>
UnwrapOr unwrapOr(Fallback&& fallback) { UnwrapOr unwrapOr(Fallback&& fallback) {
return UnwrapOr(std::forward<Fallback>(fallback)); return UnwrapOr(std::forward<Fallback>(fallback));
......
...@@ -33,7 +33,7 @@ namespace detail { ...@@ -33,7 +33,7 @@ namespace detail {
* Alternate values from a sequence with values from a sequence container. * Alternate values from a sequence with values from a sequence container.
* Stops once we run out of values from either source. * Stops once we run out of values from either source.
*/ */
template<class Container> template <class Container>
class Interleave : public Operator<Interleave<Container>> { class Interleave : public Operator<Interleave<Container>> {
// see comment about copies in CopiedSource // see comment about copies in CopiedSource
const std::shared_ptr<const Container> container_; const std::shared_ptr<const Container> container_;
...@@ -41,8 +41,7 @@ class Interleave : public Operator<Interleave<Container>> { ...@@ -41,8 +41,7 @@ class Interleave : public Operator<Interleave<Container>> {
explicit Interleave(Container container) explicit Interleave(Container container)
: container_(new Container(std::move(container))) {} : container_(new Container(std::move(container))) {}
template<class Value, template <class Value, class Source>
class Source>
class Generator : public GenImpl<Value, Generator<Value, Source>> { class Generator : public GenImpl<Value, Generator<Value, Source>> {
Source source_; Source source_;
const std::shared_ptr<const Container> container_; const std::shared_ptr<const Container> container_;
...@@ -56,7 +55,7 @@ class Interleave : public Operator<Interleave<Container>> { ...@@ -56,7 +55,7 @@ class Interleave : public Operator<Interleave<Container>> {
: source_(std::move(source)), : source_(std::move(source)),
container_(container) { } container_(container) { }
template<class Handler> template <class Handler>
bool apply(Handler&& handler) const { bool apply(Handler&& handler) const {
auto iter = container_->begin(); auto iter = container_->begin();
return source_.apply([&](const Value& value) -> bool { return source_.apply([&](const Value& value) -> bool {
...@@ -75,16 +74,12 @@ class Interleave : public Operator<Interleave<Container>> { ...@@ -75,16 +74,12 @@ class Interleave : public Operator<Interleave<Container>> {
} }
}; };
template<class Value2, template <class Value2, class Source, class Gen = Generator<Value2, Source>>
class Source,
class Gen = Generator<Value2,Source>>
Gen compose(GenImpl<Value2, Source>&& source) const { Gen compose(GenImpl<Value2, Source>&& source) const {
return Gen(std::move(source.self()), container_); return Gen(std::move(source.self()), container_);
} }
template<class Value2, template <class Value2, class Source, class Gen = Generator<Value2, Source>>
class Source,
class Gen = Generator<Value2,Source>>
Gen compose(const GenImpl<Value2, Source>& source) const { Gen compose(const GenImpl<Value2, Source>& source) const {
return Gen(source.self(), container_); return Gen(source.self(), container_);
} }
...@@ -97,7 +92,7 @@ class Interleave : public Operator<Interleave<Container>> { ...@@ -97,7 +92,7 @@ class Interleave : public Operator<Interleave<Container>> {
* them into a tuple. * them into a tuple.
* *
*/ */
template<class Container> template <class Container>
class Zip : public Operator<Zip<Container>> { class Zip : public Operator<Zip<Container>> {
// see comment about copies in CopiedSource // see comment about copies in CopiedSource
const std::shared_ptr<const Container> container_; const std::shared_ptr<const Container> container_;
...@@ -105,10 +100,12 @@ class Zip : public Operator<Zip<Container>> { ...@@ -105,10 +100,12 @@ class Zip : public Operator<Zip<Container>> {
explicit Zip(Container container) explicit Zip(Container container)
: container_(new Container(std::move(container))) {} : container_(new Container(std::move(container))) {}
template<class Value1, template <
class Value1,
class Source, class Source,
class Value2 = decltype(*std::begin(*container_)), class Value2 = decltype(*std::begin(*container_)),
class Result = std::tuple<typename std::decay<Value1>::type, class Result = std::tuple<
typename std::decay<Value1>::type,
typename std::decay<Value2>::type>> typename std::decay<Value2>::type>>
class Generator : public GenImpl<Result, class Generator : public GenImpl<Result,
Generator<Value1,Source,Value2,Result>> { Generator<Value1,Source,Value2,Result>> {
...@@ -120,7 +117,7 @@ class Zip : public Operator<Zip<Container>> { ...@@ -120,7 +117,7 @@ class Zip : public Operator<Zip<Container>> {
: source_(std::move(source)), : source_(std::move(source)),
container_(container) { } container_(container) { }
template<class Handler> template <class Handler>
bool apply(Handler&& handler) const { bool apply(Handler&& handler) const {
auto iter = container_->begin(); auto iter = container_->begin();
return (source_.apply([&](Value1 value) -> bool { return (source_.apply([&](Value1 value) -> bool {
...@@ -136,30 +133,24 @@ class Zip : public Operator<Zip<Container>> { ...@@ -136,30 +133,24 @@ class Zip : public Operator<Zip<Container>> {
} }
}; };
template<class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(GenImpl<Value, Source>&& source) const { Gen compose(GenImpl<Value, Source>&& source) const {
return Gen(std::move(source.self()), container_); return Gen(std::move(source.self()), container_);
} }
template<class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(const GenImpl<Value, Source>& source) const { Gen compose(const GenImpl<Value, Source>& source) const {
return Gen(source.self(), container_); return Gen(source.self(), container_);
} }
}; };
template<class... Types1, template <class... Types1, class... Types2>
class... Types2>
auto add_to_tuple(std::tuple<Types1...> t1, std::tuple<Types2...> t2) -> auto add_to_tuple(std::tuple<Types1...> t1, std::tuple<Types2...> t2) ->
std::tuple<Types1..., Types2...> { std::tuple<Types1..., Types2...> {
return std::tuple_cat(std::move(t1), std::move(t2)); return std::tuple_cat(std::move(t1), std::move(t2));
} }
template<class... Types1, template <class... Types1, class Type2>
class Type2>
auto add_to_tuple(std::tuple<Types1...> t1, Type2&& t2) -> auto add_to_tuple(std::tuple<Types1...> t1, Type2&& t2) ->
decltype(std::tuple_cat(std::move(t1), decltype(std::tuple_cat(std::move(t1),
std::make_tuple(std::forward<Type2>(t2)))) { std::make_tuple(std::forward<Type2>(t2)))) {
...@@ -167,8 +158,7 @@ decltype(std::tuple_cat(std::move(t1), ...@@ -167,8 +158,7 @@ decltype(std::tuple_cat(std::move(t1),
std::make_tuple(std::forward<Type2>(t2))); std::make_tuple(std::forward<Type2>(t2)));
} }
template<class Type1, template <class Type1, class... Types2>
class... Types2>
auto add_to_tuple(Type1&& t1, std::tuple<Types2...> t2) -> auto add_to_tuple(Type1&& t1, std::tuple<Types2...> t2) ->
decltype(std::tuple_cat(std::make_tuple(std::forward<Type1>(t1)), decltype(std::tuple_cat(std::make_tuple(std::forward<Type1>(t1)),
std::move(t2))) { std::move(t2))) {
...@@ -176,8 +166,7 @@ decltype(std::tuple_cat(std::make_tuple(std::forward<Type1>(t1)), ...@@ -176,8 +166,7 @@ decltype(std::tuple_cat(std::make_tuple(std::forward<Type1>(t1)),
std::move(t2)); std::move(t2));
} }
template<class Type1, template <class Type1, class Type2>
class Type2>
auto add_to_tuple(Type1&& t1, Type2&& t2) -> auto add_to_tuple(Type1&& t1, Type2&& t2) ->
decltype(std::make_tuple(std::forward<Type1>(t1), decltype(std::make_tuple(std::forward<Type1>(t1),
std::forward<Type2>(t2))) { std::forward<Type2>(t2))) {
...@@ -188,7 +177,7 @@ decltype(std::make_tuple(std::forward<Type1>(t1), ...@@ -188,7 +177,7 @@ decltype(std::make_tuple(std::forward<Type1>(t1),
// Merges a 2-tuple into a single tuple (get<0> could already be a tuple) // Merges a 2-tuple into a single tuple (get<0> could already be a tuple)
class MergeTuples { class MergeTuples {
public: public:
template<class Tuple> template <class Tuple>
auto operator()(Tuple&& value) const -> auto operator()(Tuple&& value) const ->
decltype(add_to_tuple(std::get<0>(std::forward<Tuple>(value)), decltype(add_to_tuple(std::get<0>(std::forward<Tuple>(value)),
std::get<1>(std::forward<Tuple>(value)))) { std::get<1>(std::forward<Tuple>(value)))) {
...@@ -205,7 +194,8 @@ class MergeTuples { ...@@ -205,7 +194,8 @@ class MergeTuples {
// TODO(mcurtiss): support zip() for N>1 operands. Because of variadic problems, // TODO(mcurtiss): support zip() for N>1 operands. Because of variadic problems,
// this might not be easily possible until gcc4.8 is available. // this might not be easily possible until gcc4.8 is available.
template<class Source, template <
class Source,
class Zip = detail::Zip<typename std::decay<Source>::type>> class Zip = detail::Zip<typename std::decay<Source>::type>>
Zip zip(Source&& source) { Zip zip(Source&& source) {
return Zip(std::forward<Source>(source)); return Zip(std::forward<Source>(source));
......
...@@ -23,15 +23,16 @@ namespace folly { ...@@ -23,15 +23,16 @@ namespace folly {
namespace gen { namespace gen {
namespace detail { namespace detail {
template<class Container> template <class Container>
class Interleave; class Interleave;
template<class Container> template <class Container>
class Zip; class Zip;
} // namespace detail } // namespace detail
template<class Source2, template <
class Source2,
class Source2Decayed = typename std::decay<Source2>::type, class Source2Decayed = typename std::decay<Source2>::type,
class Interleave = detail::Interleave<Source2Decayed>> class Interleave = detail::Interleave<Source2Decayed>>
Interleave interleave(Source2&& source2) { Interleave interleave(Source2&& source2) {
......
...@@ -37,16 +37,15 @@ namespace gen { ...@@ -37,16 +37,15 @@ namespace gen {
* Usage: * Usage:
* IsCompatibleSignature<FunctorType, bool(int, float)>::value * IsCompatibleSignature<FunctorType, bool(int, float)>::value
*/ */
template<class Candidate, class Expected> template <class Candidate, class Expected>
class IsCompatibleSignature { class IsCompatibleSignature {
static constexpr bool value = false; static constexpr bool value = false;
}; };
template<class Candidate, template <class Candidate, class ExpectedReturn, class... ArgTypes>
class ExpectedReturn,
class... ArgTypes>
class IsCompatibleSignature<Candidate, ExpectedReturn(ArgTypes...)> { class IsCompatibleSignature<Candidate, ExpectedReturn(ArgTypes...)> {
template<class F, template <
class F,
class ActualReturn = class ActualReturn =
decltype(std::declval<F>()(std::declval<ArgTypes>()...)), decltype(std::declval<F>()(std::declval<ArgTypes>()...)),
bool good = std::is_same<ExpectedReturn, ActualReturn>::value> bool good = std::is_same<ExpectedReturn, ActualReturn>::value>
...@@ -54,7 +53,7 @@ class IsCompatibleSignature<Candidate, ExpectedReturn(ArgTypes...)> { ...@@ -54,7 +53,7 @@ class IsCompatibleSignature<Candidate, ExpectedReturn(ArgTypes...)> {
return good; return good;
} }
template<class F> template <class F>
static constexpr bool testArgs(...) { static constexpr bool testArgs(...) {
return false; return false;
} }
...@@ -66,7 +65,7 @@ public: ...@@ -66,7 +65,7 @@ public:
* FBounded - Helper type for the curiously recurring template pattern, used * FBounded - Helper type for the curiously recurring template pattern, used
* heavily here to enable inlining and obviate virtual functions * heavily here to enable inlining and obviate virtual functions
*/ */
template<class Self> template <class Self>
struct FBounded { struct FBounded {
const Self& self() const { const Self& self() const {
return *static_cast<const Self*>(this); return *static_cast<const Self*>(this);
...@@ -82,16 +81,14 @@ struct FBounded { ...@@ -82,16 +81,14 @@ struct FBounded {
* generator. All operators implement a method compose(), which takes a * generator. All operators implement a method compose(), which takes a
* generator and produces an output generator. * generator and produces an output generator.
*/ */
template<class Self> template <class Self>
class Operator : public FBounded<Self> { class Operator : public FBounded<Self> {
public: public:
/** /**
* compose() - Must be implemented by child class to compose a new Generator * compose() - Must be implemented by child class to compose a new Generator
* out of a given generator. This function left intentionally unimplemented. * out of a given generator. This function left intentionally unimplemented.
*/ */
template<class Source, template <class Source, class Value, class ResultGen = void>
class Value,
class ResultGen = void>
ResultGen compose(const GenImpl<Value, Source>& source) const; ResultGen compose(const GenImpl<Value, Source>& source) const;
protected: protected:
...@@ -106,7 +103,8 @@ class Operator : public FBounded<Self> { ...@@ -106,7 +103,8 @@ class Operator : public FBounded<Self> {
* operator|() - For composing two operators without binding it to a * operator|() - For composing two operators without binding it to a
* particular generator. * particular generator.
*/ */
template<class Left, template <
class Left,
class Right, class Right,
class Composed = detail::Composed<Left, Right>> class Composed = detail::Composed<Left, Right>>
Composed operator|(const Operator<Left>& left, Composed operator|(const Operator<Left>& left,
...@@ -114,7 +112,8 @@ Composed operator|(const Operator<Left>& left, ...@@ -114,7 +112,8 @@ Composed operator|(const Operator<Left>& left,
return Composed(left.self(), right.self()); return Composed(left.self(), right.self());
} }
template<class Left, template <
class Left,
class Right, class Right,
class Composed = detail::Composed<Left, Right>> class Composed = detail::Composed<Left, Right>>
Composed operator|(const Operator<Left>& left, Composed operator|(const Operator<Left>& left,
...@@ -122,7 +121,8 @@ Composed operator|(const Operator<Left>& left, ...@@ -122,7 +121,8 @@ Composed operator|(const Operator<Left>& left,
return Composed(left.self(), std::move(right.self())); return Composed(left.self(), std::move(right.self()));
} }
template<class Left, template <
class Left,
class Right, class Right,
class Composed = detail::Composed<Left, Right>> class Composed = detail::Composed<Left, Right>>
Composed operator|(Operator<Left>&& left, Composed operator|(Operator<Left>&& left,
...@@ -130,7 +130,8 @@ Composed operator|(Operator<Left>&& left, ...@@ -130,7 +130,8 @@ Composed operator|(Operator<Left>&& left,
return Composed(std::move(left.self()), right.self()); return Composed(std::move(left.self()), right.self());
} }
template<class Left, template <
class Left,
class Right, class Right,
class Composed = detail::Composed<Left, Right>> class Composed = detail::Composed<Left, Right>>
Composed operator|(Operator<Left>&& left, Composed operator|(Operator<Left>&& left,
...@@ -144,8 +145,7 @@ Composed operator|(Operator<Left>&& left, ...@@ -144,8 +145,7 @@ Composed operator|(Operator<Left>&& left,
* implement apply(). foreach() may also be implemented to special case the * implement apply(). foreach() may also be implemented to special case the
* condition where the entire sequence is consumed. * condition where the entire sequence is consumed.
*/ */
template<class Value, template <class Value, class Self>
class Self>
class GenImpl : public FBounded<Self> { class GenImpl : public FBounded<Self> {
protected: protected:
// To prevent slicing // To prevent slicing
...@@ -166,13 +166,13 @@ class GenImpl : public FBounded<Self> { ...@@ -166,13 +166,13 @@ class GenImpl : public FBounded<Self> {
* the handler returning false), as 'Chain' uses the return value of apply to * the handler returning false), as 'Chain' uses the return value of apply to
* determine if it should process the second object in its chain. * determine if it should process the second object in its chain.
*/ */
template<class Handler> template <class Handler>
bool apply(Handler&& handler) const; bool apply(Handler&& handler) const;
/** /**
* foreach() - Send all values produced by this generator to given lambda. * foreach() - Send all values produced by this generator to given lambda.
*/ */
template<class Body> template <class Body>
void foreach(Body&& body) const { void foreach(Body&& body) const {
this->self().apply([&](Value value) -> bool { this->self().apply([&](Value value) -> bool {
static_assert(!infinite, "Cannot call foreach on infinite GenImpl"); static_assert(!infinite, "Cannot call foreach on infinite GenImpl");
...@@ -194,7 +194,8 @@ class GenImpl : public FBounded<Self> { ...@@ -194,7 +194,8 @@ class GenImpl : public FBounded<Self> {
static constexpr bool infinite = false; static constexpr bool infinite = false;
}; };
template<class LeftValue, template <
class LeftValue,
class Left, class Left,
class RightValue, class RightValue,
class Right, class Right,
...@@ -207,7 +208,8 @@ Chain operator+(const GenImpl<LeftValue, Left>& left, ...@@ -207,7 +208,8 @@ Chain operator+(const GenImpl<LeftValue, Left>& left,
return Chain(left.self(), right.self()); return Chain(left.self(), right.self());
} }
template<class LeftValue, template <
class LeftValue,
class Left, class Left,
class RightValue, class RightValue,
class Right, class Right,
...@@ -220,7 +222,8 @@ Chain operator+(const GenImpl<LeftValue, Left>& left, ...@@ -220,7 +222,8 @@ Chain operator+(const GenImpl<LeftValue, Left>& left,
return Chain(left.self(), std::move(right.self())); return Chain(left.self(), std::move(right.self()));
} }
template<class LeftValue, template <
class LeftValue,
class Left, class Left,
class RightValue, class RightValue,
class Right, class Right,
...@@ -233,7 +236,8 @@ Chain operator+(GenImpl<LeftValue, Left>&& left, ...@@ -233,7 +236,8 @@ Chain operator+(GenImpl<LeftValue, Left>&& left,
return Chain(std::move(left.self()), right.self()); return Chain(std::move(left.self()), right.self());
} }
template<class LeftValue, template <
class LeftValue,
class Left, class Left,
class RightValue, class RightValue,
class Right, class Right,
...@@ -250,9 +254,7 @@ Chain operator+(GenImpl<LeftValue, Left>&& left, ...@@ -250,9 +254,7 @@ Chain operator+(GenImpl<LeftValue, Left>&& left,
* operator|() which enables foreach-like usage: * operator|() which enables foreach-like usage:
* gen | [](Value v) -> void {...}; * gen | [](Value v) -> void {...};
*/ */
template<class Value, template <class Value, class Gen, class Handler>
class Gen,
class Handler>
typename std::enable_if< typename std::enable_if<
IsCompatibleSignature<Handler, void(Value)>::value>::type IsCompatibleSignature<Handler, void(Value)>::value>::type
operator|(const GenImpl<Value, Gen>& gen, Handler&& handler) { operator|(const GenImpl<Value, Gen>& gen, Handler&& handler) {
...@@ -265,9 +267,7 @@ operator|(const GenImpl<Value, Gen>& gen, Handler&& handler) { ...@@ -265,9 +267,7 @@ operator|(const GenImpl<Value, Gen>& gen, Handler&& handler) {
* operator|() which enables foreach-like usage with 'break' support: * operator|() which enables foreach-like usage with 'break' support:
* gen | [](Value v) -> bool { return shouldContinue(); }; * gen | [](Value v) -> bool { return shouldContinue(); };
*/ */
template<class Value, template <class Value, class Gen, class Handler>
class Gen,
class Handler>
typename std::enable_if< typename std::enable_if<
IsCompatibleSignature<Handler, bool(Value)>::value, bool>::type IsCompatibleSignature<Handler, bool(Value)>::value, bool>::type
operator|(const GenImpl<Value, Gen>& gen, Handler&& handler) { operator|(const GenImpl<Value, Gen>& gen, Handler&& handler) {
...@@ -279,17 +279,13 @@ operator|(const GenImpl<Value, Gen>& gen, Handler&& handler) { ...@@ -279,17 +279,13 @@ operator|(const GenImpl<Value, Gen>& gen, Handler&& handler) {
* adaptors: * adaptors:
* gen | map(square) | sum * gen | map(square) | sum
*/ */
template<class Value, template <class Value, class Gen, class Op>
class Gen,
class Op>
auto operator|(const GenImpl<Value, Gen>& gen, const Operator<Op>& op) -> auto operator|(const GenImpl<Value, Gen>& gen, const Operator<Op>& op) ->
decltype(op.self().compose(gen.self())) { decltype(op.self().compose(gen.self())) {
return op.self().compose(gen.self()); return op.self().compose(gen.self());
} }
template<class Value, template <class Value, class Gen, class Op>
class Gen,
class Op>
auto operator|(GenImpl<Value, Gen>&& gen, const Operator<Op>& op) -> auto operator|(GenImpl<Value, Gen>&& gen, const Operator<Op>& op) ->
decltype(op.self().compose(std::move(gen.self()))) { decltype(op.self().compose(std::move(gen.self()))) {
return op.self().compose(std::move(gen.self())); return op.self().compose(std::move(gen.self()));
...@@ -308,8 +304,7 @@ namespace detail { ...@@ -308,8 +304,7 @@ namespace detail {
* *
* auto valuesIncluded = from(optionals) | valuesOf | as<vector>(); * auto valuesIncluded = from(optionals) | valuesOf | as<vector>();
*/ */
template<class First, template <class First, class Second>
class Second>
class Composed : public Operator<Composed<First, Second>> { class Composed : public Operator<Composed<First, Second>> {
First first_; First first_;
Second second_; Second second_;
...@@ -320,22 +315,24 @@ class Composed : public Operator<Composed<First, Second>> { ...@@ -320,22 +315,24 @@ class Composed : public Operator<Composed<First, Second>> {
: first_(std::move(first)) : first_(std::move(first))
, second_(std::move(second)) {} , second_(std::move(second)) {}
template<class Source, template <
class Source,
class Value, class Value,
class FirstRet = decltype(std::declval<First>() class FirstRet =
.compose(std::declval<Source>())), decltype(std::declval<First>().compose(std::declval<Source>())),
class SecondRet = decltype(std::declval<Second>() class SecondRet =
.compose(std::declval<FirstRet>()))> decltype(std::declval<Second>().compose(std::declval<FirstRet>()))>
SecondRet compose(const GenImpl<Value, Source>& source) const { SecondRet compose(const GenImpl<Value, Source>& source) const {
return second_.compose(first_.compose(source.self())); return second_.compose(first_.compose(source.self()));
} }
template<class Source, template <
class Source,
class Value, class Value,
class FirstRet = decltype(std::declval<First>() class FirstRet =
.compose(std::declval<Source>())), decltype(std::declval<First>().compose(std::declval<Source>())),
class SecondRet = decltype(std::declval<Second>() class SecondRet =
.compose(std::declval<FirstRet>()))> decltype(std::declval<Second>().compose(std::declval<FirstRet>()))>
SecondRet compose(GenImpl<Value, Source>&& source) const { SecondRet compose(GenImpl<Value, Source>&& source) const {
return second_.compose(first_.compose(std::move(source.self()))); return second_.compose(first_.compose(std::move(source.self())));
} }
...@@ -349,7 +346,7 @@ class Composed : public Operator<Composed<First, Second>> { ...@@ -349,7 +346,7 @@ class Composed : public Operator<Composed<First, Second>> {
* auto nums = seq(1, 10) + seq(20, 30); * auto nums = seq(1, 10) + seq(20, 30);
* int total = nums | sum; * int total = nums | sum;
*/ */
template<class Value, class First, class Second> template <class Value, class First, class Second>
class Chain : public GenImpl<Value, class Chain : public GenImpl<Value,
Chain<Value, First, Second>> { Chain<Value, First, Second>> {
First first_; First first_;
...@@ -359,13 +356,13 @@ public: ...@@ -359,13 +356,13 @@ public:
: first_(std::move(first)) : first_(std::move(first))
, second_(std::move(second)) {} , second_(std::move(second)) {}
template<class Handler> template <class Handler>
bool apply(Handler&& handler) const { bool apply(Handler&& handler) const {
return first_.apply(std::forward<Handler>(handler)) return first_.apply(std::forward<Handler>(handler))
&& second_.apply(std::forward<Handler>(handler)); && second_.apply(std::forward<Handler>(handler));
} }
template<class Body> template <class Body>
void foreach(Body&& body) const { void foreach(Body&& body) const {
first_.foreach(std::forward<Body>(body)); first_.foreach(std::forward<Body>(body));
second_.foreach(std::forward<Body>(body)); second_.foreach(std::forward<Body>(body));
......
...@@ -20,21 +20,21 @@ ...@@ -20,21 +20,21 @@
namespace folly { namespace folly {
namespace gen { namespace gen {
template<class Value, class Self> template <class Value, class Self>
class GenImpl; class GenImpl;
template<class Self> template <class Self>
class Operator; class Operator;
namespace detail { namespace detail {
template<class Self> template <class Self>
struct FBounded; struct FBounded;
template<class First, class Second> template <class First, class Second>
class Composed; class Composed;
template<class Value, class First, class Second> template <class Value, class First, class Second>
class Chain; class Chain;
} // detail } // detail
......
...@@ -132,7 +132,8 @@ class Sub : public Operator<Sub<Sink>> { ...@@ -132,7 +132,8 @@ class Sub : public Operator<Sub<Sink>> {
public: public:
explicit Sub(Sink sink) : sink_(sink) {} explicit Sub(Sink sink) : sink_(sink) {}
template <class Value, template <
class Value,
class Source, class Source,
class Result = class Result =
decltype(std::declval<Sink>().compose(std::declval<Source>())), decltype(std::declval<Sink>().compose(std::declval<Source>())),
...@@ -150,7 +151,8 @@ class Parallel : public Operator<Parallel<Ops>> { ...@@ -150,7 +151,8 @@ class Parallel : public Operator<Parallel<Ops>> {
public: public:
Parallel(Ops ops, size_t threads) : ops_(std::move(ops)), threads_(threads) {} Parallel(Ops ops, size_t threads) : ops_(std::move(ops)), threads_(threads) {}
template <class Input, template <
class Input,
class Source, class Source,
class InputDecayed = typename std::decay<Input>::type, class InputDecayed = typename std::decay<Input>::type,
class Composed = class Composed =
......
...@@ -42,14 +42,16 @@ class ChunkedRangeSource; ...@@ -42,14 +42,16 @@ class ChunkedRangeSource;
* Especially for use with 'parallel()', chunked can be used to process values * Especially for use with 'parallel()', chunked can be used to process values
* from a persistent container in chunks larger than one value at a time. The * from a persistent container in chunks larger than one value at a time. The
* values produced are generators for slices of the input container. */ * values produced are generators for slices of the input container. */
template <class Container, template <
class Container,
class Iterator = typename Container::const_iterator, class Iterator = typename Container::const_iterator,
class Chunked = detail::ChunkedRangeSource<Iterator>> class Chunked = detail::ChunkedRangeSource<Iterator>>
Chunked chunked(const Container& container, int chunkSize = 256) { Chunked chunked(const Container& container, int chunkSize = 256) {
return Chunked(chunkSize, folly::range(container.begin(), container.end())); return Chunked(chunkSize, folly::range(container.begin(), container.end()));
} }
template <class Container, template <
class Container,
class Iterator = typename Container::iterator, class Iterator = typename Container::iterator,
class Chunked = detail::ChunkedRangeSource<Iterator>> class Chunked = detail::ChunkedRangeSource<Iterator>>
Chunked chunked(Container& container, int chunkSize = 256) { Chunked chunked(Container& container, int chunkSize = 256) {
......
...@@ -42,7 +42,7 @@ namespace detail { ...@@ -42,7 +42,7 @@ namespace detail {
* *
* auto squares = seq(1, 10) | pmap(fibonacci, 4) | sum; * auto squares = seq(1, 10) | pmap(fibonacci, 4) | sum;
*/ */
template<class Predicate> template <class Predicate>
class PMap : public Operator<PMap<Predicate>> { class PMap : public Operator<PMap<Predicate>> {
Predicate pred_; Predicate pred_;
size_t nThreads_; size_t nThreads_;
...@@ -53,12 +53,12 @@ class PMap : public Operator<PMap<Predicate>> { ...@@ -53,12 +53,12 @@ class PMap : public Operator<PMap<Predicate>> {
: pred_(std::move(pred)), : pred_(std::move(pred)),
nThreads_(nThreads) { } nThreads_(nThreads) { }
template<class Value, template <
class Value,
class Source, class Source,
class Input = typename std::decay<Value>::type, class Input = typename std::decay<Value>::type,
class Output = typename std::decay< class Output = typename std::decay<
typename std::result_of<Predicate(Value)>::type typename std::result_of<Predicate(Value)>::type>::type>
>::type>
class Generator : class Generator :
public GenImpl<Output, Generator<Value, Source, Input, Output>> { public GenImpl<Output, Generator<Value, Source, Input, Output>> {
Source source_; Source source_;
...@@ -153,7 +153,7 @@ class PMap : public Operator<PMap<Predicate>> { ...@@ -153,7 +153,7 @@ class PMap : public Operator<PMap<Predicate>> {
nThreads_(nThreads ? nThreads : sysconf(_SC_NPROCESSORS_ONLN)) { nThreads_(nThreads ? nThreads : sysconf(_SC_NPROCESSORS_ONLN)) {
} }
template<class Body> template <class Body>
void foreach(Body&& body) const { void foreach(Body&& body) const {
ExecutionPipeline pipeline(pred_, nThreads_); ExecutionPipeline pipeline(pred_, nThreads_);
...@@ -190,7 +190,7 @@ class PMap : public Operator<PMap<Predicate>> { ...@@ -190,7 +190,7 @@ class PMap : public Operator<PMap<Predicate>> {
} }
} }
template<class Handler> template <class Handler>
bool apply(Handler&& handler) const { bool apply(Handler&& handler) const {
ExecutionPipeline pipeline(pred_, nThreads_); ExecutionPipeline pipeline(pred_, nThreads_);
...@@ -238,16 +238,12 @@ class PMap : public Operator<PMap<Predicate>> { ...@@ -238,16 +238,12 @@ class PMap : public Operator<PMap<Predicate>> {
static constexpr bool infinite = Source::infinite; static constexpr bool infinite = Source::infinite;
}; };
template<class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(GenImpl<Value, Source>&& source) const { Gen compose(GenImpl<Value, Source>&& source) const {
return Gen(std::move(source.self()), pred_, nThreads_); return Gen(std::move(source.self()), pred_, nThreads_);
} }
template<class Source, template <class Source, class Value, class Gen = Generator<Value, Source>>
class Value,
class Gen = Generator<Value, Source>>
Gen compose(const GenImpl<Value, Source>& source) const { Gen compose(const GenImpl<Value, Source>& source) const {
return Gen(source.self(), pred_, nThreads_); return Gen(source.self(), pred_, nThreads_);
} }
......
...@@ -24,7 +24,7 @@ namespace gen { ...@@ -24,7 +24,7 @@ namespace gen {
namespace detail { namespace detail {
template<class Predicate> template <class Predicate>
class PMap; class PMap;
} // namespace detail } // namespace detail
...@@ -38,8 +38,7 @@ class PMap; ...@@ -38,8 +38,7 @@ class PMap;
* generator and the rest of the pipeline is executed in the * generator and the rest of the pipeline is executed in the
* caller thread. * caller thread.
*/ */
template<class Predicate, template <class Predicate, class PMap = detail::PMap<Predicate>>
class PMap = detail::PMap<Predicate>>
PMap pmap(Predicate pred = Predicate(), size_t nThreads = 0) { PMap pmap(Predicate pred = Predicate(), size_t nThreads = 0) {
return PMap(std::move(pred), nThreads); return PMap(std::move(pred), nThreads);
} }
......
...@@ -258,16 +258,12 @@ class StringResplitter : public Operator<StringResplitter> { ...@@ -258,16 +258,12 @@ class StringResplitter : public Operator<StringResplitter> {
static constexpr bool infinite = Source::infinite; static constexpr bool infinite = Source::infinite;
}; };
template<class Source, template <class Source, class Value, class Gen = Generator<Source>>
class Value,
class Gen = Generator<Source>>
Gen compose(GenImpl<Value, Source>&& source) const { Gen compose(GenImpl<Value, Source>&& source) const {
return Gen(std::move(source.self()), delimiter_, keepDelimiter_); return Gen(std::move(source.self()), delimiter_, keepDelimiter_);
} }
template<class Source, template <class Source, class Value, class Gen = Generator<Source>>
class Value,
class Gen = Generator<Source>>
Gen compose(const GenImpl<Value, Source>& source) const { Gen compose(const GenImpl<Value, Source>& source) const {
return Gen(source.self(), delimiter_, keepDelimiter_); return Gen(source.self(), delimiter_, keepDelimiter_);
} }
...@@ -309,8 +305,7 @@ class SplitStringSource ...@@ -309,8 +305,7 @@ class SplitStringSource
* *
* This type is primarily used through the 'unsplit' function. * This type is primarily used through the 'unsplit' function.
*/ */
template<class Delimiter, template <class Delimiter, class Output>
class Output>
class Unsplit : public Operator<Unsplit<Delimiter, Output>> { class Unsplit : public Operator<Unsplit<Delimiter, Output>> {
Delimiter delimiter_; Delimiter delimiter_;
public: public:
...@@ -318,8 +313,7 @@ class Unsplit : public Operator<Unsplit<Delimiter, Output>> { ...@@ -318,8 +313,7 @@ class Unsplit : public Operator<Unsplit<Delimiter, Output>> {
: delimiter_(delimiter) { : delimiter_(delimiter) {
} }
template<class Source, template <class Source, class Value>
class Value>
Output compose(const GenImpl<Value, Source>& source) const { Output compose(const GenImpl<Value, Source>& source) const {
Output outputBuffer; Output outputBuffer;
UnsplitBuffer<Delimiter, Output> unsplitter(delimiter_, &outputBuffer); UnsplitBuffer<Delimiter, Output> unsplitter(delimiter_, &outputBuffer);
...@@ -334,8 +328,7 @@ class Unsplit : public Operator<Unsplit<Delimiter, Output>> { ...@@ -334,8 +328,7 @@ class Unsplit : public Operator<Unsplit<Delimiter, Output>> {
* *
* This type is primarily used through the 'unsplit' function. * This type is primarily used through the 'unsplit' function.
*/ */
template<class Delimiter, template <class Delimiter, class OutputBuffer>
class OutputBuffer>
class UnsplitBuffer : public Operator<UnsplitBuffer<Delimiter, OutputBuffer>> { class UnsplitBuffer : public Operator<UnsplitBuffer<Delimiter, OutputBuffer>> {
Delimiter delimiter_; Delimiter delimiter_;
OutputBuffer* outputBuffer_; OutputBuffer* outputBuffer_;
...@@ -346,8 +339,7 @@ class UnsplitBuffer : public Operator<UnsplitBuffer<Delimiter, OutputBuffer>> { ...@@ -346,8 +339,7 @@ class UnsplitBuffer : public Operator<UnsplitBuffer<Delimiter, OutputBuffer>> {
CHECK(outputBuffer); CHECK(outputBuffer);
} }
template<class Source, template <class Source, class Value>
class Value>
void compose(const GenImpl<Value, Source>& source) const { void compose(const GenImpl<Value, Source>& source) const {
// If the output buffer is empty, we skip inserting the delimiter for the // If the output buffer is empty, we skip inserting the delimiter for the
// first element. // first element.
...@@ -367,7 +359,7 @@ class UnsplitBuffer : public Operator<UnsplitBuffer<Delimiter, OutputBuffer>> { ...@@ -367,7 +359,7 @@ class UnsplitBuffer : public Operator<UnsplitBuffer<Delimiter, OutputBuffer>> {
/** /**
* Hack for static for-like constructs * Hack for static for-like constructs
*/ */
template<class Target, class=void> template <class Target, class = void>
inline Target passthrough(Target target) { return target; } inline Target passthrough(Target target) { return target; }
FOLLY_PUSH_WARNING FOLLY_PUSH_WARNING
...@@ -386,9 +378,7 @@ FOLLY_PUSH_WARNING ...@@ -386,9 +378,7 @@ FOLLY_PUSH_WARNING
* | as<vector<tuple<int, string>>>(); * | as<vector<tuple<int, string>>>();
* *
*/ */
template<class TargetContainer, template <class TargetContainer, class Delimiter, class... Targets>
class Delimiter,
class... Targets>
class SplitTo { class SplitTo {
Delimiter delimiter_; Delimiter delimiter_;
public: public:
......
...@@ -27,18 +27,16 @@ namespace gen { ...@@ -27,18 +27,16 @@ namespace gen {
namespace detail { namespace detail {
class StringResplitter; class StringResplitter;
template<class Delimiter> template <class Delimiter>
class SplitStringSource; class SplitStringSource;
template<class Delimiter, class Output> template <class Delimiter, class Output>
class Unsplit; class Unsplit;
template<class Delimiter, class OutputBuffer> template <class Delimiter, class OutputBuffer>
class UnsplitBuffer; class UnsplitBuffer;
template<class TargetContainer, template <class TargetContainer, class Delimiter, class... Targets>
class Delimiter,
class... Targets>
class SplitTo; class SplitTo;
} // namespace detail } // namespace detail
...@@ -97,14 +95,16 @@ S lines(StringPiece source) { ...@@ -97,14 +95,16 @@ S lines(StringPiece source) {
// NOTE: The template arguments are reversed to allow the user to cleanly // NOTE: The template arguments are reversed to allow the user to cleanly
// specify the output type while still inferring the type of the delimiter. // specify the output type while still inferring the type of the delimiter.
template<class Output = folly::fbstring, template <
class Output = folly::fbstring,
class Delimiter, class Delimiter,
class Unsplit = detail::Unsplit<Delimiter, Output>> class Unsplit = detail::Unsplit<Delimiter, Output>>
Unsplit unsplit(const Delimiter& delimiter) { Unsplit unsplit(const Delimiter& delimiter) {
return Unsplit(delimiter); return Unsplit(delimiter);
} }
template<class Output = folly::fbstring, template <
class Output = folly::fbstring,
class Unsplit = detail::Unsplit<fbstring, Output>> class Unsplit = detail::Unsplit<fbstring, Output>>
Unsplit unsplit(const char* delimiter) { Unsplit unsplit(const char* delimiter) {
return Unsplit(delimiter); return Unsplit(delimiter);
...@@ -124,21 +124,22 @@ Unsplit unsplit(const char* delimiter) { ...@@ -124,21 +124,22 @@ Unsplit unsplit(const char* delimiter) {
* split("a,b,c", ",") | unsplit(",", &anotherbuffer); * split("a,b,c", ",") | unsplit(",", &anotherbuffer);
* assert(anotherBuffer == "initial,a,b,c"); * assert(anotherBuffer == "initial,a,b,c");
*/ */
template<class Delimiter, template <
class Delimiter,
class OutputBuffer, class OutputBuffer,
class UnsplitBuffer = detail::UnsplitBuffer<Delimiter, OutputBuffer>> class UnsplitBuffer = detail::UnsplitBuffer<Delimiter, OutputBuffer>>
UnsplitBuffer unsplit(Delimiter delimiter, OutputBuffer* outputBuffer) { UnsplitBuffer unsplit(Delimiter delimiter, OutputBuffer* outputBuffer) {
return UnsplitBuffer(delimiter, outputBuffer); return UnsplitBuffer(delimiter, outputBuffer);
} }
template<class OutputBuffer, template <
class OutputBuffer,
class UnsplitBuffer = detail::UnsplitBuffer<fbstring, OutputBuffer>> class UnsplitBuffer = detail::UnsplitBuffer<fbstring, OutputBuffer>>
UnsplitBuffer unsplit(const char* delimiter, OutputBuffer* outputBuffer) { UnsplitBuffer unsplit(const char* delimiter, OutputBuffer* outputBuffer) {
return UnsplitBuffer(delimiter, outputBuffer); return UnsplitBuffer(delimiter, outputBuffer);
} }
template <class... Targets>
template<class... Targets>
detail::Map<detail::SplitTo<std::tuple<Targets...>, char, Targets...>> detail::Map<detail::SplitTo<std::tuple<Targets...>, char, Targets...>>
eachToTuple(char delim) { eachToTuple(char delim) {
return detail::Map< return detail::Map<
...@@ -146,7 +147,7 @@ eachToTuple(char delim) { ...@@ -146,7 +147,7 @@ eachToTuple(char delim) {
detail::SplitTo<std::tuple<Targets...>, char, Targets...>(delim)); detail::SplitTo<std::tuple<Targets...>, char, Targets...>(delim));
} }
template<class... Targets> template <class... Targets>
detail::Map<detail::SplitTo<std::tuple<Targets...>, fbstring, Targets...>> detail::Map<detail::SplitTo<std::tuple<Targets...>, fbstring, Targets...>>
eachToTuple(StringPiece delim) { eachToTuple(StringPiece delim) {
return detail::Map< return detail::Map<
...@@ -154,7 +155,7 @@ eachToTuple(StringPiece delim) { ...@@ -154,7 +155,7 @@ eachToTuple(StringPiece delim) {
detail::SplitTo<std::tuple<Targets...>, fbstring, Targets...>(delim)); detail::SplitTo<std::tuple<Targets...>, fbstring, Targets...>(delim));
} }
template<class First, class Second> template <class First, class Second>
detail::Map<detail::SplitTo<std::pair<First, Second>, char, First, Second>> detail::Map<detail::SplitTo<std::pair<First, Second>, char, First, Second>>
eachToPair(char delim) { eachToPair(char delim) {
return detail::Map< return detail::Map<
...@@ -162,7 +163,7 @@ eachToPair(char delim) { ...@@ -162,7 +163,7 @@ eachToPair(char delim) {
detail::SplitTo<std::pair<First, Second>, char, First, Second>(delim)); detail::SplitTo<std::pair<First, Second>, char, First, Second>(delim));
} }
template<class First, class Second> template <class First, class Second>
detail::Map<detail::SplitTo<std::pair<First, Second>, fbstring, First, Second>> detail::Map<detail::SplitTo<std::pair<First, Second>, fbstring, First, Second>>
eachToPair(StringPiece delim) { eachToPair(StringPiece delim) {
return detail::Map< return detail::Map<
......
...@@ -174,7 +174,7 @@ BENCHMARK_RELATIVE(Fib_Sum_Gen, iters) { ...@@ -174,7 +174,7 @@ BENCHMARK_RELATIVE(Fib_Sum_Gen, iters) {
} }
struct FibYielder { struct FibYielder {
template<class Yield> template <class Yield>
void operator()(Yield&& yield) const { void operator()(Yield&& yield) const {
int a = 0; int a = 0;
int b = 1; int b = 1;
......
...@@ -48,12 +48,12 @@ EXPECT_SAME(int&, typename ArgumentReference<int&>::type); ...@@ -48,12 +48,12 @@ EXPECT_SAME(int&, typename ArgumentReference<int&>::type);
EXPECT_SAME(const int&, typename ArgumentReference<const int&>::type); EXPECT_SAME(const int&, typename ArgumentReference<const int&>::type);
EXPECT_SAME(const int&, typename ArgumentReference<const int>::type); EXPECT_SAME(const int&, typename ArgumentReference<const int>::type);
template<typename T> template <typename T>
ostream& operator<<(ostream& os, const set<T>& values) { ostream& operator<<(ostream& os, const set<T>& values) {
return os << from(values); return os << from(values);
} }
template<typename T> template <typename T>
ostream& operator<<(ostream& os, const vector<T>& values) { ostream& operator<<(ostream& os, const vector<T>& values) {
os << "["; os << "[";
for (auto& value : values) { for (auto& value : values) {
...@@ -71,7 +71,7 @@ auto multiply = [](int a, int b) { return a * b; }; ...@@ -71,7 +71,7 @@ auto multiply = [](int a, int b) { return a * b; };
auto product = foldl(1, multiply); auto product = foldl(1, multiply);
template<typename A, typename B> template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& pair) { ostream& operator<<(ostream& os, const pair<A, B>& pair) {
return os << "(" << pair.first << ", " << pair.second << ")"; return os << "(" << pair.first << ", " << pair.second << ")";
} }
......
...@@ -50,7 +50,7 @@ static auto isPrime = [](int n) { ...@@ -50,7 +50,7 @@ static auto isPrime = [](int n) {
}; };
struct { struct {
template<class T> template <class T>
std::unique_ptr<T> operator()(T t) const { std::unique_ptr<T> operator()(T t) const {
return std::unique_ptr<T>(new T(std::move(t))); return std::unique_ptr<T>(new T(std::move(t)));
} }
......
...@@ -288,7 +288,7 @@ TEST(StringGen, ResplitMaxLength) { ...@@ -288,7 +288,7 @@ TEST(StringGen, ResplitMaxLength) {
); );
} }
template<typename F> template <typename F>
void runUnsplitSuite(F fn) { void runUnsplitSuite(F fn) {
fn("hello, world"); fn("hello, world");
fn("hello,world,goodbye"); fn("hello,world,goodbye");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment