X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=include%2Fllvm%2FSupport%2FYAMLParser.h;h=a5addfa3c7ae2c675b23ad7de9639cd0a21aeccc;hp=b056ab6c1ce28eb93438736509d025a6d89313a3;hb=71a6baa31c4a08a3c123953a0239bff001b2e437;hpb=4cb9f9dcb1839ebe4a09c1c254f1ee1f598d98c8 diff --git a/include/llvm/Support/YAMLParser.h b/include/llvm/Support/YAMLParser.h index b056ab6c1ce..a5addfa3c7a 100644 --- a/include/llvm/Support/YAMLParser.h +++ b/include/llvm/Support/YAMLParser.h @@ -305,7 +305,7 @@ private: /// increment() which must set CurrentEntry to 0 to create an end iterator. template class basic_collection_iterator - : public std::iterator { + : public std::iterator { public: basic_collection_iterator() : Base(nullptr) {} basic_collection_iterator(BaseT *B) : Base(B) {} @@ -326,11 +326,24 @@ public: return Base->CurrentEntry; } + /// Note on EqualityComparable: + /// + /// The iterator is not re-entrant, + /// it is meant to be used for parsing YAML on-demand + /// Once iteration started - it can point only to one entry at a time + /// hence Base.CurrentEntry and Other.Base.CurrentEntry are equal + /// iff Base and Other.Base are equal. + bool operator==(const basic_collection_iterator &Other) const { + if (Base && (Base == Other.Base)) { + assert((Base->CurrentEntry == Other.Base->CurrentEntry) + && "Equal Bases expected to point to equal Entries"); + } + + return Base == Other.Base; + } + bool operator!=(const basic_collection_iterator &Other) const { - if (Base != Other.Base) - return true; - return (Base && Other.Base) && - Base->CurrentEntry != Other.Base->CurrentEntry; + return !(Base == Other.Base); } basic_collection_iterator &operator++() {