aboutsummaryrefslogtreecommitdiff
path: root/lib/std/meta.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-01-19 02:40:35 -0500
committerAndrew Kelley <andrew@ziglang.org>2020-01-19 20:54:04 -0500
commita867b43366c7fb132ec44a03f9b40ead888900fb (patch)
tree13cb163c8e42f78b690481ea60bcbea97465396e /lib/std/meta.zig
parentc15623428e83bd8baa1450678bf59beab2c2df99 (diff)
downloadzig-a867b43366c7fb132ec44a03f9b40ead888900fb.tar.gz
zig-a867b43366c7fb132ec44a03f9b40ead888900fb.zip
progress towards merging
see BRANCH_TODO file
Diffstat (limited to 'lib/std/meta.zig')
-rw-r--r--lib/std/meta.zig18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/std/meta.zig b/lib/std/meta.zig
index 5e5850e393..5cb9c6589c 100644
--- a/lib/std/meta.zig
+++ b/lib/std/meta.zig
@@ -556,3 +556,21 @@ pub fn refAllDecls(comptime T: type) void {
if (!builtin.is_test) return;
_ = declarations(T);
}
+
+/// Returns a slice of pointers to public declarations of a namespace.
+pub fn declList(comptime Namespace: type, comptime Decl: type) []const *const Decl {
+ const S = struct {
+ fn declNameLessThan(lhs: *const Decl, rhs: *const Decl) bool {
+ return mem.lessThan(u8, lhs.name, rhs.name);
+ }
+ };
+ comptime {
+ const decls = declarations(Namespace);
+ var array: [decls.len]*const Decl = undefined;
+ for (decls) |decl, i| {
+ array[i] = &@field(Namespace, decl.name);
+ }
+ std.sort.sort(*const Decl, &array, S.declNameLessThan);
+ return &array;
+ }
+}