include/o3tl/enumarray.hxx | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
New commits: commit e7c3b635387a4b207998a70fec46328642966d71 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Tue Aug 19 11:19:37 2025 +0200 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Tue Aug 19 14:05:09 2025 +0200 Use C++20 concepts and requirements to simplify enumarray ctor Resolves the "to keep things simple that parameter is always passed by const lvalue reference for now even if there could be cases where passing it by rvalue reference might be beneficial or even necessary" comment from commit 37ec4442d70339dc8ec5fb8e4ec8984420b6e14d (o3tl: ensure that the initializer of enumarray contains enough elements, 2022-06-18). Also helps to see the problem in IDE immediately, instead of delayed to compile time. Change-Id: I04e7343604bd02a075d07f2adf2760ad5883f908 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189902 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/include/o3tl/enumarray.hxx b/include/o3tl/enumarray.hxx index 4fd5cab3155f..0ea89c855f2b 100644 --- a/include/o3tl/enumarray.hxx +++ b/include/o3tl/enumarray.hxx @@ -25,6 +25,7 @@ #include <utility> #include <array> #include <cassert> +#include <concepts> namespace o3tl { @@ -57,16 +58,11 @@ public: static const size_type max_index = static_cast<size_type>(E::LAST); - // If this ctor only had the args parameter pack, it would erroneously get picked as a better - // choice than the (implicit) copy ctor (taking a const lvalue reference) when a copy is made - // from a non-const lvalue enumarray; the easiest way to avoid that is the additional arg - // parameter; and to keep things simple that parameter is always passed by const lvalue - // reference for now even if there could be cases where passing it by rvalue reference might be - // beneficial or even necessary if V is a move-only type: - template<typename... T> constexpr enumarray(V const & arg, T && ...args): - detail_values{arg, std::forward<T>(args)...} + template <std::convertible_to<V>... T> + requires(sizeof...(T) == max_index + 1) + constexpr enumarray(T&&... args) + : detail_values{ std::forward<T>(args)... } { - static_assert(sizeof... (T) == max_index); } // coverity[uninit_ctor] - by design: