Created an ArraySize utility function.
[ Merge of http://go/wvgerrit/82232 ] The new function `ArraySize` will only work for compile-time fixed-length arrays, and will provide compiler errors if the provided argument is not an array. This will replace the commonly used macro `N_ELEM()` which uses `sizeof()`. Test: Linux unittest Bug: 137041745 Change-Id: I0f5c268197a8062a99ccba43c73349e97f66eb02
This commit is contained in:
20
libwvdrmengine/cdm/util/include/arraysize.h
Normal file
20
libwvdrmengine/cdm/util/include/arraysize.h
Normal file
@@ -0,0 +1,20 @@
|
||||
// Copyright 2019 Google LLC. All Rights Reserved. This file and proprietary
|
||||
// source code may only be used and distributed under the Widevine Master
|
||||
// License Agreement.
|
||||
|
||||
#ifndef WVCDM_UTIL_ARRAYSIZE_H_
|
||||
#define WVCDM_UTIL_ARRAYSIZE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
// Returns the size of a fixed-length array.
|
||||
template <typename T, size_t N>
|
||||
constexpr size_t ArraySize(const T (&)[N]) {
|
||||
return N;
|
||||
}
|
||||
|
||||
} // namespace wvcdm
|
||||
|
||||
#endif // WVCDM_UTIL_ARRAYSIZE_H_
|
||||
Reference in New Issue
Block a user