6 #ifndef JSON_ALLOCATOR_H_INCLUDED 7 #define JSON_ALLOCATOR_H_INCLUDED 16 template <
typename T>
class SecureAllocator {
21 using const_pointer =
const T*;
23 using const_reference =
const T&;
24 using size_type = std::size_t;
25 using difference_type = std::ptrdiff_t;
30 pointer allocate(size_type n) {
32 return static_cast<pointer
>(::operator
new(n *
sizeof(T)));
40 void deallocate(pointer p, size_type n) {
42 memset_s(p, n *
sizeof(T), 0, n *
sizeof(T));
50 template <
typename... Args>
void construct(pointer p, Args&&... args) {
52 ::new (static_cast<void*>(p)) T(std::forward<Args>(args)...);
55 size_type max_size()
const {
return size_t(-1) /
sizeof(T); }
57 pointer address(reference x)
const {
return std::addressof(x); }
59 const_pointer address(const_reference x)
const {
return std::addressof(x); }
64 void destroy(pointer p) {
71 template <
typename U> SecureAllocator(
const SecureAllocator<U>&) {}
72 template <
typename U>
struct rebind {
using other = SecureAllocator<U>; };
75 template <
typename T,
typename U>
76 bool operator==(
const SecureAllocator<T>&,
const SecureAllocator<U>&) {
80 template <
typename T,
typename U>
81 bool operator!=(
const SecureAllocator<T>&,
const SecureAllocator<U>&) {
89 #endif // JSON_ALLOCATOR_H_INCLUDED JSON (JavaScript Object Notation).
Definition: allocator.h:15