26# define ZTH_MALLOC_INLINE inline
27# define ZTH_MALLOC_ATTR(attr)
29# define ZTH_MALLOC_INLINE __attribute__((noinline))
30# if !defined(__clang_analyzer__) && GCC_VERSION >= 110000L
31# define ZTH_MALLOC_ATTR(attr) __attribute__(attr)
33# define ZTH_MALLOC_ATTR(attr) __attribute__((malloc))
47 typename Config::Allocator<T>::type allocator;
48 allocator.deallocate(p, n);
67 (malloc((
void (*)(T*,
size_t)
noexcept)deallocate, 1),
71 return allocator.allocate(n);
84 (malloc((
void (*)(T*,
size_t)
noexcept)deallocate, 1),
85 alloc_size(1))) static
ZTH_MALLOC_INLINE T* allocate_noexcept(
size_t n = 1) noexcept
88 return allocate<T>(n);
89 }
catch(std::bad_alloc
const&) {
101 (malloc((
void (*)(T*)
noexcept)delete_alloc)))
static ZTH_MALLOC_INLINE T* new_alloc()
103 T* o = allocate<T>();
115template <
typename T,
typename Arg>
117 (
void (*)(T*)
noexcept)delete_alloc)))
static ZTH_MALLOC_INLINE T* new_alloc(Arg
const& arg)
119 T* o = allocate<T>();
131# if __cplusplus >= 201103L
132template <
typename T,
typename... Arg>
134 (
void (*)(T*)
noexcept)delete_alloc)))
static ZTH_MALLOC_INLINE T* new_alloc(Arg&&... arg)
136 T* o = allocate<T>();
138 new(o) T{std::forward<Arg>(arg)...};
160# define ZTH_CLASS_NEW_DELETE(T) \
162 static ZTH_MALLOC_INLINE void operator delete(void* ptr) noexcept \
164 ::zth::deallocate<T>(static_cast<T*>(ptr)); \
166 ZTH_MALLOC_ATTR((malloc, alloc_size(1))) \
167 __attribute__((warn_unused_result, returns_nonnull)) static ZTH_MALLOC_INLINE void* \
168 operator new(std::size_t UNUSED_PAR(n)) \
170 zth_assert(n == sizeof(T)); \
171 return ::zth::allocate<T>(); \
173 static ZTH_MALLOC_INLINE void operator delete[](void* ptr, size_t sz) noexcept \
175 zth_assert(sz % sizeof(T) == 0); \
176 ::zth::deallocate<T>(static_cast<T*>(ptr), sz / sizeof(T)); \
178 ZTH_MALLOC_ATTR((malloc, alloc_size(1))) \
179 __attribute__((warn_unused_result, returns_nonnull)) static ZTH_MALLOC_INLINE void* \
180 operator new[](std::size_t sz) \
182 zth_assert(sz % sizeof(T) == 0); \
183 return ::zth::allocate<T>(sz / sizeof(T)); \
185 typedef typename zth::Config::Allocator<T>::type allocator_type; \
195 typedef std::vector<T, typename Config::Allocator<T>::type>
type;
202template <
typename Key,
typename T,
typename Compare = std::less<Key> >
213template <
typename Key,
typename Compare = std::less<Key> >
215 typedef std::set<Key, Compare, typename Config::Allocator<Key>::type>
type;
224 typedef std::list<T, typename Config::Allocator<T>::type>
type;
227template <
typename Traits,
typename Allocator>
230 return string(s.data(), s.size());
235 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::map type using Config::Allocator::type.
std::set< Key, Compare, typename Config::Allocator< Key >::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.
void zth_terminate()
Terminate immediately.