【发布时间】:2022-12-01 14:33:07
【问题描述】:
std::get's index is not known, but evaluated at compile time. I want to do something very similar to std::get's functionality with an std::array member.
Take this struct:
template<size_t size>
struct ArrayWrapper {
std::array<int, size> arr;
};
I would want to be able to do something like this: ArrayWrapper<4> foo; Here, arr inside foo would be initialized at compile time with a size of 4. The code above doesn't work, which doesn't make sense to me since size is known at compile time.
Is there any way of making this work?
【问题讨论】:
-
Your corrected code compiles for me.
标签: c++ compile-time