Added experimental uni_type

This commit is contained in:
John Wellbelove 2021-05-25 11:02:24 +01:00
parent 84e1241c39
commit 3cbd432a29

View File

@ -6,6 +6,13 @@ public:
static constexpr size_t Size = Size_;
//***********************************
template <typename T>
uni_type(const uni_type& other)
{
memcpy(buffer, other.buffer, Size_);
}
//***********************************
template <typename T>
T& get()
@ -20,12 +27,22 @@ public:
return *reinterpret_cast<T*>(buffer);
}
//***********************************
template <typename T>
operator T()
{
return *reinterpret_cast<T*>(buffer);
}
//***********************************
template <typename T>
uni_type& operator =(const uni_type& rhs)
{
memcpy(buffer, rhs.buffer, Size_);
return *this;
}
//***********************************
constexpr size_t size() const
{
@ -37,8 +54,6 @@ private:
char buffer[Size]
};
template <size_t Size_>
class uni_type_ptr
{
@ -46,6 +61,18 @@ public:
static constexpr size_t Size = Size_;
//***********************************
uni_type_ptr()
: pbuffer(ETL_NULLPTR)
{
}
//***********************************
uni_type_ptr(void* pbuffer_)
: pbuffer(reinterpret_cast<char*>(pbuffer))
{
}
//***********************************
template <typename T>
T& get()
@ -75,4 +102,4 @@ public:
private:
char* pbuffer;
};
};