Two small refactors

This commit is contained in:
Jeremy 2023-09-30 03:36:07 -04:00
parent d6f6617c14
commit e82f6e360f
No known key found for this signature in database
GPG Key ID: 19AA8270105E8EB4
2 changed files with 8 additions and 11 deletions

View File

@ -169,12 +169,13 @@ namespace detail {
typename std::enable_if<!std::is_same<typename std::decay<T>::type, void>::value, int>::type = 0
>
class optional {
bool holds_value = false;
union {
char x;
T uvalue;
};
bool holds_value = false;
public:
optional() noexcept {}
@ -201,7 +202,7 @@ namespace detail {
optional& operator=(const optional& other) {
optional copy(other);
swap(*this, copy);
swap(copy);
return *this;
}
@ -229,12 +230,8 @@ namespace detail {
typename std::enable_if<!std::is_same<typename std::decay<U>::type, optional<T>>::value, int>::type = 0
>
optional& operator=(U&& value) {
if(holds_value) {
uvalue = std::forward<U>(value);
} else {
new (static_cast<void*>(std::addressof(uvalue))) T(std::forward<U>(value));
holds_value = true;
}
optional o(std::move(value));
swap(o);
return *this;
}

View File

@ -51,7 +51,7 @@ namespace detail {
}
std::vector<stacktrace_frame> resolve_frames(const std::vector<object_frame>& frames) {
std::vector<stacktrace_frame> trace(frames.size(), stacktrace_frame { 0, 0, UINT_LEAST32_MAX, "", "" });
std::vector<stacktrace_frame> trace(frames.size(), null_frame);
#if defined(CPPTRACE_GET_SYMBOLS_WITH_LIBDL) \
|| defined(CPPTRACE_GET_SYMBOLS_WITH_DBGHELP) \
|| defined(CPPTRACE_GET_SYMBOLS_WITH_LIBBACKTRACE)
@ -87,7 +87,7 @@ namespace detail {
|| defined(CPPTRACE_GET_SYMBOLS_WITH_ADDR2LINE)
auto dlframes = get_frames_object_info(frames);
#endif
std::vector<stacktrace_frame> trace(frames.size(), stacktrace_frame { 0, 0, UINT_LEAST32_MAX, "", "" });
std::vector<stacktrace_frame> trace(frames.size(), null_frame);
#ifdef CPPTRACE_GET_SYMBOLS_WITH_LIBDL
apply_trace(trace, libdl::resolve_frames(frames));
#endif