Is there any safe and standard compliant way to treat a C style array as an std::array without copying the data into a new std::array?
This clearly doesn't compile, but is the effect I would like (my real use is more complicated but this short sample should show what I'd like to do). I guess a reinterpret_cast would "work" but probably isn't safe?
#include <array>
int main()
{
int data[] = {1, 2, 3, 4, 5};
// This next line is the important one, treating an existing array as a std::array
std::array<int, 5>& a = data;
}
It feels like it ought to be possible as the data should be stored identically.
edit: To be clear I don't want to clear a new std::array, I want to refer to the existing data as one.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…