Skip to content

Commit

Permalink
Address some compilation failures with various compilers.
Browse files Browse the repository at this point in the history
  • Loading branch information
ylavic committed Apr 11, 2019
1 parent 32d006d commit 41e5efe
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
50 changes: 42 additions & 8 deletions include/rapidjson/allocators.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@
#include "rapidjson.h"

#include <memory>
#if RAPIDJSON_HAS_CXX11_TYPETRAITS
#if RAPIDJSON_HAS_CXX11
#include <type_traits>
#endif

RAPIDJSON_NAMESPACE_BEGIN

RAPIDJSON_DIAG_PUSH
#ifdef __GNUC__
RAPIDJSON_DIAG_OFF(effc++)
#endif

///////////////////////////////////////////////////////////////////////////////
// Allocator

Expand Down Expand Up @@ -89,7 +94,7 @@ class StdBaseAllocator {
};

StdBaseAllocator(Allocator &allocator) RAPIDJSON_NOEXCEPT :
allocator_(allocator) {
allocator_(&allocator) {
}

StdBaseAllocator(const StdBaseAllocator& other) RAPIDJSON_NOEXCEPT :
Expand All @@ -101,6 +106,14 @@ class StdBaseAllocator {
allocator_(other.allocator_) {
}

#if RAPIDJSON_HAS_CXX11
StdBaseAllocator(StdBaseAllocator&& other) RAPIDJSON_NOEXCEPT :
allocator_(other.allocator_) {
}
using propagate_on_container_move_assignment = std::true_type;
using is_always_equal = std::is_empty<Allocator>;
#endif

size_type max_size() const RAPIDJSON_NOEXCEPT {
return static_cast<size_type>(-1) / sizeof(value_type);
}
Expand Down Expand Up @@ -128,7 +141,7 @@ class StdBaseAllocator {
void construct(pointer p, const_reference r) {
::new(static_cast<void*>(p)) value_type(r);
}
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
#if RAPIDJSON_HAS_CXX11
template<typename OtherType, typename... Args>
void construct(OtherType* p, Args&&... args) {
::new(static_cast<void*>(p)) OtherType(std::forward<Args>(args)...);
Expand Down Expand Up @@ -156,10 +169,11 @@ class StdBaseAllocator {
}
pointer Reallocate(pointer old, size_type old_n, size_type new_n) {
RAPIDJSON_ASSERT(sizeof(value_type) == 1 || new_n <= max_size());
return static_cast<pointer>(allocator_.Realloc(old, old_n * sizeof(value_type),
new_n * sizeof(value_type)));
return static_cast<pointer>(allocator_->Realloc(old, old_n * sizeof(value_type),
new_n * sizeof(value_type)));
}
#if 0 && RAPIDJSON_HAS_CXX11_RVALUE_REFS

#if RAPIDJSON_HAS_CXX11
template<typename OtherType, typename... Args>
OtherType *New(Args&&... args) {
typename rebind<OtherType>::other a(*this);
Expand All @@ -176,11 +190,29 @@ class StdBaseAllocator {
#endif

private:
Allocator *allocator_;

StdBaseAllocator() /* = delete */;
template <typename, typename> friend class StdBaseAllocator; // OtherType::allocator_
Allocator &allocator_;

// For OtherType::allocator_
template <typename, typename>
friend class StdBaseAllocator;
template<typename T1, typename T2, typename A>
friend bool operator==(const StdBaseAllocator<T1, A>& a1,
const StdBaseAllocator<T2, A>& a2) RAPIDJSON_NOEXCEPT;
};

template<typename T1, typename T2, typename A>
bool operator==(const StdBaseAllocator<T1, A>& a1,
const StdBaseAllocator<T2, A>& a2) RAPIDJSON_NOEXCEPT {
return a1.allocator_ == a2.allocator_;
}
template<typename T1, typename T2, typename A>
bool operator!=(const StdBaseAllocator<T1, A>& a1,
const StdBaseAllocator<T2, A>& a2) RAPIDJSON_NOEXCEPT {
return !(a1 == a2);
}

///////////////////////////////////////////////////////////////////////////////
// CrtAllocator

Expand Down Expand Up @@ -406,6 +438,8 @@ class MemoryPoolAllocator : public StdBaseAllocator<unsigned char, MemoryPoolAll
BaseAllocator* ownBaseAllocator_; //!< base allocator created by this object.
};

RAPIDJSON_DIAG_POP

RAPIDJSON_NAMESPACE_END

#endif // RAPIDJSON_ENCODINGS_H_
4 changes: 2 additions & 2 deletions include/rapidjson/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@ inline GenericStringRef<CharType> StringRef(const std::basic_string<CharType>& s
#ifdef RAPIDJSON_USE_MEMBERS_MAP
template <typename Encoding, typename Allocator>
struct GenericMemberMap {
typedef Allocator AllocatorType;
typedef typename Encoding::Ch Ch;
typedef GenericStringRef<Ch> KeyType;
struct KeyLess {
Expand All @@ -421,9 +420,10 @@ struct GenericMemberMap {
return cmp < 0 || (cmp == 0 && s1.length < s2.length);
}
};
typedef std::pair<const KeyType, SizeType> Pair;
typedef typename Allocator::template rebind<Pair>::other AllocatorType;
typedef std::multimap<KeyType, SizeType, KeyLess, AllocatorType> Map;
typedef typename Map::iterator Iterator;
typedef typename Map::value_type Pair;
};
#endif

Expand Down
4 changes: 4 additions & 0 deletions include/rapidjson/rapidjson.h
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,10 @@ RAPIDJSON_NAMESPACE_END
///////////////////////////////////////////////////////////////////////////////
// C++11 features

#ifndef RAPIDJSON_HAS_CXX11
#define RAPIDJSON_HAS_CXX11 (__cplusplus >= 201103L)
#endif

#ifndef RAPIDJSON_HAS_CXX11_RVALUE_REFS
#if defined(__clang__)
#if __has_feature(cxx_rvalue_references) && \
Expand Down

0 comments on commit 41e5efe

Please sign in to comment.