summaryrefslogtreecommitdiffhomepage
path: root/compat
diff options
context:
space:
mode:
Diffstat (limited to 'compat')
-rw-r--r--compat/defs.hpp2
-rw-r--r--compat/int-hash.cpp13
-rw-r--r--compat/int-hash.hpp4
-rw-r--r--compat/is-complete.hpp21
-rw-r--r--compat/map.hpp2
-rw-r--r--compat/safe-ptr.hpp35
6 files changed, 43 insertions, 34 deletions
diff --git a/compat/defs.hpp b/compat/defs.hpp
index edefbb5e..6f3c9ab2 100644
--- a/compat/defs.hpp
+++ b/compat/defs.hpp
@@ -89,3 +89,5 @@
#ifndef fm_ASAN
#define fm_ASAN 0
#endif
+
+#define fm_FILENAME_MAX 260
diff --git a/compat/int-hash.cpp b/compat/int-hash.cpp
index 3c85a436..35422486 100644
--- a/compat/int-hash.cpp
+++ b/compat/int-hash.cpp
@@ -1,5 +1,6 @@
#include "compat/defs.hpp"
#include "int-hash.hpp"
+#include <Corrade/Containers/StringView.h>
#include <bit>
namespace floormat {
@@ -78,15 +79,9 @@ fm_UNROLL_8
return hash;
}
-size_t hash_int(uint32_t x) noexcept
-{
- return fnvhash_uint_32(x);
-}
-
-size_t hash_int(uint64_t x) noexcept
-{
- return fnvhash_uint_64(x);
-}
+size_t hash_int(uint32_t x) noexcept { return fnvhash_uint_32(x); }
+size_t hash_int(uint64_t x) noexcept { return fnvhash_uint_64(x); }
+size_t hash_string_view::operator()(StringView s) const noexcept { return Hash::fnvhash_buf(s.data(), s.size()); }
} // namespace floormat
diff --git a/compat/int-hash.hpp b/compat/int-hash.hpp
index a5d6b147..27f2651f 100644
--- a/compat/int-hash.hpp
+++ b/compat/int-hash.hpp
@@ -1,5 +1,7 @@
#pragma once
+// todo rename to hash-fnv.hpp
+
namespace floormat::Hash {
template<size_t N = sizeof nullptr * 8> struct fnvhash_params;
@@ -20,4 +22,6 @@ uint32_t hash_32(const void* buf, size_t size) noexcept;
size_t hash_int(uint32_t x) noexcept;
size_t hash_int(uint64_t x) noexcept;
+struct hash_string_view { size_t operator()(StringView str) const noexcept; };
+
} // namespace floormat
diff --git a/compat/is-complete.hpp b/compat/is-complete.hpp
new file mode 100644
index 00000000..d6bba88b
--- /dev/null
+++ b/compat/is-complete.hpp
@@ -0,0 +1,21 @@
+#pragma once
+
+namespace floormat::detail_type_traits {
+
+namespace { template<class T> class IsComplete_ {
+ // from <Corrade/Containers/Pointer.h>
+ template<class U> static char get(U*, decltype(sizeof(U))* = nullptr);
+ static short get(...);
+ public:
+ enum: bool { value = sizeof(get(static_cast<T*>(nullptr))) == sizeof(char) };
+}; } // namespace
+
+} // namespace floormat::detail_type_traits
+
+namespace floormat {
+
+template<typename T>
+constexpr inline bool is_complete =
+ bool(::floormat::detail_type_traits::IsComplete_<T>::value);
+
+} // namespace floormat
diff --git a/compat/map.hpp b/compat/map.hpp
index 3c1610d4..860b4d77 100644
--- a/compat/map.hpp
+++ b/compat/map.hpp
@@ -32,7 +32,7 @@ constexpr auto map(const F& fun, const std::array<T, N>& array)
using return_type = std::decay_t<decltype( fun(array[0]) )>;
static_assert(!std::is_same_v<return_type, void>);
static_assert(std::is_same_v<T, std::decay_t<T>>);
- static_assert(sizeof(return_type) > 0);
+ static_assert(sizeof(return_type));
using ::floormat::detail::map::map0;
return map0(fun, array, std::make_index_sequence<N>{});
}
diff --git a/compat/safe-ptr.hpp b/compat/safe-ptr.hpp
index 0882f3be..95cd3bae 100644
--- a/compat/safe-ptr.hpp
+++ b/compat/safe-ptr.hpp
@@ -13,41 +13,26 @@ class safe_ptr final
T* ptr;
public:
- template<typename... Ts>
- requires requires (Ts&&... xs) {
- new T{Utility::forward<Ts>(xs)...};
- }
- safe_ptr(InPlaceInitT, Ts&&... args) noexcept:
- ptr{new T{Utility::forward<Ts>(args)...}}
- {}
-
- explicit safe_ptr(T*&& ptr) noexcept: ptr{ptr}
- {
- fm_assert(ptr != nullptr);
- ptr = nullptr;
- }
-
~safe_ptr() noexcept
{
- if (ptr) [[likely]]
- delete ptr;
+ delete ptr;
ptr = (T*)0xbadcafedeadbabe;
}
- explicit safe_ptr(safe_ptr&& other) noexcept: ptr{other.ptr}
- {
- other.ptr = nullptr;
- }
+ safe_ptr(std::nullptr_t) = delete;
+ safe_ptr(T* ptr) noexcept: ptr{ptr} { fm_assert(ptr != nullptr); }
+ safe_ptr(safe_ptr&& other) noexcept: ptr{other.ptr} { other.ptr = nullptr; }
+
+ safe_ptr() noexcept: safe_ptr{InPlaceInit} {}
- explicit safe_ptr() noexcept:
- ptr{new T{}}
+ template<typename... Ts> safe_ptr(InPlaceInitT, Ts&&... args) noexcept:
+ ptr(new T{ Utility::forward<Ts>(args)... })
{}
safe_ptr& operator=(safe_ptr&& other) noexcept
{
fm_assert(this != &other);
- if (ptr) [[likely]]
- delete ptr;
+ delete ptr;
ptr = other.ptr;
other.ptr = nullptr;
return *this;
@@ -57,6 +42,8 @@ public:
//explicit operator bool() const noexcept { return ptr != nullptr; }
+ T* get() noexcept { return ptr; }
+ const T* get() const noexcept { return ptr; }
const T& operator*() const noexcept { return *ptr; }
T& operator*() noexcept { return *ptr; }
const T* operator->() const noexcept { return ptr; }