projects
/
folly.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
folly copyright 2015 -> copyright 2016
[folly.git]
/
folly
/
gen
/
Base-inl.h
diff --git
a/folly/gen/Base-inl.h
b/folly/gen/Base-inl.h
index 0c4e92f4556959aff2f6a17d994eb595e86c9ae3..3b756fbc5ef5d79a0c5712623d5c84784e16a94f 100644
(file)
--- a/
folly/gen/Base-inl.h
+++ b/
folly/gen/Base-inl.h
@@
-1,5
+1,5
@@
/*
/*
- * Copyright 201
5
Facebook, Inc.
+ * Copyright 201
6
Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@
-347,7
+347,7
@@
class SeqWithStepImpl {
template <class Value>
class InfiniteImpl {
public:
template <class Value>
class InfiniteImpl {
public:
- bool test(const Value&
current
) const { return true; }
+ bool test(const Value&
/* current */
) const { return true; }
void step(Value& current) const { ++current; }
static constexpr bool infinite = true;
};
void step(Value& current) const { ++current; }
static constexpr bool infinite = true;
};
@@
-559,7
+559,8
@@
class Filter : public Operator<Filter<Predicate>> {
template <class Body>
void foreach(Body&& body) const {
source_.foreach([&](Value value) {
template <class Body>
void foreach(Body&& body) const {
source_.foreach([&](Value value) {
- if (pred_(std::forward<Value>(value))) {
+ // NB: Argument not forwarded to avoid accidental move-construction
+ if (pred_(value)) {
body(std::forward<Value>(value));
}
});
body(std::forward<Value>(value));
}
});
@@
-568,7
+569,8
@@
class Filter : public Operator<Filter<Predicate>> {
template <class Handler>
bool apply(Handler&& handler) const {
return source_.apply([&](Value value) -> bool {
template <class Handler>
bool apply(Handler&& handler) const {
return source_.apply([&](Value value) -> bool {
- if (pred_(std::forward<Value>(value))) {
+ // NB: Argument not forwarded to avoid accidental move-construction
+ if (pred_(value)) {
return handler(std::forward<Value>(value));
}
return true;
return handler(std::forward<Value>(value));
}
return true;
@@
-1828,10
+1830,11
@@
class IsEmpty : public Operator<IsEmpty<emptyResult>> {
"false or hang. 'any' or 'notEmpty' will either return true "
"or hang.");
bool ans = emptyResult;
"false or hang. 'any' or 'notEmpty' will either return true "
"or hang.");
bool ans = emptyResult;
- source | [&](Value v) -> bool {
- ans = !emptyResult;
- return false;
- };
+ source |
+ [&](Value /* v */) -> bool {
+ ans = !emptyResult;
+ return false;
+ };
return ans;
}
};
return ans;
}
};
@@
-1888,9
+1891,8
@@
class Count : public Operator<Count> {
size_t compose(const GenImpl<Value, Source>& source) const {
static_assert(!Source::infinite, "Cannot count infinite source");
return foldl(size_t(0),
size_t compose(const GenImpl<Value, Source>& source) const {
static_assert(!Source::infinite, "Cannot count infinite source");
return foldl(size_t(0),
- [](size_t accum, Value v) {
- return accum + 1;
- }).compose(source);
+ [](size_t accum, Value /* v */) { return accum + 1; })
+ .compose(source);
}
};
}
};
@@
-2306,7
+2308,13
@@
constexpr detail::Indirect indirect{};
constexpr detail::Unwrap unwrap{};
constexpr detail::Unwrap unwrap{};
-inline detail::Take take(size_t count) { return detail::Take(count); }
+template <class Number>
+inline detail::Take take(Number count) {
+ if (count < 0) {
+ throw std::invalid_argument("Negative value passed to take()");
+ }
+ return detail::Take(static_cast<size_t>(count));
+}
inline detail::Stride stride(size_t s) { return detail::Stride(s); }
inline detail::Stride stride(size_t s) { return detail::Stride(s); }