Added more static asserts for alignment

This commit is contained in:
John Wellbelove 2021-06-03 20:45:36 +01:00
parent a2aa6b26c3
commit 2b2a542aa1

View File

@ -110,6 +110,8 @@ namespace etl
static ETL_CONSTANT size_t Size = Size_;
static ETL_CONSTANT size_t Alignment = Alignment_;
ETL_STATIC_ASSERT(etl::is_power_of_2<Alignment>::value, "Alignment must be a power of 2");
//***********************************
/// Default constructor
//***********************************
@ -125,10 +127,26 @@ namespace etl
mem_cast(const mem_cast<Other_Size, Other_Alignment>& other)
{
ETL_STATIC_ASSERT(Size >= Other_Size, "Other size is too large");
ETL_STATIC_ASSERT(Alignment >= Other_Alignment, "Other alignment incompatible");
ETL_STATIC_ASSERT(Alignment >= Other_Alignment, "Other alignment is incompatible");
ETL_STATIC_ASSERT(etl::is_power_of_2<Other_Alignment>::value, "Other alignment must be a power of 2");
memcpy(buffer, other.buffer, Size_);
}
//***********************************
/// Assignment operator
//***********************************
template <size_t Other_Size, size_t Other_Alignment>
mem_cast& operator =(const mem_cast<Other_Size, Other_Alignment>& rhs)
{
ETL_STATIC_ASSERT(Size >= Other_Size, "RHS size is too large");
ETL_STATIC_ASSERT(Alignment >= Other_Alignment, "RHS alignment is incompatible");
ETL_STATIC_ASSERT(etl::is_power_of_2<Other_Alignment>::value, "Other alignment must be a power of 2");
memcpy(buffer, rhs.buffer, Size_);
return *this;
}
//***********************************
/// Assign from value
@ -286,20 +304,6 @@ namespace etl
return *static_cast<const T*>(p);
}
//***********************************
/// Assignment operator
//***********************************
template <size_t Other_Size, size_t Other_Alignment>
mem_cast& operator =(const mem_cast<Other_Size, Other_Alignment>& rhs)
{
ETL_STATIC_ASSERT(Size >= Other_Size, "RHS size is too large");
ETL_STATIC_ASSERT(Alignment >= Other_Alignment, "RHS alignment incompatible");
memcpy(buffer, rhs.buffer, Size_);
return *this;
}
//***********************************
/// Get the size of the buffer
//***********************************
@ -374,6 +378,17 @@ namespace etl
{
}
//***********************************
/// Assignment operator
//***********************************
mem_cast_ptr& operator =(const mem_cast_ptr& rhs)
{
pbuffer = rhs.pbuffer;
buffer_size = rhs.buffer_size;
return *this;
}
//***********************************
/// Assign from value
//***********************************
@ -540,17 +555,6 @@ namespace etl
return *reinterpret_cast<const T*>(p);
}
//***********************************
/// Assignment operator
//***********************************
mem_cast_ptr& operator =(const mem_cast_ptr& rhs)
{
pbuffer = rhs.pbuffer;
buffer_size = rhs.buffer_size;
return *this;
}
//***********************************
/// Get the size of the buffer
//***********************************