mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-15 16:36:03 +08:00
Added more static asserts for alignment
This commit is contained in:
parent
a2aa6b26c3
commit
2b2a542aa1
@ -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
|
||||
//***********************************
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user