groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 11/16: [src]: Add `array_size` utility template function.


From: G. Branden Robinson
Subject: [groff] 11/16: [src]: Add `array_size` utility template function.
Date: Fri, 25 Aug 2023 14:11:19 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 6d5987c97b63589328daff049c7b0f7220bb4149
Author: G. Branden Robinson <g.branden.robinson@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 <alx@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.robinson@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.snit@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:



reply via email to

[Prev in Thread] Current Thread [Next in Thread]