Skip to content

Commit c0ad37c

Browse files
committed
clean up source_location
1 parent 7008b96 commit c0ad37c

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

include/rsl/source_location

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ class source_location {
2424

2525
template <std::meta::access_context R, RawSloc Data>
2626
consteval static SourceContext const* make_context() {
27-
struct SourceContextImpl : SourceContext {
27+
struct SourceContextImpl final : SourceContext {
2828
using SourceContext::SourceContext;
29-
consteval virtual std::meta::info scope() const { return R.scope(); }
30-
consteval virtual std::meta::access_context access_context() const { return R; }
29+
consteval std::meta::info scope() const override { return R.scope(); }
30+
consteval std::meta::access_context access_context() const override { return R; }
3131
};
3232
constexpr static SourceContextImpl obj{Data};
3333
return &obj;
@@ -45,29 +45,35 @@ public:
4545
// public to avoid violating rules for structural types
4646
SourceContext const* _impl_sloc = make_context<std::meta::access_context::unchecked(), {}>();
4747
consteval source_location() noexcept = default;
48-
49-
consteval static source_location current(
50-
std::source_location sloc = std::source_location::current(),
51-
std::meta::access_context ctx = std::meta::access_context::current()) {
52-
auto base = RawSloc{define_static_string(std::string_view(sloc.file_name())),
48+
consteval explicit(false)
49+
source_location(std::source_location const& sloc,
50+
std::meta::access_context ctx = std::meta::access_context::current()) {
51+
auto base = RawSloc{define_static_string(std::string_view(sloc.file_name())),
5352
define_static_string(std::string_view(sloc.function_name())),
5453
sloc.line(),
5554
sloc.column()};
55+
_impl_sloc = extract<SourceContext const*>(
56+
substitute(^^_impl_context, {reflect_constant(ctx), std::meta::reflect_constant(base)}));
57+
}
5658

59+
consteval static source_location current(
60+
std::source_location sloc = std::source_location::current(),
61+
std::meta::access_context ctx = std::meta::access_context::current()) {
5762
// TODO: with gcc we can use make_context directly - _impl_context is a workaround for clang
58-
return source_location{extract<SourceContext const*>(
59-
substitute(^^_impl_context, {reflect_constant(ctx), std::meta::reflect_constant(base)}))};
63+
return {sloc, ctx};
6064
}
6165

6266
// TODO wrap file_name and function_name in rsl::cstring_view as soon as implemented
63-
constexpr char const* file_name() const noexcept { return _impl_sloc->file_name; }
64-
constexpr char const* function_name() const noexcept { return _impl_sloc->function_name; }
65-
constexpr unsigned line() const noexcept { return _impl_sloc->line; }
66-
constexpr unsigned column() const noexcept { return _impl_sloc->column; }
67+
[[nodiscard]] constexpr char const* file_name() const noexcept { return _impl_sloc->file_name; }
68+
[[nodiscard]] constexpr char const* function_name() const noexcept {
69+
return _impl_sloc->function_name;
70+
}
71+
[[nodiscard]] constexpr unsigned line() const noexcept { return _impl_sloc->line; }
72+
[[nodiscard]] constexpr unsigned column() const noexcept { return _impl_sloc->column; }
6773

6874
// consteval-only extensions
69-
consteval std::meta::info scope() const noexcept { return _impl_sloc->scope(); }
70-
consteval std::meta::access_context access_context() const noexcept {
75+
[[nodiscard]] consteval std::meta::info scope() const noexcept { return _impl_sloc->scope(); }
76+
[[nodiscard]] consteval std::meta::access_context access_context() const noexcept {
7177
return _impl_sloc->access_context();
7278
}
7379
};

0 commit comments

Comments
 (0)