I want to test the use of alignas()
, so I write down these code:
#include <vector>
using namespace std;
template<typename X>
void user(const vector<X>& vx)
{
constexpr int bufmax = 1024;
alignas(X) buffer[bufmax];
const int max = min(vx.size(), bufmax / sizeof(X));
uninitialized_copy(vx.begin(), vx.begin()+max, buffer);
}
However, when I compile it with g++, the compiler outputs an error: "expected primary-expression before alignas(X)
". Who could explain this? I don't know the exact usages of alignas()
.