11#pragma once
22#include " xrCore/xrMemory.h"
33
4- template <class T >
4+ template <typename T>
55class xalloc
66{
77public:
8- typedef size_t size_type;
9- typedef std::ptrdiff_t difference_type ;
10- typedef T* pointer ;
11- typedef const T* const_pointer ;
12- typedef T& reference ;
13- typedef const T& const_reference ;
14- typedef T value_type;
8+ using size_type = size_t ;
9+ using difference_type = std::ptrdiff_t ;
10+ using pointer = T* ;
11+ using const_pointer = const T*;
12+ using reference = T& ;
13+ using const_reference = const T&;
14+ using value_type = T ;
1515
16- public:
17- template <class _Other >
16+ template <class Other >
1817 struct rebind
1918 {
20- typedef xalloc<_Other> other ;
19+ using other = xalloc<Other> ;
2120 };
2221
23- public:
24- pointer address (reference _Val) const { return &_Val; }
25- const_pointer address (const_reference _Val) const { return &_Val; }
26- xalloc () {}
27- xalloc (const xalloc<T>&) {}
28- template <class _Other >
29- xalloc (const xalloc<_Other>&) {}
30- template <class _Other >
31- xalloc<T>& operator =(const xalloc<_Other>&) { return *this ; }
32- pointer allocate (size_type n, const void * p = nullptr ) const { return xr_alloc<T>(n); }
33- char * _charalloc (size_type n) { return (char *)allocate (n); }
34- void deallocate (pointer p, size_type n) const { xr_free (p); }
35- void deallocate (void * p, size_type n) const { xr_free (p); }
36- void construct (pointer p, const T& _Val) { new (p) T (_Val); }
22+ pointer address (reference ref) const { return &ref; }
23+ const_pointer address (const_reference ref) const { return &ref; }
24+
25+ xalloc () = default ;
26+ xalloc (const xalloc<T>&) = default ;
27+
28+ template <class Other >
29+ xalloc (const xalloc<Other>&) {}
30+
31+ template <class Other >
32+ xalloc& operator =(const xalloc<Other>&) { return *this ; }
33+
34+ pointer allocate (const size_type n, const void * p = nullptr ) const { return xr_alloc<T>(n); }
35+ void deallocate (pointer p, const size_type /* n*/ ) const { xr_free (p); }
36+ void deallocate (void * p, const size_type /* n*/ ) const { xr_free (p); }
37+ void construct (pointer p, const T& ref) { new (p) T (ref); }
3738 void destroy (pointer p) { p->~T (); }
3839 size_type max_size () const
3940 {
40- size_type _Count = ( size_type)(- 1 )/ sizeof (T);
41- return 0 <_Count ? _Count : 1 ;
41+ constexpr auto count = std::numeric_limits< size_type>:: max () / sizeof (T);
42+ return 0 < count ? count : 1 ;
4243 }
4344};
4445
@@ -47,16 +48,16 @@ struct xr_allocator
4748 template <typename T>
4849 struct helper
4950 {
50- typedef xalloc<T> result ;
51+ using result = xalloc<T>;
5152 };
5253
53- static void * alloc (const u32 & n) { return xr_malloc (( u32 ) n); }
54+ static void * alloc (const size_t n) { return xr_malloc (n); }
5455 template <typename T>
5556 static void dealloc (T*& p) { xr_free (p); }
5657};
5758
58- template <class _Ty , class _Other >
59- inline bool operator ==(const xalloc<_Ty >&, const xalloc<_Other >&) { return true ; }
59+ template <class T , class Other >
60+ bool operator ==(const xalloc<T >&, const xalloc<Other >&) { return true ; }
6061
61- template <class _Ty , class _Other >
62- inline bool operator !=(const xalloc<_Ty >&, const xalloc<_Other >&) { return false ; }
62+ template <class T , class Other >
63+ bool operator !=(const xalloc<T >&, const xalloc<Other >&) { return false ; }
0 commit comments