25# define ZTH_MALLOC_INLINE inline
26# define ZTH_MALLOC_ATTR(attr)
28# define ZTH_MALLOC_INLINE __attribute__((noinline))
29# if !defined(__clang_analyzer__) && GCC_VERSION >= 110000L
30# define ZTH_MALLOC_ATTR(attr) __attribute__(attr)
32# define ZTH_MALLOC_ATTR(attr) __attribute__((malloc))
46 typename Config::Allocator<T>::type allocator;
47 allocator.deallocate(p, n);
66 (malloc((
void (*)(T*,
size_t)
noexcept)deallocate, 1),
70 return allocator.allocate(n);
83 (malloc((
void (*)(T*,
size_t)
noexcept)deallocate, 1),
84 alloc_size(1))) static
ZTH_MALLOC_INLINE T* allocate_noexcept(
size_t n = 1) noexcept
87 return allocate<T>(n);
88 }
catch(std::bad_alloc
const&) {
100 (malloc((
void (*)(T*)
noexcept)delete_alloc)))
static ZTH_MALLOC_INLINE T* new_alloc()
102 T* o = allocate<T>();
114template <
typename T,
typename Arg>
116 (
void (*)(T*)
noexcept)delete_alloc)))
static ZTH_MALLOC_INLINE T* new_alloc(Arg
const& arg)
118 T* o = allocate<T>();
130# if __cplusplus >= 201103L
131template <
typename T,
typename... Arg>
133 (
void (*)(T*)
noexcept)delete_alloc)))
static ZTH_MALLOC_INLINE T* new_alloc(Arg&&... arg)
135 T* o = allocate<T>();
137 new(o) T{std::forward<Arg>(arg)...};
159# define ZTH_CLASS_NEW_DELETE(T) \
161 static ZTH_MALLOC_INLINE void operator delete(void* ptr) noexcept \
163 ::zth::deallocate<T>(static_cast<T*>(ptr)); \
165 ZTH_MALLOC_ATTR((malloc, alloc_size(1))) \
166 __attribute__((warn_unused_result, returns_nonnull)) static ZTH_MALLOC_INLINE void* \
167 operator new(std::size_t UNUSED_PAR(n)) \
169 zth_assert(n == sizeof(T)); \
170 return ::zth::allocate<T>(); \
172 static ZTH_MALLOC_INLINE void operator delete[](void* ptr, size_t sz) noexcept \
174 zth_assert(sz % sizeof(T) == 0); \
175 ::zth::deallocate<T>(static_cast<T*>(ptr), sz / sizeof(T)); \
177 ZTH_MALLOC_ATTR((malloc, alloc_size(1))) \
178 __attribute__((warn_unused_result, returns_nonnull)) static ZTH_MALLOC_INLINE void* \
179 operator new[](std::size_t sz) \
181 zth_assert(sz % sizeof(T) == 0); \
182 return ::zth::allocate<T>(sz / sizeof(T)); \
184 typedef typename zth::Config::Allocator<T>::type allocator_type; \
194 typedef std::vector<T, typename Config::Allocator<T>::type>
type;
201template <
typename Key,
typename T,
typename Compare = std::less<Key> >
214 typedef std::list<T, typename Config::Allocator<T>::type>
type;
217template <
typename Traits,
typename Allocator>
220 return string(s.data(), s.size());
225 return std::string(s.data(), s.size());
#define ZTH_MALLOC_ATTR(attr)
#define ZTH_MALLOC_INLINE
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.