[common] add GetArrayLength() and GetArrayEnd() (#7413)

This commit adds two inline template functions to get the length of an
array and a pointer to the end of the array. These functions replace
similar macros that were used with OT core modules. The template
functions are safer to use since they would perform type checking at
compile time. The functions validate that the input variable is
indeed an array and unlike the macros they will not work with a
pointer variable.
This commit is contained in:
Abtin Keshavarzian
2022-02-14 14:03:23 -08:00
committed by GitHub
parent 49918c7f8e
commit 7ec658e47a
33 changed files with 144 additions and 55 deletions
+2 -1
View File
@@ -34,6 +34,7 @@
#include "notifier.hpp"
#include "border_router/routing_manager.hpp"
#include "common/array.hpp"
#include "common/code_utils.hpp"
#include "common/debug.hpp"
#include "common/locator_getters.hpp"
@@ -289,7 +290,7 @@ const char *Notifier::EventToString(Event aEvent) const
"PndDset", // kEventPendingDatasetChanged (1 << 29)
};
for (uint8_t index = 0; index < OT_ARRAY_LENGTH(kEventStrings); index++)
for (uint8_t index = 0; index < GetArrayLength(kEventStrings); index++)
{
if (static_cast<uint32_t>(aEvent) == (1U << index))
{