Summary: It's easy to accidentally pass a negative value to ##take()##, which leads to underflow on conversion to ##size_t##.
Reviewed By: @​rosephilip, @philippv
Differential Revision:
D2421459
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); }
| as<vector>();
EXPECT_EQ(expected, actual);
}
+ {
+ int64_t limit = 5;
+ take(limit - 5);
+ EXPECT_THROW(take(limit - 6), std::invalid_argument);
+ }
}