summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--compat/non-const.hpp15
-rw-r--r--serialize/savegame.cpp11
2 files changed, 16 insertions, 10 deletions
diff --git a/compat/non-const.hpp b/compat/non-const.hpp
new file mode 100644
index 00000000..f04827b7
--- /dev/null
+++ b/compat/non-const.hpp
@@ -0,0 +1,15 @@
+#pragma once
+
+namespace floormat {
+
+template<typename T> T& non_const(const T& value) { return const_cast<T&>(value); }
+template<typename T> T& non_const(T& value) = delete;
+template<typename T> T& non_const(T&&) = delete;
+template<typename T> T& non_const(const T&& value) = delete;
+
+template<typename T> T& non_const_(const T& value) { return const_cast<T&>(value); }
+template<typename T> T& non_const_(T& value) { return value; }
+template<typename T> T& non_const_(T&& value) { return static_cast<T&>(value); }
+template<typename T> T& non_const_(const T&& value) { return static_cast<T&>(const_cast<T&&>(value)); }
+
+} // namespace floormat
diff --git a/serialize/savegame.cpp b/serialize/savegame.cpp
index 0c664eed..ef46a3f9 100644
--- a/serialize/savegame.cpp
+++ b/serialize/savegame.cpp
@@ -1,6 +1,7 @@
#include "binary-writer.inl"
#include "binary-reader.inl"
#include "compat/defs.hpp"
+#include "compat/non-const.hpp"
#include "compat/strerror.hpp"
#include "compat/int-hash.hpp"
#include "compat/exception.hpp"
@@ -66,16 +67,6 @@ template<typename T> concept Number = std::is_arithmetic_v<std::remove_cvref_t<T
template<typename T> concept Enum = std::is_enum_v<std::remove_cvref_t<T>>;
template<typename T> concept Vector = Math::IsVector<std::remove_cvref_t<T>>::value;
-template<typename T> [[maybe_unused]] T& non_const(const T& value) { return const_cast<T&>(value); }
-template<typename T> [[maybe_unused]] T& non_const(T& value) = delete;
-template<typename T> [[maybe_unused]] T& non_const(T&&) = delete;
-template<typename T> [[maybe_unused]] T& non_const(const T&& value) = delete;
-
-template<typename T> [[maybe_unused]] T& non_const_(const T& value) { return const_cast<T&>(value); }
-template<typename T> [[maybe_unused]] T& non_const_(T& value) { return value; }
-template<typename T> [[maybe_unused]] T& non_const_(T&& value) { return static_cast<T&>(value); }
-template<typename T> [[maybe_unused]] T& non_const_(const T&& value) { return static_cast<T&>(const_cast<T&&>(value)); }
-
struct buffer
{
std::unique_ptr<char[]> data;