Go to the documentation of this file.
9 #ifndef EAGINE_VARARRAY_HPP
10 #define EAGINE_VARARRAY_HPP
13 #include <type_traits>
18 template <
typename T,
typename S>
19 class basic_vararray {
24 using alloc_unit_t = std::conditional_t<
alignof(T) >=
alignof(S), T, S>;
26 static std::size_t alloc_unit_c(std::size_t n) noexcept {
27 if(
alignof(T) >=
alignof(S)) {
28 return n + (
sizeof(S) /
sizeof(T)) +
29 ((
sizeof(S) %
sizeof(T)) ? 1 : 0);
31 return 1 + ((n *
sizeof(T)) /
sizeof(S)) +
32 (((n *
sizeof(T)) %
sizeof(S)) ? 1 : 0);
37 const size_type _size = 0;
41 constexpr basic_vararray() noexcept = default;
43 static std::
size_t instance_size(size_type n) noexcept {
44 return alloc_unit_c(n) *
sizeof(alloc_unit_t);
47 std::size_t instance_size() const noexcept {
48 return instance_size(_size);
51 size_type size() const noexcept {
56 using const_iterator =
const T*;
58 iterator begin() noexcept {
62 iterator end() noexcept {
63 return begin() + size();
66 const_iterator begin() const noexcept {
70 const_iterator end() const noexcept {
71 return begin() + size();
76 using vararray = basic_vararray<T, std::size_t>;
79 template <
typename T,
typename S, S N>
80 class basic_vararray_store {
86 constexpr basic_vararray_store() noexcept = default;
88 operator basic_vararray<T, S> &() {
89 return *
reinterpret_cast<basic_vararray<T, S>*
>(
this);
92 operator const basic_vararray<T, S> &()
const {
93 return *
reinterpret_cast<const basic_vararray<T, S>*
>(
this);
97 template <
typename T, std::
size_t N>
98 using vararray_store = basic_vararray_store<T, std::size_t, N>;
102 #endif // EAGINE_VARARRAY_HPP
value_type
Value tree value element data type enumeration.
Definition: interface.hpp:27
Common code is placed in this namespace.
Definition: eagine.hpp:21