Skip to content

Commit 4271578

Browse files
committed
fold current_scope into <rsl/source_location>, add current_{function,class,namespace}
1 parent 77340f4 commit 4271578

File tree

2 files changed

+32
-66
lines changed

2 files changed

+32
-66
lines changed

include/rsl/source_location

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,36 @@ public:
7171
}
7272
};
7373

74+
consteval std::meta::info current_scope(
75+
std::meta::info ctx = std::meta::access_context::current().scope()) {
76+
return ctx;
77+
}
78+
79+
consteval std::meta::info current_function(std::meta::info scope = current_scope()) {
80+
if (is_function(scope)) {
81+
return scope;
82+
}
83+
throw "not in a function";
84+
}
85+
86+
consteval std::meta::info current_class(std::meta::info scope = current_scope()) {
87+
while (not is_namespace(scope)) {
88+
if (is_type(scope)) {
89+
return scope;
90+
}
91+
scope = parent_of(scope);
92+
}
93+
throw "not in a class";
94+
}
95+
96+
consteval std::meta::info current_namespace(std::meta::info scope = current_scope()) {
97+
while (scope != ^^::) {
98+
if (is_namespace(scope)) {
99+
return scope;
100+
}
101+
scope = parent_of(scope);
102+
}
103+
return ^^::;
104+
}
105+
74106
} // namespace rsl

include/rsl/utility

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)