1#ifndef VEG_DYNAMIC_STACK_DYNAMIC_STACK_HPP_UBOMZFTOS
2#define VEG_DYNAMIC_STACK_DYNAMIC_STACK_HPP_UBOMZFTOS
24 return (a > b) ? a : b;
41 return a.size_bytes == b.size_bytes && a.align == b.align;
46 using namespace _detail::_dynstack;
53 (max2)(a.align, b.align)),
54 (max2)(a.align, b.align),
59 using namespace _detail::_dynstack;
62 round_up_pow2(a.size_bytes, max2(a.align, b.align)),
63 round_up_pow2(b.size_bytes, max2(a.align, b.align))),
64 (max2)(a.align, b.align),
78 isize{
sizeof(T) } * len,
122 static_assert(
sizeof(std::uintptr_t) >=
sizeof(
void*),
123 "std::uintptr_t can't hold a pointer value");
129 (alignment >
isize{ 0 }),
130 ((
u64(alignment) & (
u64(alignment) - 1)) ==
u64(0)));
139 auto const intptr =
reinterpret_cast<std::uintptr_t
>(ptr);
159template<
typename T,
bool = VEG_CONCEPT(trivially_destructible<T>)>
192 return ::new (ptr) T[
usize(len)];
201 return ::new (ptr) T[
usize(len)]{};
210 return proxsuite::linalg::veg::mem::launder(
static_cast<T*
>(
211 static_cast<void*
>(::new (ptr)
unsigned char[
usize(len) *
sizeof(T)])));
223 : stack_data(
s.ptr_mut())
224 , stack_bytes(
s.len())
231 return isize(stack_bytes);
251 (align =
alignof(T),
isize))
254 assert_valid_len(len);
267 (align =
alignof(T),
isize))
271 assert_valid_len(len);
282 isize align =
alignof(T))
285 assert_valid_len(len);
334 if (
data !=
nullptr) {
337 static_cast<unsigned char*
>(
parent->stack_data);
339 static_cast<unsigned char*
>(
old_pos);
341 static_cast<unsigned char*
>(
const_cast<void*
>(
void_data_end));
348 static_cast<isize>(
static_cast<unsigned char*
>(
parent->stack_data) -
349 static_cast<unsigned char*
>(
old_pos));
374 other.Base::data =
nullptr;
381 auto cleanup =
static_cast<decltype(rhs)
>(*this);
383 static_cast<Base&
>(*this) = rhs;
384 static_cast<Base&
>(rhs) = {};
411 static_cast<T*
>(
const_cast<void*
>(
Base::data));
428 template<
typename Fn>
447 if (
ptr !=
nullptr) {
448 bool success =
false;
485 auto cleanup =
static_cast<decltype(rhs)
>(*this);
487 static_cast<Base&
>(*this) = rhs;
488 static_cast<Base&
>(rhs) = {};
#define VEG_ASSERT_ALL_OF(...)
#define PROXSUITE_MAYBE_UNUSED
void backward_destroy(RefMut< A > alloc, RefMut< C > cloner, T *ptr, T *ptr_end)
constexpr auto round_up_pow2(isize a, isize b) noexcept -> isize
constexpr auto max2(isize a, isize b) noexcept -> isize
auto align_next(isize alignment, isize size, void *&ptr, isize &space) VEG_ALWAYS_NOEXCEPT -> void *
_detail::_meta::make_signed< usize >::Type isize
decltype(sizeof(0)) usize
#define VEG_ALWAYS_NOEXCEPT
#define VEG_INTERNAL_ASSERT_PRECONDITIONS
#define VEG_NOEXCEPT_IF(...)
proxsuite::linalg::veg::dynstack::DynStackMut * parent
void const volatile * data
void destroy(void const volatile *void_data_end) VEG_NOEXCEPT
auto operator=(DynStackArrayDtor const &) -> DynStackArrayDtor &=default
auto operator=(DynStackArrayDtor &&) -> DynStackArrayDtor &=default
VEG_INLINE ~DynStackArrayDtor()
DynStackArrayDtor()=default
DynStackArrayDtor(DynStackArrayDtor &&)=default
DynStackArrayDtor(DynStackArrayDtor const &)=default
proxsuite::linalg::veg::dynstack::DynStackMut & parent
VEG_INLINE void operator()() const VEG_NOEXCEPT
auto make(void *ptr, isize len) -> T *
auto make(void *ptr, isize len) -> T *
auto make(void *ptr, isize len) -> T *
VEG_NODISCARD auto as_mut() VEG_NOEXCEPT -> SliceMut< T >
VEG_INLINE ~DynStackAlloc() VEG_NOEXCEPT
DynStackAlloc(DynStackAlloc const &)=delete
VEG_NODISCARD auto ptr_mut() VEG_NOEXCEPT -> T *
auto operator=(DynStackAlloc const &) -> DynStackAlloc &=delete
DynStackAlloc(DynStackAlloc &&other) VEG_NOEXCEPT
auto operator=(DynStackAlloc &&rhs) VEG_NOEXCEPT -> DynStackAlloc &
VEG_NODISCARD auto as_ref() const VEG_NOEXCEPT -> Slice< T >
VEG_NODISCARD auto ptr() const VEG_NOEXCEPT -> T const *
VEG_NODISCARD auto len() const VEG_NOEXCEPT -> isize
DynStackArray(DynStackArray const &)=delete
DynStackArray(DynStackArray &&) VEG_NOEXCEPT=default
VEG_TEMPLATE((typename T), requires VEG_CONCEPT(constructible< T >), VEG_NODISCARD auto make_new_for_overwrite,(, Tag< T >),(len, isize),(align=alignof(T), isize)) VEG_NOEXCEPT_IF(VEG_CONCEPT(nothrow_constructible< T >)) -> DynStackArray< T >
VEG_NODISCARD auto ptr() const VEG_NOEXCEPT -> void const *
VEG_TEMPLATE((typename T), requires VEG_CONCEPT(constructible< T >), VEG_NODISCARD auto make_new,(, Tag< T >),(len, isize),(align=alignof(T), isize)) VEG_NOEXCEPT_IF(VEG_CONCEPT(nothrow_constructible< T >)) -> DynStackArray< T >
VEG_NODISCARD auto ptr_mut() const VEG_NOEXCEPT -> void *
VEG_NODISCARD auto make_alloc(Tag< T >, isize len, isize align=alignof(T)) VEG_NOEXCEPT -> DynStackAlloc< T >
DynStackMut(FromSliceMut, SliceMut< unsigned char > s) VEG_NOEXCEPT
VEG_NODISCARD auto remaining_bytes() const VEG_NOEXCEPT -> isize
constexpr friend auto operator&(StackReq a, StackReq b) noexcept -> StackReq
static VEG_CPP14(constexpr) auto and_(Slice< StackReq > reqs) noexcept -> StackReq
static constexpr auto with_len(proxsuite::linalg::veg::Tag< T >, isize len) noexcept -> StackReq
constexpr friend auto operator|(StackReq a, StackReq b) noexcept -> StackReq
constexpr auto alloc_req() const noexcept -> isize
constexpr friend auto operator==(StackReq a, StackReq b) noexcept -> bool
static VEG_CPP14(constexpr) auto or_(Slice< StackReq > reqs) noexcept -> StackReq