1 year ago
#266445
glades
Adjust array inside struct according to parameter pack length (passed into constructor)
I want to create a constexpr struct which holds a number of states in an array, represented by state_type_t
. The struct should be created dynamically via a parameter pack. My problem is that I don't know the size of the array holding the states as I would have to be aware of the number of arguments in the parameter pack... Is there a way around this (C++11)?
template<int S>
struct state_collection
{
state_collection(state_type_t... Args) : states_(Args...) const noexcept {
}
std::array<state_type_t, S> states_; // <-- how big is S? How to derive S from parameter pack size?
};
struct region
{
constexpr state_collection req_;
constexpr state_collection act_;
};
region( { .req_{LOCAL_STATE_A, LOCAL_STATE_B}, .act_{} } );
c++
stdarray
parameter-pack
0 Answers
Your Answer