allow storage of extra data inside metadata

v1
Brett 2024-03-07 12:46:00 -05:00
parent 19857f3b2b
commit b937df3ca6
2 changed files with 43 additions and 12 deletions

View File

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.5)
include(cmake/color.cmake)
set(BLT_VERSION 0.14.1)
set(BLT_VERSION 0.14.2)
set(BLT_TEST_VERSION 0.0.1)
set(BLT_TARGET BLT)

View File

@ -29,8 +29,35 @@
namespace blt
{
//#define ALIGN_TO(x, size) (((x) + size - 1) & ~(size - 1))
template<typename T = void>
template<typename MetaExtra>
struct metadata_template_t;
template<>
struct metadata_template_t<void>
{
// size in number of elements!
blt::size_t size;
explicit metadata_template_t(blt::size_t size): size(size)
{}
};
template<typename Extra>
struct metadata_template_t
{
// size in number of elements!
blt::size_t size;
Extra extra;
explicit metadata_template_t(blt::size_t size): size(size)
{}
};
/**
* @tparam T type to store inside
* @tparam Extra any extra data to store. void will result in zero size increase.
*/
template<typename T = void, typename Extra = void>
class array
{
public:
@ -39,14 +66,8 @@ namespace blt
using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
private:
struct metadata_t
{
// size in number of elements!
blt::size_t size;
explicit metadata_t(blt::size_t size): size(size)
{}
} metadata;
using metadata_t = metadata_template_t<Extra>;
metadata_t metadata;
static constexpr blt::size_t ALIGNMENT = std::max(sizeof(metadata_t), alignof(T));
@ -186,6 +207,16 @@ namespace blt
return reverse_iterator{cbegin()};
}
constexpr inline metadata_t& get_metadata()
{
return metadata;
}
constexpr inline const metadata_t& get_metadata() const
{
return metadata;
}
~array() = default;
};