I'm trying to implement 16-byte alignment of simple static array using std::aligned_storage pattern:
#include <type_traits>
int main()
{
const size_t SIZE = 8;
using float_16 = std::aligned_storage<sizeof(float) * SIZE, 16>::type;
float_16 mas;
new(&mas) float[SIZE];//Placement new. Is this necessary?
mas[0]=1.f;//Compile error while attempting to set elements of aligned array
}
I get the following compile-error:
no match for «operator[]» in «mas[0]»
Then I tried to use explicit pointer casting:
float* mas_ = reinterpret_cast<float*>(mas);
but this also yields compile-error:
invalid cast from type «float_16 {aka std::aligned_storage<32u, 16u>::type}» to type «float*»
Can anybody suggest me how align static array using std::aligned_storage correctly?