1 #ifndef ZTH_ALLOCATOR_H
2 #define ZTH_ALLOCATOR_H
30 __attribute__((warn_unused_result, returns_nonnull))
static inline T* allocate(
size_t n = 1)
33 return allocator.allocate(n);
45 __attribute__((warn_unused_result))
static inline T* allocate_noexcept(
size_t n = 1) noexcept
48 return allocate<T>(n);
55 __attribute__((warn_unused_result))
static inline T* new_alloc()
57 T* o = allocate<T>(1);
62 template <
typename T,
typename Arg>
63 __attribute__((warn_unused_result))
static inline T* new_alloc(Arg
const& arg)
65 T* o = allocate<T>(1);
70 # if __cplusplus >= 201103L
71 template <
typename T,
typename... Arg>
72 __attribute__((warn_unused_result))
static inline T* new_alloc(Arg&&... arg)
74 T* o = allocate<T>(1);
75 new(o) T(std::forward<Arg>(arg)...);
85 static inline void deallocate(T* p,
size_t n = 1) noexcept
91 allocator.deallocate(p, n);
95 static inline void delete_alloc(T* p) noexcept
114 # define ZTH_CLASS_NEW_DELETE(T) \
116 void* operator new(std::size_t UNUSED_PAR(n)) \
118 zth_assert(n == sizeof(T)); \
119 return ::zth::allocate<T>(); \
121 void operator delete(void* ptr) \
123 ::zth::deallocate<T>(static_cast<T*>(ptr)); \
132 template <
typename T>
134 typedef std::vector<T, typename Config::Allocator<T>::type>
type;
141 template <
typename Key,
typename T,
typename Compare = std::less<Key> >
152 template <
typename T>
154 typedef std::list<T, typename Config::Allocator<T>::type>
type;
157 template <
typename Traits,
typename Allocator>
160 return string(s.data(), s.size());
std::basic_string< char, std::char_traits< char >, Config::Allocator< char >::type > string
std::string type using Config::Allocator::type.
std::string to_std_string(string const &s)
string to_zth_string(std::basic_string< char, Traits, Allocator > const &s)
std::list type using Config::Allocator::type.
std::list< T, typename Config::Allocator< T >::type > type
std::map type using Config::Allocator::type.
std::map< Key, T, Compare, typename Config::Allocator< std::pair< const Key, T > >::type > type
std::vector type using Config::Allocator::type.
std::vector< T, typename Config::Allocator< T >::type > type
#define unlikely(expr)
Marks the given expression to likely be evaluated to true.