From 02c2b28cd0f341fd955f9648d9174777e0b60689 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 1 Apr 2021 23:04:54 -0700 Subject: common: common_funcs: Add Size helper function. --- src/common/common_funcs.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src') diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h index 73c8c9354..19bb021e0 100644 --- a/src/common/common_funcs.h +++ b/src/common/common_funcs.h @@ -136,4 +136,19 @@ namespace Common { return u32(a) | u32(b) << 8 | u32(c) << 16 | u32(d) << 24; } +// std::size() does not support zero-size C arrays. We're fixing that. +template +constexpr auto Size(const C& c) -> decltype(c.size()) { + return std::size(c); +} + +template +constexpr std::size_t Size(const C& c) { + if constexpr (sizeof(C) == 0) { + return 0; + } else { + return std::size(c); + } +} + } // namespace Common -- cgit v1.2.3