From ac660dcf3dd705373d95dbee34d308e48b5dbcbb Mon Sep 17 00:00:00 2001 From: John Maguire Date: Thu, 14 Jan 2016 16:14:13 +0000 Subject: [PATCH] Use a simpler arraysize() implementation. --- ext/libclementine-common/core/arraysize.h | 39 +++-------------------- 1 file changed, 5 insertions(+), 34 deletions(-) diff --git a/ext/libclementine-common/core/arraysize.h b/ext/libclementine-common/core/arraysize.h index ff43e200b..0036bda87 100644 --- a/ext/libclementine-common/core/arraysize.h +++ b/ext/libclementine-common/core/arraysize.h @@ -1,34 +1,5 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// From Chromium src/base/macros.h - -#include // For size_t. - -// The arraysize(arr) macro returns the # of elements in an array arr. -// The expression is a compile-time constant, and therefore can be -// used in defining new arrays, for example. If you use arraysize on -// a pointer by mistake, you will get a compile-time error. -// -// One caveat is that arraysize() doesn't accept any array of an -// anonymous type or a type defined inside a function. In these rare -// cases, you have to use the unsafe ARRAYSIZE_UNSAFE() macro below. This is -// due to a limitation in C++'s template system. The limitation might -// eventually be removed, but it hasn't happened yet. - -// This template function declaration is used in defining arraysize. -// Note that the function doesn't need an implementation, as we only -// use its type. -template -char (&ArraySizeHelper(T (&array)[N]))[N]; - -// That gcc wants both of these prototypes seems mysterious. VC, for -// its part, can't decide which to use (another mystery). Matching of -// template overloads: the final frontier. -#ifndef _MSC_VER -template -char (&ArraySizeHelper(const T (&array)[N]))[N]; -#endif - -#define arraysize(array) (sizeof(ArraySizeHelper(array))) +template +constexpr size_t arraysize(const T&) { + static_assert(std::is_array::value, "Argument must be array"); + return std::extent::value; +}