Skip to content

Commit

Permalink
chore: add UntypedStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Oct 26, 2024
1 parent dd0b88a commit 92c702a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
28 changes: 28 additions & 0 deletions src/ll/api/base/Alias.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#pragma once

#include <bit>
#include <cstddef>
#include <type_traits>
#include <utility>

namespace ll {
template <class T, size_t N>
struct CArray {
Expand All @@ -11,4 +16,27 @@ struct CArray<T, 0> {
};
template <class T, size_t N = 0>
using CArrayT = typename CArray<T, N>::type;

template <size_t Len, size_t Align = (std::min)((1ull << std::countr_zero(Len)), 8ull)>
struct UntypedStorage {
alignas(Align) std::byte data[Len];

template <class T>
[[nodiscard]] T& as() & {
return *reinterpret_cast<T*>(this);
}
template <class T>
[[nodiscard]] T const& as() const& {
return *reinterpret_cast<T const*>(this);
}
template <class T>
[[nodiscard]] T&& as() && {
return std::move(*reinterpret_cast<T*>(this));
}
template <class T>
[[nodiscard]] T const&& as() const&& {
return std::move(*reinterpret_cast<T const*>(this));
}
};

} // namespace ll
6 changes: 3 additions & 3 deletions src/ll/api/coro/Generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ template <class T>
struct Generator {
using value = std::remove_cvref_t<T>;
using reference = T&&;
using yielded = std::conditional_t<std::is_reference_v<reference>, reference, reference const&>;
using yielded = reference;


struct promise_type {
Expand Down Expand Up @@ -60,8 +60,8 @@ struct Generator {
struct iterator {
using iterator_category = std::input_iterator_tag;
using difference_type = ptrdiff_t;
using value_type = value;
using reference = reference;
using value_type = Generator::value;
using reference = Generator::reference;
using pointer = std::add_pointer_t<yielded>;

std::coroutine_handle<promise_type> handle = nullptr;
Expand Down

0 comments on commit 92c702a

Please sign in to comment.