From 75508e3c03f659080df7db2211fb5a80cc1afeee Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 28 Feb 2024 18:19:24 +0100 Subject: compat: add ADL-safe {move,forward,swap} --- compat/move.hpp | 38 ++++++++++++++++++++++++++++++++++++++ compat/prelude.hpp | 1 + 2 files changed, 39 insertions(+) create mode 100644 compat/move.hpp diff --git a/compat/move.hpp b/compat/move.hpp new file mode 100644 index 00000000..483de82b --- /dev/null +++ b/compat/move.hpp @@ -0,0 +1,38 @@ +#pragma once +#include + +namespace floormat { + +template concept AlwaysTrue = true; + +// from Corrade/Utility/Move.h + +template +constexpr T&& forward(std::remove_reference_t& t) noexcept +{ + return static_cast(t); +} + +template +constexpr T&& forward(std::remove_reference_t&& t) noexcept +{ + static_assert(!std::is_lvalue_reference_v); + return static_cast(t); +} + +template +constexpr std::remove_reference_t&& move(T&& t) noexcept +{ + return static_cast&&>(t); +} + +template +void swap(T& a, std::common_type_t& b) +noexcept(std::is_nothrow_move_constructible_v && std::is_nothrow_move_assignable_v) +{ + T tmp = static_cast(a); + a = static_cast(b); + b = static_cast(tmp); +} + +} // namespace floormat diff --git a/compat/prelude.hpp b/compat/prelude.hpp index 847b378f..4f76fae8 100644 --- a/compat/prelude.hpp +++ b/compat/prelude.hpp @@ -1,5 +1,6 @@ #pragma once #include "integer-types.hpp" +#include "move.hpp" #include #include #include -- cgit v1.2.3