Skip to content

Commit

Permalink
✨ added cast to resource types and more QoL improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
lamarrr committed Nov 28, 2024
1 parent 52ae390 commit e6116fb
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 296 deletions.
9 changes: 5 additions & 4 deletions ashura/std/dyn.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ struct [[nodiscard]] Dyn
};

template <typename T, typename... Args>
Result<Dyn<T *>, Void> dyn_inplace(AllocatorImpl allocator, Args &&...args)
constexpr Result<Dyn<T *>, Void> dyn_inplace(AllocatorImpl allocator,
Args &&...args)
{
T *object;
if (!allocator.nalloc(1, object)) [[unlikely]]
Expand All @@ -107,13 +108,13 @@ Result<Dyn<T *>, Void> dyn_inplace(AllocatorImpl allocator, Args &&...args)
}

template <typename T>
Result<Dyn<T *>, Void> dyn(AllocatorImpl allocator, T object)
constexpr Result<Dyn<T *>, Void> dyn(AllocatorImpl allocator, T object)
{
return dyn_inplace<T>(allocator, (T &&) object);
}

template <typename Base, typename H>
Dyn<H> transmute(Dyn<Base> &&base, H handle)
constexpr Dyn<H> transmute(Dyn<Base> &&base, H handle)
{
Dyn<H> t{(H &&) handle, base.inner.allocator, base.inner.uninit};
base.inner.handle = {};
Expand All @@ -123,7 +124,7 @@ Dyn<H> transmute(Dyn<Base> &&base, H handle)
}

template <typename To, typename From>
Dyn<To> cast(Dyn<From> &&from)
constexpr Dyn<To> cast(Dyn<From> &&from)
{
return transmute((Dyn<From> &&) from, static_cast<To>(from.get()));
}
Expand Down
Loading

0 comments on commit e6116fb

Please sign in to comment.