Make clear that we are using ptrdiff_t as the iterator difference type.
authorLei Zhang <antiagainst@google.com>
Tue, 16 Aug 2016 15:19:34 +0000 (11:19 -0400)
committerLei Zhang <antiagainst@google.com>
Tue, 16 Aug 2016 15:21:08 +0000 (11:21 -0400)
And ptrdiff_t is a implementation defined signed type. Comparing it
with unsigned number literal causes compiler warnings.

source/opt/iterator.h
test/opt/test_ir_loader.cpp

index 6ca3dbc..da572ff 100644 (file)
@@ -41,9 +41,10 @@ namespace ir {
 // std::vector<|ValueType|>.
 template <typename ValueType, bool IsConst = false>
 class UptrVectorIterator
-    : public std::iterator<std::random_access_iterator_tag,
-                           typename std::conditional<IsConst, const ValueType,
-                                                     ValueType>::type> {
+    : public std::iterator<
+          std::random_access_iterator_tag,
+          typename std::conditional<IsConst, const ValueType, ValueType>::type,
+          ptrdiff_t> {
  public:
   using super = std::iterator<
       std::random_access_iterator_tag,
@@ -51,6 +52,7 @@ class UptrVectorIterator
 
   using pointer = typename super::pointer;
   using reference = typename super::reference;
+  using difference_type = typename super::difference_type;
 
   // Type aliases. We need to apply constness properly if |IsConst| is true.
   using Uptr = std::unique_ptr<ValueType>;
index 8717140..479cb4b 100644 (file)
@@ -216,7 +216,7 @@ TEST(IrBuilder, OpUndefOutsideFunction) {
   const auto opundef_count = std::count_if(
       module->types_values_begin(), module->types_values_end(),
       [](const ir::Instruction& inst) { return inst.opcode() == SpvOpUndef; });
-  EXPECT_EQ(3u, opundef_count);
+  EXPECT_EQ(3, opundef_count);
 
   std::vector<uint32_t> binary;
   module->ToBinary(&binary, /* skip_nop = */ false);