Skip to content

Commit

Permalink
Avoid warnings when using -std=c++20 and clang 10: use three way comp…
Browse files Browse the repository at this point in the history
…arision for iterators when possible. (Tencent#1667)

/data/mwrep/res/osp/RapidJson/20-0-0-0/include/rapidjson/document.h:729:58: error: use of overloaded operator '!=' is ambiguous (with operand types 'rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >::MemberIterator' (aka 'rapidjson::GenericMemberIterator<false, rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >') and 'rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >::MemberIterator')
                for (MemberIterator m = MemberBegin(); m != MemberEnd(); ++m)
  • Loading branch information
Romain-Geissler-1A authored and jasonsandlin committed Aug 2, 2023
1 parent 43b2e4c commit 01cbc9f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions include/rapidjson/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#include "encodedstream.h"
#include <new> // placement new
#include <limits>
#ifdef __cpp_impl_three_way_comparison
#include <compare>
#endif

RAPIDJSON_DIAG_PUSH
#ifdef _MSC_VER
Expand Down Expand Up @@ -174,12 +177,17 @@ class GenericMemberIterator {

//! @name relations
//@{
#ifdef __cpp_impl_three_way_comparison
template <bool Const_> bool operator==(const GenericMemberIterator<Const_,Encoding,Allocator>& that) const { return ptr_ == that.ptr_; }
template <bool Const_> std::strong_ordering operator<=>(const GenericMemberIterator<Const_,Encoding,Allocator>& that) const { return ptr_ <=> that.ptr_; }
#else
bool operator==(ConstIterator that) const { return ptr_ == that.ptr_; }
bool operator!=(ConstIterator that) const { return ptr_ != that.ptr_; }
bool operator<=(ConstIterator that) const { return ptr_ <= that.ptr_; }
bool operator>=(ConstIterator that) const { return ptr_ >= that.ptr_; }
bool operator< (ConstIterator that) const { return ptr_ < that.ptr_; }
bool operator> (ConstIterator that) const { return ptr_ > that.ptr_; }
#endif
//@}

//! @name dereference
Expand Down

0 comments on commit 01cbc9f

Please sign in to comment.