gbranden pushed a commit to branch master in repository groff. commit 6d5987c97b63589328daff049c7b0f7220bb4149 Author: G. Branden Robinson <g.branden.robin...@gmail.com> AuthorDate: Mon Aug 7 11:15:26 2023 -0500
[src]: Add `array_size` utility template function. [src]: Add template function for obtaining the length of an array. * src/include/lib.h (array_size) [__cplusplus]: Do it. Reported-by: Alejandro Colomar <a...@kernel.org> --- ChangeLog | 7 +++++++ src/include/lib.h | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/ChangeLog b/ChangeLog index d7e191cac..cfabc5417 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2023-08-24 G. Branden Robinson <g.branden.robin...@gmail.com> + + [src]: Add template function for obtaining the length of an + array. + + * src/include/lib.h (array_size) [__cplusplus]: Do it. + 2023-08-22 Dave Kemper <saint.s...@gmail.com> * doc/pic.ms: Document `PY` macro, new to groff 1.23.0. diff --git a/src/include/lib.h b/src/include/lib.h index 6b1d854e0..841f0ed99 100644 --- a/src/include/lib.h +++ b/src/include/lib.h @@ -152,6 +152,14 @@ int mksdir(char *tmpl); static const double PI = 3.14159265358979323846; +#ifdef __cplusplus +template <typename T, size_t N> +// constexpr // C++11 +size_t array_size(T(&)[N]) { + return N; +} +#endif + #endif /* GROFF_LIB_H */ // Local Variables: _______________________________________________ Groff-commit mailing list Groff-commit@gnu.org https://lists.gnu.org/mailman/listinfo/groff-commit