19
19
20
20
#include < memory>
21
21
22
+ #if RAPIDJSON_HAS_CXX11
23
+ #include < type_traits>
24
+ #endif
25
+
22
26
RAPIDJSON_NAMESPACE_BEGIN
23
27
24
28
// /////////////////////////////////////////////////////////////////////////////
@@ -420,6 +424,11 @@ class StdAllocator :
420
424
public std::allocator<T>
421
425
{
422
426
typedef std::allocator<T> allocator_type;
427
+ #if RAPIDJSON_HAS_CXX11
428
+ typedef std::allocator_traits<allocator_type> traits_type;
429
+ #else
430
+ typedef allocator_type traits_type;
431
+ #endif
423
432
424
433
public:
425
434
typedef BaseAllocator BaseAllocatorType;
@@ -449,30 +458,52 @@ class StdAllocator :
449
458
~StdAllocator () RAPIDJSON_NOEXCEPT
450
459
{ }
451
460
452
- typedef typename allocator_type::value_type value_type;
453
- typedef typename allocator_type::pointer pointer;
454
- typedef typename allocator_type::const_pointer const_pointer;
455
- typedef typename allocator_type::reference reference;
456
- typedef typename allocator_type::const_reference const_reference;
457
- typedef typename allocator_type::size_type size_type;
458
- typedef typename allocator_type::difference_type difference_type;
459
-
460
461
template <typename U>
461
462
struct rebind {
462
463
typedef StdAllocator<U, BaseAllocator> other;
463
464
};
464
465
466
+ typedef typename traits_type::size_type size_type;
467
+ typedef typename traits_type::difference_type difference_type;
468
+
469
+ typedef typename traits_type::value_type value_type;
470
+ typedef typename traits_type::pointer pointer;
471
+ typedef typename traits_type::const_pointer const_pointer;
472
+
465
473
#if RAPIDJSON_HAS_CXX11
466
- using allocator_type::max_size;
467
- using allocator_type::address;
468
- using allocator_type::construct;
469
- using allocator_type::destroy;
470
- #else
471
- size_t max_size () const RAPIDJSON_NOEXCEPT
474
+
475
+ typedef typename std::add_lvalue_reference<value_type>::type &reference;
476
+ typedef typename std::add_lvalue_reference<typename std::add_const<value_type>::type>::type &const_reference;
477
+
478
+ pointer address (reference r) const RAPIDJSON_NOEXCEPT
472
479
{
473
- return allocator_type::max_size ();
480
+ return std::addressof (r);
481
+ }
482
+ const_pointer address (const_reference r) const RAPIDJSON_NOEXCEPT
483
+ {
484
+ return std::addressof (r);
485
+ }
486
+
487
+ size_type max_size () const RAPIDJSON_NOEXCEPT
488
+ {
489
+ return traits_type::max_size (*this );
490
+ }
491
+
492
+ template <typename ...Args>
493
+ void construct (pointer p, Args&&... args)
494
+ {
495
+ traits_type::construct (*this , p, std::forward<Args>(args)...);
496
+ }
497
+ void destroy (pointer p)
498
+ {
499
+ traits_type::destroy (*this , p);
474
500
}
475
501
502
+ #else // !RAPIDJSON_HAS_CXX11
503
+
504
+ typedef typename allocator_type::reference reference;
505
+ typedef typename allocator_type::const_reference const_reference;
506
+
476
507
pointer address (reference r) const RAPIDJSON_NOEXCEPT
477
508
{
478
509
return allocator_type::address (r);
@@ -482,6 +513,11 @@ class StdAllocator :
482
513
return allocator_type::address (r);
483
514
}
484
515
516
+ size_type max_size () const RAPIDJSON_NOEXCEPT
517
+ {
518
+ return allocator_type::max_size ();
519
+ }
520
+
485
521
void construct (pointer p, const_reference r)
486
522
{
487
523
allocator_type::construct (p, r);
@@ -490,7 +526,8 @@ class StdAllocator :
490
526
{
491
527
allocator_type::destroy (p);
492
528
}
493
- #endif
529
+
530
+ #endif // !RAPIDJSON_HAS_CXX11
494
531
495
532
template <typename U>
496
533
U* allocate (size_type n = 1 , const void * = 0 )
@@ -578,13 +615,13 @@ class StdAllocator<void, BaseAllocator> :
578
615
~StdAllocator () RAPIDJSON_NOEXCEPT
579
616
{ }
580
617
581
- typedef typename allocator_type::value_type value_type;
582
-
583
618
template <typename U>
584
619
struct rebind {
585
620
typedef StdAllocator<U, BaseAllocator> other;
586
621
};
587
622
623
+ typedef typename allocator_type::value_type value_type;
624
+
588
625
private:
589
626
template <typename , typename >
590
627
friend class StdAllocator ; // access to StdAllocator<!T>.*
0 commit comments