folly/wangle/futures/Future-inl.h: avoid -Wsign-compare errors
authorJim Meyering <meyering@fb.com>
Tue, 6 Jan 2015 23:46:38 +0000 (15:46 -0800)
committerViswanath Sivakumar <viswanath@fb.com>
Tue, 13 Jan 2015 19:01:05 +0000 (11:01 -0800)
Summary:
* folly/wangle/futures/Future-inl.h (whenAll): Do not compare
signed (std::distance) with unsigned(size_t): add an assertion
to eliminate the possibility of negative, then assign to a new
size_t "n".

Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 -r folly && fbmake dbgo

Reviewed By: jsedgwick@fb.com

Subscribers: trunkagent, fugalh, folly-diffs@

FB internal diff: D1770668

Tasks: 5941250

Signature: t1:1770668:1420736965:fc722657a2ec523052fd96c33d65d5ca24aae61c

folly/wangle/futures/Future-inl.h

index 66cadbcf7f02f1c70e1504e4f056278d81b39ee0..61c386ad80c8cbcd52f9b95c315470d89e244b11 100644 (file)
@@ -546,10 +546,10 @@ whenAll(InputIterator first, InputIterator last)
   typedef
     typename std::iterator_traits<InputIterator>::value_type::value_type T;
 
-  auto n = std::distance(first, last);
-  if (n == 0) {
+  if (first >= last) {
     return makeFuture(std::vector<Try<T>>());
   }
+  size_t n = std::distance(first, last);
 
   auto ctx = new detail::WhenAllContext<T>();