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
This diff is collapsed.
This diff is collapsed.
...@@ -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