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>
#if RAPIDJSON_HAS_CXX11
#include <limits>
#include <type_traits>
#endif
@ -466,6 +465,7 @@ public:
typedef typename traits_type::size_type size_type;
typedef typename traits_type::difference_type difference_type;
typedef typename traits_type::value_type value_type;
typedef typename traits_type::pointer pointer;
typedef typename traits_type::const_pointer const_pointer;
@ -484,19 +484,19 @@ public:
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>
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)
{
p->~T();
traits_type::destroy(*this, p);
}
#else // !RAPIDJSON_HAS_CXX11
@ -513,7 +513,7 @@ public:
return allocator_type::address(r);
}
size_t max_size() const RAPIDJSON_NOEXCEPT
size_type max_size() const RAPIDJSON_NOEXCEPT
{
return allocator_type::max_size();
}
@ -615,13 +615,13 @@ public:
~StdAllocator() RAPIDJSON_NOEXCEPT
{ }
typedef typename allocator_type::value_type value_type;
template<typename U>
struct rebind {
typedef StdAllocator<U, BaseAllocator> other;
};
typedef typename allocator_type::value_type value_type;
private:
template <typename, typename>
friend class StdAllocator; // access to StdAllocator<!T>.*

View File

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