Add template utils for constructing all elements in an std::array

This avoids the excessive repetition needed for the case where array
members have no default constructor.

eg:
```c++
std::array<Type, 10> channels{util::MakeFilledArray<Type, 10>(typeConstructorArg, <...>)};
```
This commit is contained in:
Billy Laws 2021-10-30 18:47:40 +01:00 committed by PixelyIon
parent 34bf413661
commit fd0420443c

View File

@ -260,4 +260,15 @@ namespace skyline::util {
return &value;
}
};
}
template<typename T, typename... TArgs, size_t... Is>
std::array<T, sizeof...(Is)> MakeFilledArray(std::index_sequence<Is...>, TArgs &&... args)
{
return {(void(Is), T(args...))...};
}
template<typename T, size_t Size, typename... TArgs>
std::array<T, Size> MakeFilledArray(TArgs &&... args) {
return MakeFilledArray<T>(std::make_index_sequence<Size>(), std::forward<TArgs>(args)...);
}
}