Skip to content

Commit 08cf9a5

Browse files
committed
Make StdAllocator C++17-20 compatible.
1 parent 02f4260 commit 08cf9a5

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

include/rapidjson/allocators.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <memory>
2121

2222
#if RAPIDJSON_HAS_CXX11
23-
#include <limits>
2423
#include <type_traits>
2524
#endif
2625

@@ -466,6 +465,7 @@ class StdAllocator :
466465

467466
typedef typename traits_type::size_type size_type;
468467
typedef typename traits_type::difference_type difference_type;
468+
469469
typedef typename traits_type::value_type value_type;
470470
typedef typename traits_type::pointer pointer;
471471
typedef typename traits_type::const_pointer const_pointer;
@@ -484,19 +484,19 @@ class StdAllocator :
484484
return std::addressof(r);
485485
}
486486

487-
size_t max_size() const RAPIDJSON_NOEXCEPT
487+
size_type max_size() const RAPIDJSON_NOEXCEPT
488488
{
489-
return std::numeric_limits<size_type>::max() / sizeof(value_type);
489+
return traits_type::max_size(*this);
490490
}
491491

492492
template <typename ...Args>
493-
void construct(pointer p, Args &&...args)
493+
void construct(pointer p, Args&&... args)
494494
{
495-
::new (static_cast<void*>(p)) value_type(std::forward<Args>(args)...);
495+
traits_type::construct(*this, p, std::forward<Args>(args)...);
496496
}
497497
void destroy(pointer p)
498498
{
499-
p->~T();
499+
traits_type::destroy(*this, p);
500500
}
501501

502502
#else // !RAPIDJSON_HAS_CXX11
@@ -513,7 +513,7 @@ class StdAllocator :
513513
return allocator_type::address(r);
514514
}
515515

516-
size_t max_size() const RAPIDJSON_NOEXCEPT
516+
size_type max_size() const RAPIDJSON_NOEXCEPT
517517
{
518518
return allocator_type::max_size();
519519
}
@@ -615,13 +615,13 @@ class StdAllocator<void, BaseAllocator> :
615615
~StdAllocator() RAPIDJSON_NOEXCEPT
616616
{ }
617617

618-
typedef typename allocator_type::value_type value_type;
619-
620618
template<typename U>
621619
struct rebind {
622620
typedef StdAllocator<U, BaseAllocator> other;
623621
};
624622

623+
typedef typename allocator_type::value_type value_type;
624+
625625
private:
626626
template <typename, typename>
627627
friend class StdAllocator; // access to StdAllocator<!T>.*

include/rapidjson/rapidjson.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@
135135
#define RAPIDJSON_CPLUSPLUS __cplusplus
136136
#endif
137137

138+
//!@endcond
139+
138140
///////////////////////////////////////////////////////////////////////////////
139141
// RAPIDJSON_HAS_STDSTRING
140142

@@ -627,10 +629,14 @@ RAPIDJSON_NAMESPACE_END
627629

628630
#if RAPIDJSON_HAS_CXX17
629631
# define RAPIDJSON_DELIBERATE_FALLTHROUGH [[fallthrough]]
630-
#elif defined(__has_cpp_attribute) && __has_cpp_attribute(fallthrough)
631-
# define RAPIDJSON_DELIBERATE_FALLTHROUGH __attribute__((fallthrough))
632-
#elif defined(__has_cpp_attribute) && __has_cpp_attribute(clang::fallthrough)
633-
# define RAPIDJSON_DELIBERATE_FALLTHROUGH [[clang::fallthrough]]
632+
#elif defined(__has_cpp_attribute)
633+
# if __has_cpp_attribute(clang::fallthrough)
634+
# define RAPIDJSON_DELIBERATE_FALLTHROUGH [[clang::fallthrough]]
635+
# elif __has_cpp_attribute(fallthrough)
636+
# define RAPIDJSON_DELIBERATE_FALLTHROUGH __attribute__((fallthrough))
637+
# else
638+
# define RAPIDJSON_DELIBERATE_FALLTHROUGH
639+
# endif
634640
#else
635641
# define RAPIDJSON_DELIBERATE_FALLTHROUGH
636642
#endif

0 commit comments

Comments
 (0)