14#ifndef __AUDACITY_PACKED_ARRAY__
15#define __AUDACITY_PACKED_ARRAY__
21template<
typename T>
struct Traits;
36 std::declval<T>().*(Traits<T>::array_member)
43 static_assert(std::extent_v<member_type> == 1);
55 return reinterpret_cast<size_t>(
begin(0));
85template<
typename Type,
86 template<
typename>
typename BaseDeleter = std::default_delete>
104 (void)std::declval<element_type>().~element_type(),
105 (void)std::declval<header_type>().~header_type(),
106 (void)std::declval<base_type>()(p)
112 for (
auto count =
mCount; count--;)
113 (--pE)->~element_type();
126template<
typename Type,
127 template<
typename>
typename BaseDeleter = std::default_delete>
129 : std::unique_ptr<Type, Deleter<Type, BaseDeleter>>
132 std::unique_ptr<Type, Deleter<Type, BaseDeleter>>::unique_ptr;
137 return *(
begin(*
this) + ii);
142template<
typename Type,
template<
typename>
typename BaseDeleter>
145 return p.get_deleter().GetCount();
149template<
typename Type,
template<
typename>
typename BaseDeleter>
158template<
typename Type,
template<
typename>
typename BaseDeleter>
161 auto result =
begin(p);
176 return ::operator
new(std::max(
size, enlarged));
181 ::operator
delete(p);
194 return [enlarged](
auto &&...args) {
197 Type{ std::forward<decltype(args)>(args)... },
198 std::max(
sizeof(Type), enlarged)
215 const auto bytes = traits_type::element_offset()
216 + count *
sizeof(
typename traits_type::element_type);
217 return AllocateBytes<Type>(bytes);
static constexpr PackedArray_t PackedArrayArg
Tag argument to distinguish an overload of operator new.
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
auto AllocateCount(size_t count)
Allocate a Ptr<Type> holding count elements.
auto AllocateBytes(size_t enlarged)
Allocate a Ptr<Type> holding at least enlarged bytes.
size_t Count(const Ptr< Type, BaseDeleter > &p)
Find out how many elements were allocated with a Ptr.
Deleter for an array of elements and optional contiguous header structure.
typename traits_type::header_type header_type
typename traits_type::element_type element_type
void operator()(Type *p) const noexcept(noexcept((void) std::declval< element_type >().~element_type(),(void) std::declval< header_type >().~header_type(),(void) std::declval< base_type >()(p)))
BaseDeleter< managed_type > base_type
Deleter(size_t size=0) noexcept
Smart pointer type that deallocates with Deleter.
auto & operator[](size_t ii) const
Enables subscripting. Does not check for null!
Primary template used in Deleter that can be specialized.
static iterated_type * begin(T *p)
std::remove_extent_t< member_type > iterated_type
typename Traits< T >::element_type element_type
static size_t element_offset()
static element_type * element_ptr(T *p)
std::remove_reference_t< decltype(std::declval< T >().*(Traits< T >::array_member))> member_type
Primary template of metafunction deducing other things from Traits<T>
static size_t element_offset()
static element_type * element_ptr(T *p)
static iterated_type * begin(T *p)
typename Traits< T >::element_type element_type