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