summaryrefslogtreecommitdiffhomepage
path: root/compat
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-03-18 23:42:07 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-03-18 23:42:07 +0100
commit4d9a82b720c8ce74b94f43f72ddd819ef21abbdf (patch)
treec0a5d21b8e19fbb60c286faec8e302e6f32b6679 /compat
parent32b8c22828315292857e2cd9909fba620f30ff70 (diff)
pre-declare integer types without cstddef/cstdint
Diffstat (limited to 'compat')
-rw-r--r--compat/enum-bitset.hpp10
-rw-r--r--compat/format.hpp12
-rw-r--r--compat/function2.hpp96
-rw-r--r--compat/int-hash.hpp7
-rw-r--r--compat/integer-types.hpp61
-rw-r--r--compat/prelude.hpp8
6 files changed, 125 insertions, 69 deletions
diff --git a/compat/enum-bitset.hpp b/compat/enum-bitset.hpp
index ccf76434..ebbd9982 100644
--- a/compat/enum-bitset.hpp
+++ b/compat/enum-bitset.hpp
@@ -4,16 +4,16 @@
namespace floormat {
template<typename Enum, Enum COUNT_ = Enum::COUNT>
-requires (std::is_enum_v<Enum> && std::is_same_v<std::size_t, std::common_type_t<std::size_t, std::underlying_type_t<Enum>>>)
-struct enum_bitset : std::bitset<std::size_t(COUNT_)> {
+requires (std::is_enum_v<Enum> && std::is_same_v<size_t, std::common_type_t<size_t, std::underlying_type_t<Enum>>>)
+struct enum_bitset : std::bitset<size_t(COUNT_)> {
using enum_type = Enum;
using value_type = std::underlying_type_t<enum_type>;
- static constexpr auto COUNT = std::size_t{value_type(COUNT_)};
+ static constexpr auto COUNT = size_t{value_type(COUNT_)};
using std::bitset<COUNT>::bitset;
- constexpr bool operator[](Enum x) const { return std::bitset<COUNT>::operator[](std::size_t{value_type(x)}); }
- constexpr decltype(auto) operator[](Enum x) { return std::bitset<COUNT>::operator[](std::size_t{value_type(x)}); }
+ constexpr bool operator[](Enum x) const { return std::bitset<COUNT>::operator[](size_t{value_type(x)}); }
+ constexpr decltype(auto) operator[](Enum x) { return std::bitset<COUNT>::operator[](size_t{value_type(x)}); }
};
} // namespace floormat
diff --git a/compat/format.hpp b/compat/format.hpp
index bf6e8861..2a88abab 100644
--- a/compat/format.hpp
+++ b/compat/format.hpp
@@ -20,12 +20,12 @@ template<> struct formatter<Corrade::Containers::String> {
#if !FMT_USE_NONTYPE_TEMPLATE_ARGS
namespace floormat::detail::fmt {
-template<std::size_t N>
+template<size_t N>
struct fmt_string final {
- static constexpr std::size_t size = N;
+ static constexpr size_t size = N;
char data[N];
- template <std::size_t... Is>
+ template <size_t... Is>
consteval fmt_string(const char (&arr)[N]) noexcept {
for (auto i = 0_uz; i < N; i++)
data[i] = arr[i];
@@ -46,10 +46,10 @@ using namespace fmt::literals;
namespace floormat {
-template<std::size_t N, typename Fmt, typename... Xs>
-std::size_t snformat(char(&buf)[N], Fmt&& fmt, Xs&&... args)
+template<size_t N, typename Fmt, typename... Xs>
+size_t snformat(char(&buf)[N], Fmt&& fmt, Xs&&... args)
{
- constexpr std::size_t n = N > 0 ? N - 1 : 0;
+ constexpr size_t n = N > 0 ? N - 1 : 0;
auto result = fmt::format_to_n(buf, n, std::forward<Fmt>(fmt), std::forward<Xs>(args)...);
const auto len = std::min(n, result.size);
if constexpr(N > 0)
diff --git a/compat/function2.hpp b/compat/function2.hpp
index 07b40338..cd23bad9 100644
--- a/compat/function2.hpp
+++ b/compat/function2.hpp
@@ -460,13 +460,13 @@ union data_accessor {
/// The pointer we use if the object is on the heap
void* ptr_;
/// The first field of the inplace storage
- std::size_t inplace_storage_;
+ size_t inplace_storage_;
};
/// See opcode::op_fetch_empty
static FU2_DETAIL_CXX14_CONSTEXPR void write_empty(data_accessor* accessor,
bool empty) noexcept {
- accessor->inplace_storage_ = std::size_t(empty);
+ accessor->inplace_storage_ = size_t(empty);
}
template <typename From, typename To>
@@ -482,7 +482,7 @@ using transfer_volatile_t =
template <typename T, typename Accessor>
FU2_DETAIL_CXX14_CONSTEXPR auto retrieve(std::true_type /*is_inplace*/,
Accessor from,
- std::size_t from_capacity) {
+ size_t from_capacity) {
using type = transfer_const_t<Accessor, transfer_volatile_t<Accessor, void>>*;
/// Process the command by using the data inside the internal capacity
@@ -495,7 +495,7 @@ FU2_DETAIL_CXX14_CONSTEXPR auto retrieve(std::true_type /*is_inplace*/,
/// through the allocator
template <typename T, typename Accessor>
constexpr auto retrieve(std::false_type /*is_inplace*/, Accessor from,
- std::size_t /*from_capacity*/) {
+ size_t /*from_capacity*/) {
return from->ptr_;
}
@@ -591,11 +591,11 @@ using is_noexcept_noexcept = std::true_type;
template <typename Ret, typename... Args> \
struct function_trait<Ret(Args...) CONST VOLATILE OVL_REF NOEXCEPT> { \
using pointer_type = Ret (*)(data_accessor CONST VOLATILE*, \
- std::size_t capacity, Args...); \
+ size_t capacity, Args...); \
template <typename T, bool IsInplace> \
struct internal_invoker { \
static Ret invoke(data_accessor CONST VOLATILE* data, \
- std::size_t capacity, Args... args) NOEXCEPT { \
+ size_t capacity, Args... args) NOEXCEPT { \
auto obj = retrieve<T>(std::integral_constant<bool, IsInplace>{}, \
data, capacity); \
auto box = static_cast<T CONST VOLATILE*>(obj); \
@@ -608,7 +608,7 @@ using is_noexcept_noexcept = std::true_type;
\
template <typename T> \
struct view_invoker { \
- static Ret invoke(data_accessor CONST VOLATILE* data, std::size_t, \
+ static Ret invoke(data_accessor CONST VOLATILE* data, size_t, \
Args... args) NOEXCEPT { \
\
auto ptr = static_cast<void CONST VOLATILE*>(data->ptr_); \
@@ -627,7 +627,7 @@ using is_noexcept_noexcept = std::true_type;
template <bool Throws> \
struct empty_invoker { \
static Ret invoke(data_accessor CONST VOLATILE* /*data*/, \
- std::size_t /*capacity*/, Args... /*args*/) NOEXCEPT { \
+ size_t /*capacity*/, Args... /*args*/) NOEXCEPT { \
throw_or_abort##NOEXCEPT(std::integral_constant<bool, Throws>{}); \
} \
}; \
@@ -649,7 +649,7 @@ struct invoke_table<First> {
using type = function_pointer_of<First>;
/// Return the function pointer itself
- template <std::size_t Index>
+ template <size_t Index>
static constexpr auto fetch(type pointer) noexcept {
static_assert(Index == 0U, "The index should be 0 here!");
return pointer;
@@ -680,7 +680,7 @@ struct invoke_table<First, Second, Args...> {
function_pointer_of<Args>...> const*;
/// Return the function pointer at the particular index
- template <std::size_t Index>
+ template <size_t Index>
static constexpr auto fetch(type table) noexcept {
return std::get<Index>(*table);
}
@@ -756,18 +756,18 @@ struct invoke_table<First, Second, Args...> {
}
};
-template <std::size_t Index, typename Function, typename... Signatures>
+template <size_t Index, typename Function, typename... Signatures>
class operator_impl;
#define FU2_DEFINE_FUNCTION_TRAIT(CONST, VOLATILE, NOEXCEPT, OVL_REF, REF) \
- template <std::size_t Index, typename Function, typename Ret, \
+ template <size_t Index, typename Function, typename Ret, \
typename... Args, typename Next, typename... Signatures> \
class operator_impl<Index, Function, \
Ret(Args...) CONST VOLATILE OVL_REF NOEXCEPT, Next, \
Signatures...> \
: operator_impl<Index + 1, Function, Next, Signatures...> { \
\
- template <std::size_t, typename, typename...> \
+ template <size_t, typename, typename...> \
friend class operator_impl; \
\
protected: \
@@ -791,13 +791,13 @@ class operator_impl;
std::forward<Args>(args)...); \
} \
}; \
- template <std::size_t Index, typename Config, typename Property, \
+ template <size_t Index, typename Config, typename Property, \
typename Ret, typename... Args> \
class operator_impl<Index, function<Config, Property>, \
Ret(Args...) CONST VOLATILE OVL_REF NOEXCEPT> \
: copyable<!Config::is_owning || Config::is_copyable> { \
\
- template <std::size_t, typename, typename...> \
+ template <size_t, typename, typename...> \
friend class operator_impl; \
\
protected: \
@@ -847,9 +847,9 @@ template <bool IsThrowing, bool HasStrongExceptGuarantee,
class vtable<property<IsThrowing, HasStrongExceptGuarantee, FormalArgs...>> {
using command_function_t = void (*)(vtable* /*this*/, opcode /*op*/,
data_accessor* /*from*/,
- std::size_t /*from_capacity*/,
+ size_t /*from_capacity*/,
data_accessor* /*to*/,
- std::size_t /*to_capacity*/);
+ size_t /*to_capacity*/);
using invoke_table_t = invocation_table::invoke_table<FormalArgs...>;
@@ -864,8 +864,8 @@ class vtable<property<IsThrowing, HasStrongExceptGuarantee, FormalArgs...>> {
/// The command table
template <bool IsInplace>
static void process_cmd(vtable* to_table, opcode op, data_accessor* from,
- std::size_t from_capacity, data_accessor* to,
- std::size_t to_capacity) {
+ size_t from_capacity, data_accessor* to,
+ size_t to_capacity) {
switch (op) {
case opcode::op_move: {
@@ -940,7 +940,7 @@ class vtable<property<IsThrowing, HasStrongExceptGuarantee, FormalArgs...>> {
static void
construct(std::true_type /*apply*/, Box&& box, vtable* to_table,
data_accessor* to,
- std::size_t to_capacity) noexcept(HasStrongExceptGuarantee) {
+ size_t to_capacity) noexcept(HasStrongExceptGuarantee) {
// Try to allocate the object inplace
void* storage = retrieve<T>(std::true_type{}, to, to_capacity);
if (storage) {
@@ -958,14 +958,14 @@ class vtable<property<IsThrowing, HasStrongExceptGuarantee, FormalArgs...>> {
static void
construct(std::false_type /*apply*/, Box&& /*box*/, vtable* /*to_table*/,
data_accessor* /*to*/,
- std::size_t /*to_capacity*/) noexcept(HasStrongExceptGuarantee) {
+ size_t /*to_capacity*/) noexcept(HasStrongExceptGuarantee) {
}
};
/// The command table
static void empty_cmd(vtable* to_table, opcode op, data_accessor* /*from*/,
- std::size_t /*from_capacity*/, data_accessor* to,
- std::size_t /*to_capacity*/) {
+ size_t /*from_capacity*/, data_accessor* to,
+ size_t /*to_capacity*/) {
switch (op) {
case opcode::op_move:
@@ -994,31 +994,31 @@ public:
/// Initialize an object at the given position
template <typename T>
static void init(vtable& table, T&& object, data_accessor* to,
- std::size_t to_capacity) {
+ size_t to_capacity) {
trait<std::decay_t<T>>::construct(std::true_type{}, std::forward<T>(object),
&table, to, to_capacity);
}
/// Moves the object at the given position
- void move(vtable& to_table, data_accessor* from, std::size_t from_capacity,
+ void move(vtable& to_table, data_accessor* from, size_t from_capacity,
data_accessor* to,
- std::size_t to_capacity) noexcept(HasStrongExceptGuarantee) {
+ size_t to_capacity) noexcept(HasStrongExceptGuarantee) {
cmd_(&to_table, opcode::op_move, from, from_capacity, to, to_capacity);
set_empty();
}
/// Destroys the object at the given position
void copy(vtable& to_table, data_accessor const* from,
- std::size_t from_capacity, data_accessor* to,
- std::size_t to_capacity) const {
+ size_t from_capacity, data_accessor* to,
+ size_t to_capacity) const {
cmd_(&to_table, opcode::op_copy, const_cast<data_accessor*>(from),
from_capacity, to, to_capacity);
}
/// Destroys the object at the given position
void destroy(data_accessor* from,
- std::size_t from_capacity) noexcept(HasStrongExceptGuarantee) {
+ size_t from_capacity) noexcept(HasStrongExceptGuarantee) {
cmd_(this, opcode::op_destroy, from, from_capacity, nullptr, 0U);
}
@@ -1026,7 +1026,7 @@ public:
/// vtable
void
weak_destroy(data_accessor* from,
- std::size_t from_capacity) noexcept(HasStrongExceptGuarantee) {
+ size_t from_capacity) noexcept(HasStrongExceptGuarantee) {
cmd_(this, opcode::op_weak_destroy, from, from_capacity, nullptr, 0U);
}
@@ -1038,13 +1038,13 @@ public:
}
/// Invoke the function at the given index
- template <std::size_t Index, typename... Args>
+ template <size_t Index, typename... Args>
constexpr decltype(auto) invoke(Args&&... args) const {
auto thunk = invoke_table_t::template fetch<Index>(vtable_);
return thunk(std::forward<Args>(args)...);
}
/// Invoke the function at the given index
- template <std::size_t Index, typename... Args>
+ template <size_t Index, typename... Args>
constexpr decltype(auto) invoke(Args&&... args) const volatile {
auto thunk = invoke_table_t::template fetch<Index>(vtable_);
return thunk(std::forward<Args>(args)...);
@@ -1118,7 +1118,7 @@ public:
return &storage_.accessor_;
}
- static constexpr std::size_t capacity() noexcept {
+ static constexpr size_t capacity() noexcept {
return sizeof(storage_);
}
};
@@ -1128,7 +1128,7 @@ template <bool IsOwning /* = true*/, typename Config, typename Property>
class erasure : internal_capacity_holder<typename Config::capacity> {
template <bool, typename, typename>
friend class erasure;
- template <std::size_t, typename, typename...>
+ template <size_t, typename, typename...>
friend class operator_impl;
using vtable_t = tables::vtable<Property>;
@@ -1137,7 +1137,7 @@ class erasure : internal_capacity_holder<typename Config::capacity> {
public:
/// Returns the capacity of this erasure
- static constexpr std::size_t capacity() noexcept {
+ static constexpr size_t capacity() noexcept {
return internal_capacity_holder<typename Config::capacity>::capacity();
}
@@ -1262,7 +1262,7 @@ public:
///
/// We define this out of class to be able to forward the qualified
/// erasure correctly.
- template <std::size_t Index, typename Erasure, typename... Args>
+ template <size_t Index, typename Erasure, typename... Args>
static constexpr decltype(auto) invoke(Erasure&& erasure, Args&&... args) {
auto const capacity = erasure.capacity();
return erasure.vtable_.template invoke<Index>(
@@ -1278,7 +1278,7 @@ class erasure<false, Config,
property<IsThrowing, HasStrongExceptGuarantee, Args...>> {
template <bool, typename, typename>
friend class erasure;
- template <std::size_t, typename, typename...>
+ template <size_t, typename, typename...>
friend class operator_impl;
using property_t = property<IsThrowing, HasStrongExceptGuarantee, Args...>;
@@ -1378,7 +1378,7 @@ public:
return view_.ptr_ == nullptr;
}
- template <std::size_t Index, typename Erasure, typename... T>
+ template <size_t Index, typename Erasure, typename... T>
static constexpr decltype(auto) invoke(Erasure&& erasure, T&&... args) {
auto thunk = invoke_table_t::template fetch<Index>(erasure.invoke_table_);
return thunk(&(erasure.view_), 0UL, std::forward<T>(args)...);
@@ -1515,7 +1515,7 @@ class function<Config, property<IsThrowing, HasStrongExceptGuarantee, Args...>>
template <typename, typename>
friend class function;
- template <std::size_t, typename, typename...>
+ template <size_t, typename, typename...>
friend class type_erasure::invocation_table::operator_impl;
using property_t = property<IsThrowing, HasStrongExceptGuarantee, Args...>;
@@ -1708,18 +1708,18 @@ bool operator!=(std::nullptr_t, function<Config, Property> const& f) {
}
// Default intended object size of the function
-using object_size = std::integral_constant<std::size_t, 32U>;
+using object_size = std::integral_constant<size_t, 32U>;
} // namespace detail
} // namespace abi_400
/// Can be passed to function_base as template argument which causes
/// the internal small buffer to be sized according to the given size,
/// and aligned with the given alignment.
-template <std::size_t Capacity,
- std::size_t Alignment = alignof(std::max_align_t)>
+template <size_t Capacity,
+ size_t Alignment = alignof(std::max_align_t)>
struct capacity_fixed {
- static constexpr std::size_t capacity = Capacity;
- static constexpr std::size_t alignment = Alignment;
+ static constexpr size_t capacity = Capacity;
+ static constexpr size_t alignment = Alignment;
};
/// Default capacity for small functor optimization
@@ -1737,8 +1737,8 @@ struct capacity_none : capacity_fixed<0UL> {};
/// the given object without allocating memory for an applied type erasure.
template <typename T>
struct capacity_can_hold {
- static constexpr std::size_t capacity = sizeof(T);
- static constexpr std::size_t alignment = alignof(T);
+ static constexpr size_t capacity = sizeof(T);
+ static constexpr size_t alignment = alignof(T);
};
/// An adaptable function wrapper base for arbitrary functional types.
@@ -1758,8 +1758,8 @@ struct capacity_can_hold {
/// looks like the following example:
/// ```cpp
/// struct my_capacity {
-/// static constexpr std::size_t capacity = sizeof(my_type);
-/// static constexpr std::size_t alignment = alignof(my_type);
+/// static constexpr size_t capacity = sizeof(my_type);
+/// static constexpr size_t alignment = alignof(my_type);
/// };
/// ```
///
diff --git a/compat/int-hash.hpp b/compat/int-hash.hpp
index 36f0c8b8..52b4c170 100644
--- a/compat/int-hash.hpp
+++ b/compat/int-hash.hpp
@@ -1,12 +1,11 @@
#pragma once
-#include <cstddef>
#include <bit>
namespace floormat {
-constexpr inline std::size_t int_hash(std::size_t x) noexcept
+constexpr inline size_t int_hash(size_t x) noexcept
{
- if constexpr(sizeof(std::size_t) == 4)
+ if constexpr(sizeof(size_t) == 4)
{
// by Chris Wellons <https://nullprogram.com/blog/2018/07/31/>
x ^= x >> 15;
@@ -15,7 +14,7 @@ constexpr inline std::size_t int_hash(std::size_t x) noexcept
x *= 0x297a2d39U;
x ^= x >> 15;
}
- else if constexpr(sizeof(std::size_t) == 8)
+ else if constexpr(sizeof(size_t) == 8)
{
// NASAM by Pelle Evensen <https://mostlymangling.blogspot.com/2020/01/nasam-not-another-strange-acronym-mixer.html>
x ^= std::rotr(x, 25) ^ std::rotr(x, 47);
diff --git a/compat/integer-types.hpp b/compat/integer-types.hpp
new file mode 100644
index 00000000..0ec707d3
--- /dev/null
+++ b/compat/integer-types.hpp
@@ -0,0 +1,61 @@
+#pragma once
+
+namespace floormat {
+
+#ifdef _MSC_VER
+#ifdef _WIN64
+typedef unsigned __int64 size_t;
+typedef __int64 ptrdiff_t;
+typedef __int64 intptr_t;
+typedef unsigned __int64 uintptr_t;
+#else
+typedef unsigned int size_t;
+typedef int ptrdiff_t;
+typedef int intptr_t;
+typedef unsigned int uintptr_t;
+#endif
+typedef signed char int8_t;
+typedef short int16_t;
+typedef int int32_t;
+typedef long long int64_t;
+typedef long long intmax_t;
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+typedef unsigned long long uint64_t;
+typedef unsigned long long uintmax_t;
+#elif __GNUG__
+typedef __SIZE_TYPE__ size_t;
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+typedef __INTPTR_TYPE__ intptr_t;
+typedef __UINTPTR_TYPE__ uintptr_t;
+typedef __INT8_TYPE__ int8_t;
+typedef __INT16_TYPE__ int16_t;
+typedef __INT32_TYPE__ int32_t;
+typedef __INT64_TYPE__ int64_t;
+typedef __UINT8_TYPE__ uint8_t;
+typedef __UINT16_TYPE__ uint16_t;
+typedef __UINT32_TYPE__ uint32_t;
+typedef __UINT64_TYPE__ uint64_t;
+typedef __INTMAX_TYPE__ intmax_t;
+typedef __UINTMAX_TYPE__ uintmax_t;
+#else
+#include <cstddef>
+#include <cstdint>
+using ::std::size_t;
+using ::std::std::ptrdiff_t;
+using ::std::std::intptr_t;
+using ::std::std::uintptr_t;
+using ::std::int8_t;
+using ::std::int16_t;
+using ::std::int32_t;
+using ::std::int64_t;
+using ::std::intmax_t;
+using ::std::uint8_t;
+using ::std::uint16_t;
+using ::std::uint32_t;
+using ::std::uint64_t;
+using ::std::uintmax_t;
+#endif
+
+} // namespace floormat
diff --git a/compat/prelude.hpp b/compat/prelude.hpp
index 3516de98..8f011aa7 100644
--- a/compat/prelude.hpp
+++ b/compat/prelude.hpp
@@ -1,4 +1,5 @@
#pragma once
+#include "integer-types.hpp"
namespace floormat {
#ifdef _MSC_VER
@@ -31,11 +32,6 @@ template<typename T> class Vector2;
template<typename T> class Vector3;
template<typename T> class Vector4;
} // namespace Magnum::Math
-namespace Magnum {
-using Vector2uz = Math::Vector2<floormat::size_t>;
-using Vector3uz = Math::Vector3<floormat::size_t>;
-using Vector4uz = Math::Vector4<floormat::size_t>;
-} // namespace Magnum
namespace floormat {
using namespace ::Magnum;
@@ -45,6 +41,6 @@ namespace floormat {
using Debug [[maybe_unused]] = ::Corrade::Utility::Debug;
using Error [[maybe_unused]] = ::Corrade::Utility::Error;
namespace Path = Corrade::Utility::Path; // NOLINT(misc-unused-alias-decls)
- consteval auto operator""_uz(unsigned long long int x) { return ::floormat::size_t(x); }
+ consteval auto operator""_uz(unsigned long long int x) { return size_t(x); }
} // namespace floormat
namespace nlohmann { using ::floormat::operator""_uz; }