summaryrefslogtreecommitdiffhomepage
path: root/compat
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-02-28 18:19:24 +0100
committerStanislaw Halik <sthalik@misaki.pl>2024-02-28 20:13:32 +0100
commit75508e3c03f659080df7db2211fb5a80cc1afeee (patch)
tree5c67ed99da49bd45db0a3dc1de27dc3607d3bedc /compat
parent079f3aa5f99125f76d39cd7c08fc1a388981089d (diff)
compat: add ADL-safe {move,forward,swap}
Diffstat (limited to 'compat')
-rw-r--r--compat/move.hpp38
-rw-r--r--compat/prelude.hpp1
2 files changed, 39 insertions, 0 deletions
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 <type_traits>
+
+namespace floormat {
+
+template<typename T> concept AlwaysTrue = true;
+
+// from Corrade/Utility/Move.h
+
+template<AlwaysTrue T>
+constexpr T&& forward(std::remove_reference_t<T>& t) noexcept
+{
+ return static_cast<T&&>(t);
+}
+
+template<AlwaysTrue T>
+constexpr T&& forward(std::remove_reference_t<T>&& t) noexcept
+{
+ static_assert(!std::is_lvalue_reference_v<T>);
+ return static_cast<T&&>(t);
+}
+
+template<AlwaysTrue T>
+constexpr std::remove_reference_t<T>&& move(T&& t) noexcept
+{
+ return static_cast<std::remove_reference_t<T>&&>(t);
+}
+
+template<AlwaysTrue T>
+void swap(T& a, std::common_type_t<T>& b)
+noexcept(std::is_nothrow_move_constructible_v<T> && std::is_nothrow_move_assignable_v<T>)
+{
+ T tmp = static_cast<T&&>(a);
+ a = static_cast<T&&>(b);
+ b = static_cast<T&&>(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 <type_traits>
#include <Corrade/Tags.h>
#include <Corrade/Utility/Macros.h>