Make StdAllocator C++17-20 compatible.

This commit is contained in:
ylavic 2021-03-29 00:17:24 +02:00
parent 02f42604bd
commit 08cf9a56c0
2 changed files with 19 additions and 13 deletions

View File

@ -20,7 +20,6 @@
#include <memory> #include <memory>
#if RAPIDJSON_HAS_CXX11 #if RAPIDJSON_HAS_CXX11
#include <limits>
#include <type_traits> #include <type_traits>
#endif #endif
@ -466,6 +465,7 @@ public:
typedef typename traits_type::size_type size_type; typedef typename traits_type::size_type size_type;
typedef typename traits_type::difference_type difference_type; typedef typename traits_type::difference_type difference_type;
typedef typename traits_type::value_type value_type; typedef typename traits_type::value_type value_type;
typedef typename traits_type::pointer pointer; typedef typename traits_type::pointer pointer;
typedef typename traits_type::const_pointer const_pointer; typedef typename traits_type::const_pointer const_pointer;
@ -484,19 +484,19 @@ public:
return std::addressof(r); return std::addressof(r);
} }
size_t max_size() const RAPIDJSON_NOEXCEPT size_type max_size() const RAPIDJSON_NOEXCEPT
{ {
return std::numeric_limits<size_type>::max() / sizeof(value_type); return traits_type::max_size(*this);
} }
template <typename ...Args> template <typename ...Args>
void construct(pointer p, Args&&... args) void construct(pointer p, Args&&... args)
{ {
::new (static_cast<void*>(p)) value_type(std::forward<Args>(args)...); traits_type::construct(*this, p, std::forward<Args>(args)...);
} }
void destroy(pointer p) void destroy(pointer p)
{ {
p->~T(); traits_type::destroy(*this, p);
} }
#else // !RAPIDJSON_HAS_CXX11 #else // !RAPIDJSON_HAS_CXX11
@ -513,7 +513,7 @@ public:
return allocator_type::address(r); return allocator_type::address(r);
} }
size_t max_size() const RAPIDJSON_NOEXCEPT size_type max_size() const RAPIDJSON_NOEXCEPT
{ {
return allocator_type::max_size(); return allocator_type::max_size();
} }
@ -615,13 +615,13 @@ public:
~StdAllocator() RAPIDJSON_NOEXCEPT ~StdAllocator() RAPIDJSON_NOEXCEPT
{ } { }
typedef typename allocator_type::value_type value_type;
template<typename U> template<typename U>
struct rebind { struct rebind {
typedef StdAllocator<U, BaseAllocator> other; typedef StdAllocator<U, BaseAllocator> other;
}; };
typedef typename allocator_type::value_type value_type;
private: private:
template <typename, typename> template <typename, typename>
friend class StdAllocator; // access to StdAllocator<!T>.* friend class StdAllocator; // access to StdAllocator<!T>.*

View File

@ -135,6 +135,8 @@
#define RAPIDJSON_CPLUSPLUS __cplusplus #define RAPIDJSON_CPLUSPLUS __cplusplus
#endif #endif
//!@endcond
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// RAPIDJSON_HAS_STDSTRING // RAPIDJSON_HAS_STDSTRING
@ -627,10 +629,14 @@ RAPIDJSON_NAMESPACE_END
#if RAPIDJSON_HAS_CXX17 #if RAPIDJSON_HAS_CXX17
# define RAPIDJSON_DELIBERATE_FALLTHROUGH [[fallthrough]] # define RAPIDJSON_DELIBERATE_FALLTHROUGH [[fallthrough]]
#elif defined(__has_cpp_attribute) && __has_cpp_attribute(fallthrough) #elif defined(__has_cpp_attribute)
# define RAPIDJSON_DELIBERATE_FALLTHROUGH __attribute__((fallthrough)) # if __has_cpp_attribute(clang::fallthrough)
#elif defined(__has_cpp_attribute) && __has_cpp_attribute(clang::fallthrough)
# define RAPIDJSON_DELIBERATE_FALLTHROUGH [[clang::fallthrough]] # define RAPIDJSON_DELIBERATE_FALLTHROUGH [[clang::fallthrough]]
# elif __has_cpp_attribute(fallthrough)
# define RAPIDJSON_DELIBERATE_FALLTHROUGH __attribute__((fallthrough))
# else
# define RAPIDJSON_DELIBERATE_FALLTHROUGH
# endif
#else #else
# define RAPIDJSON_DELIBERATE_FALLTHROUGH # define RAPIDJSON_DELIBERATE_FALLTHROUGH
#endif #endif