From fd0420443caa2fa13597d75d6c0ec07b57528fce Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Sat, 30 Oct 2021 18:47:40 +0100 Subject: [PATCH] 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 channels{util::MakeFilledArray(typeConstructorArg, <...>)}; ``` --- app/src/main/cpp/skyline/common/utils.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/cpp/skyline/common/utils.h b/app/src/main/cpp/skyline/common/utils.h index 60914b31..1d35b925 100644 --- a/app/src/main/cpp/skyline/common/utils.h +++ b/app/src/main/cpp/skyline/common/utils.h @@ -260,4 +260,15 @@ namespace skyline::util { return &value; } }; -} + + template + std::array MakeFilledArray(std::index_sequence, TArgs &&... args) + { + return {(void(Is), T(args...))...}; + } + + template + std::array MakeFilledArray(TArgs &&... args) { + return MakeFilledArray(std::make_index_sequence(), std::forward(args)...); + } +} \ No newline at end of file