I am currently creating a class with a constexpr
constructor and I wonder if I can use an std::array
to store the data of this class. Does the standard explicitly specify that an std::array
has a constexpr
constructor and that its contents can be accessed at compile-time ?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Numpy matrix of coordinates
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
Based on the comment by @MarkGlisse: this compiles
I believe I have found the relevant quote from the Standard here:
12.1 Constructors [class.ctor]
This looks essentially like @BenVoigt's answer.
Because
std::array<T, N>
is an aggregate, it can be initialized as aconstexpr
if and only if the underlying typeT
has aconstexpr
constructor (when presented with each initializer you provide).