diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-11-26 13:17:08 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-11-26 13:17:08 +0100 |
commit | 708fe55ce0a26d2cd90280deeb65df186e1defcd (patch) | |
tree | 5c5bb98b0792e768e28e3f5952883d483c920589 /compat | |
parent | e8ac228ea8ea6f760d2af63a3dc006eca81b8703 (diff) |
a
Diffstat (limited to 'compat')
-rw-r--r-- | compat/debug.hpp | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/compat/debug.hpp b/compat/debug.hpp index 4de2e5ea..cb36e612 100644 --- a/compat/debug.hpp +++ b/compat/debug.hpp @@ -1,6 +1,7 @@ #pragma once #include <Corrade/Utility/Debug.h> -#include <Corrade/Containers/Containers.h> +#include <Corrade/Utility/Move.h> +#include <Corrade/Containers/StringView.h> #include <concepts> namespace floormat { @@ -23,7 +24,12 @@ struct ErrorString { int value; }; Debug& operator<<(Debug& dbg, ErrorString box); // ***** quoted ***** -template<typename T> struct Quoted { const T& value; char c; }; +template<typename T> struct Quoted +{ + using type = T; + T value; char c; +}; + Debug::Flags quoted_begin(Debug& dbg, char c); Debug& quoted_end(Debug& dbg, Debug::Flags flags, char c); @@ -46,7 +52,17 @@ floormat::detail::corrade_debug::Colon colon(char c = ':'); floormat::detail::corrade_debug::ErrorString error_string(int error); floormat::detail::corrade_debug::ErrorString error_string(); -template<DebugPrintable T> floormat::detail::corrade_debug::Quoted<T> quoted(const T& value, char c = '\'') { return { value, c }; } -template<DebugPrintable T> floormat::detail::corrade_debug::Quoted<T> quoted2(const T& value) { return { value, '"' }; } +template<DebugPrintable T> +auto quoted(T&& value, char c = '\'') +{ + using U = std::remove_cvref_t<T>; + using floormat::detail::corrade_debug::Quoted; + if constexpr(std::is_rvalue_reference_v<decltype(value)>) + return Quoted<U>{ .value = Utility::move(value), .c = c }; + else + return Quoted<const U&>{ .value = value, .c = c }; +} + +template<DebugPrintable T> auto quoted2(T&& value) { return quoted(Utility::forward<T>(value), '"'); } } // namespace floormat |