Skip to content

Commit 2661a17

Browse files
Avoid warnings when using -std=c++20 and clang 10: use three way comparision 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)
1 parent 814bb27 commit 2661a17

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

include/rapidjson/document.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
#include "encodedstream.h"
2525
#include <new> // placement new
2626
#include <limits>
27+
#ifdef __cpp_impl_three_way_comparison
28+
#include <compare>
29+
#endif
2730

2831
RAPIDJSON_DIAG_PUSH
2932
#ifdef __clang__
@@ -247,12 +250,17 @@ class GenericMemberIterator {
247250

248251
//! @name relations
249252
//@{
253+
#ifdef __cpp_impl_three_way_comparison
254+
template <bool Const_> bool operator==(const GenericMemberIterator<Const_,Encoding,Allocator>& that) const { return ptr_ == that.ptr_; }
255+
template <bool Const_> std::strong_ordering operator<=>(const GenericMemberIterator<Const_,Encoding,Allocator>& that) const { return ptr_ <=> that.ptr_; }
256+
#else
250257
bool operator==(ConstIterator that) const { return ptr_ == that.ptr_; }
251258
bool operator!=(ConstIterator that) const { return ptr_ != that.ptr_; }
252259
bool operator<=(ConstIterator that) const { return ptr_ <= that.ptr_; }
253260
bool operator>=(ConstIterator that) const { return ptr_ >= that.ptr_; }
254261
bool operator< (ConstIterator that) const { return ptr_ < that.ptr_; }
255262
bool operator> (ConstIterator that) const { return ptr_ > that.ptr_; }
263+
#endif
256264
//@}
257265

258266
//! @name dereference

0 commit comments

Comments
 (0)