我正在尝试使用std :: aligned_storage模式实现简单静态数组的16字节对齐:
#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 }@H_403_4@我得到以下编译错误:
@H_403_4@no match for «operator[]» in «mas[0]»@H_403_4@然后我尝试使用显式指针转换:
float* mas_ = reinterpret_cast<float*>(mas);@H_403_4@但这也会产生编译错误:
@H_403_4@invalid cast from type «float_16 {aka std::aligned_storage<32u,@H_403_4@任何人都可以建议我如何正确使用std :: aligned_storage对齐静态数组?
16u>::type}» to type «float*»