29__attribute__((warn_unused_result, returns_nonnull))
static inline T* allocate(
size_t n = 1)
32 return allocator.allocate(n);
44__attribute__((warn_unused_result))
static inline T* allocate_noexcept(
size_t n = 1)
noexcept
47 return allocate<T>(n);
48 }
catch(std::bad_alloc
const&) {
59__attribute__((warn_unused_result))
static inline T* new_alloc()
74template <
typename T,
typename Arg>
75__attribute__((warn_unused_result))
static inline T* new_alloc(Arg
const& arg)
90# if __cplusplus >= 201103L
91template <
typename T,
typename... Arg>
92__attribute__((warn_unused_result))
static inline T* new_alloc(Arg&&... arg)
96 new(o) T{std::forward<Arg>(arg)...};
113static inline void deallocate(T* p,
size_t n = 1)
noexcept
119 allocator.deallocate(p, n);
123static inline void delete_alloc(T* p)
noexcept
143# define ZTH_CLASS_NEW_DELETE(T) \
145 static void* operator new(std::size_t UNUSED_PAR(n)) \
147 zth_assert(n == sizeof(T)); \
148 return ::zth::allocate<T>(); \
150 static void operator delete(void* ptr) \
152 ::zth::deallocate<T>(static_cast<T*>(ptr)); \
154 static void* operator new[](std::size_t sz) \
156 zth_assert(sz % sizeof(T) == 0); \
157 return ::zth::allocate<T>(sz / sizeof(T)); \
159 static void operator delete[](void* ptr, size_t sz) \
161 zth_assert(sz % sizeof(T) == 0); \
162 ::zth::deallocate<T>(static_cast<T*>(ptr), sz / sizeof(T)); \
164 typedef typename zth::Config::Allocator<T>::type allocator_type; \
174 typedef std::vector<T, typename Config::Allocator<T>::type>
type;
181template <
typename Key,
typename T,
typename Compare = std::less<Key> >
194 typedef std::list<T, typename Config::Allocator<T>::type>
type;
197template <
typename Traits,
typename Allocator>
200 return string(s.data(), s.size());
205 return std::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.