2021-08-29 22:15:18 +02:00
|
|
|
#pragma once
|
|
|
|
|
2021-09-09 01:56:48 +02:00
|
|
|
#include <hex.hpp>
|
|
|
|
|
2021-08-29 22:15:18 +02:00
|
|
|
#include <type_traits>
|
2022-02-27 23:25:39 +01:00
|
|
|
#include <memory>
|
2021-08-29 22:15:18 +02:00
|
|
|
|
|
|
|
namespace hex {
|
|
|
|
|
|
|
|
template<typename>
|
|
|
|
struct is_integral_helper : public std::false_type { };
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct is_integral_helper<u8> : public std::true_type { };
|
|
|
|
|
|
|
|
template<>
|
2022-01-22 22:37:52 +01:00
|
|
|
struct is_integral_helper<i8> : public std::true_type { };
|
2021-08-29 22:15:18 +02:00
|
|
|
|
|
|
|
template<>
|
|
|
|
struct is_integral_helper<u16> : public std::true_type { };
|
|
|
|
|
|
|
|
template<>
|
2022-01-22 22:37:52 +01:00
|
|
|
struct is_integral_helper<i16> : public std::true_type { };
|
2021-08-29 22:15:18 +02:00
|
|
|
|
|
|
|
template<>
|
|
|
|
struct is_integral_helper<u32> : public std::true_type { };
|
|
|
|
|
|
|
|
template<>
|
2022-01-22 22:37:52 +01:00
|
|
|
struct is_integral_helper<i32> : public std::true_type { };
|
2021-08-29 22:15:18 +02:00
|
|
|
|
|
|
|
template<>
|
|
|
|
struct is_integral_helper<u64> : public std::true_type { };
|
|
|
|
|
|
|
|
template<>
|
2022-01-22 22:37:52 +01:00
|
|
|
struct is_integral_helper<i64> : public std::true_type { };
|
2021-08-29 22:15:18 +02:00
|
|
|
|
|
|
|
template<>
|
|
|
|
struct is_integral_helper<u128> : public std::true_type { };
|
|
|
|
|
|
|
|
template<>
|
2022-01-22 22:37:52 +01:00
|
|
|
struct is_integral_helper<i128> : public std::true_type { };
|
2021-08-29 22:15:18 +02:00
|
|
|
|
|
|
|
template<>
|
|
|
|
struct is_integral_helper<bool> : public std::true_type { };
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct is_integral_helper<char> : public std::true_type { };
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct is_integral_helper<char8_t> : public std::true_type { };
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct is_integral_helper<char16_t> : public std::true_type { };
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct is_integral_helper<char32_t> : public std::true_type { };
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct is_integral_helper<wchar_t> : public std::true_type { };
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct is_integral : public is_integral_helper<std::remove_cvref_t<T>>::type { };
|
|
|
|
|
|
|
|
|
2021-09-09 01:56:48 +02:00
|
|
|
template<typename>
|
|
|
|
struct is_signed_helper : public std::false_type { };
|
2021-08-29 22:15:18 +02:00
|
|
|
|
2021-09-09 01:56:48 +02:00
|
|
|
template<>
|
2022-01-22 22:37:52 +01:00
|
|
|
struct is_signed_helper<i8> : public std::true_type { };
|
2021-08-29 22:15:18 +02:00
|
|
|
|
2021-09-09 01:56:48 +02:00
|
|
|
template<>
|
2022-01-22 22:37:52 +01:00
|
|
|
struct is_signed_helper<i16> : public std::true_type { };
|
2021-08-29 22:15:18 +02:00
|
|
|
|
2021-09-09 01:56:48 +02:00
|
|
|
template<>
|
2022-01-22 22:37:52 +01:00
|
|
|
struct is_signed_helper<i32> : public std::true_type { };
|
2021-08-29 22:15:18 +02:00
|
|
|
|
2021-09-09 01:56:48 +02:00
|
|
|
template<>
|
2022-01-22 22:37:52 +01:00
|
|
|
struct is_signed_helper<i64> : public std::true_type { };
|
2021-08-29 22:15:18 +02:00
|
|
|
|
2021-09-09 01:56:48 +02:00
|
|
|
template<>
|
2022-01-22 22:37:52 +01:00
|
|
|
struct is_signed_helper<i128> : public std::true_type { };
|
2021-08-29 22:15:18 +02:00
|
|
|
|
2021-09-09 01:56:48 +02:00
|
|
|
template<>
|
|
|
|
struct is_signed_helper<char> : public std::true_type { };
|
2021-08-29 22:15:18 +02:00
|
|
|
|
2021-09-09 01:56:48 +02:00
|
|
|
template<>
|
|
|
|
struct is_signed_helper<float> : public std::true_type { };
|
2021-08-29 22:15:18 +02:00
|
|
|
|
2021-09-09 01:56:48 +02:00
|
|
|
template<>
|
|
|
|
struct is_signed_helper<double> : public std::true_type { };
|
2021-08-29 22:15:18 +02:00
|
|
|
|
2021-09-09 01:56:48 +02:00
|
|
|
template<>
|
|
|
|
struct is_signed_helper<long double> : public std::true_type { };
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct is_signed : public is_signed_helper<std::remove_cvref_t<T>>::type { };
|
2021-08-29 22:15:18 +02:00
|
|
|
|
|
|
|
|
2021-09-09 01:56:48 +02:00
|
|
|
template<typename>
|
|
|
|
struct is_floating_point_helper : public std::false_type { };
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct is_floating_point_helper<float> : public std::true_type { };
|
2021-08-29 22:15:18 +02:00
|
|
|
|
2021-09-09 01:56:48 +02:00
|
|
|
template<>
|
|
|
|
struct is_floating_point_helper<double> : public std::true_type { };
|
2021-08-29 22:15:18 +02:00
|
|
|
|
2021-09-09 01:56:48 +02:00
|
|
|
template<>
|
|
|
|
struct is_floating_point_helper<long double> : public std::true_type { };
|
2021-08-29 22:15:18 +02:00
|
|
|
|
2021-09-09 01:56:48 +02:00
|
|
|
template<typename T>
|
|
|
|
struct is_floating_point : public is_floating_point_helper<std::remove_cvref_t<T>>::type { };
|
2021-08-29 22:15:18 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION <= 12000
|
2022-01-24 20:53:17 +01:00
|
|
|
#if __has_include(<concepts>)
|
|
|
|
// Make sure we break when derived_from is implemented in libc++. Then we can fix a compatibility version above
|
|
|
|
#include <concepts>
|
|
|
|
#endif
|
2021-08-29 22:15:18 +02:00
|
|
|
// libcxx 12 still doesn't have many default concepts implemented, as a result we need to define it ourself using clang built-ins.
|
|
|
|
// [concept.derived] (patch from https://reviews.llvm.org/D74292)
|
|
|
|
namespace hex {
|
2022-01-24 20:53:17 +01:00
|
|
|
template<class _Dp, class _Bp>
|
|
|
|
concept derived_from =
|
|
|
|
__is_base_of(_Bp, _Dp) && __is_convertible_to(const volatile _Dp *, const volatile _Bp *);
|
2021-08-29 22:15:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
2022-01-24 20:53:17 +01:00
|
|
|
// Assume supported
|
|
|
|
#include <concepts>
|
2021-08-29 22:15:18 +02:00
|
|
|
namespace hex {
|
|
|
|
using std::derived_from;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// [concepts.arithmetic]
|
|
|
|
namespace hex {
|
2021-09-09 01:56:48 +02:00
|
|
|
|
2021-08-29 22:15:18 +02:00
|
|
|
template<class T>
|
|
|
|
concept integral = hex::is_integral<T>::value;
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
concept signed_integral = integral<T> && hex::is_signed<T>::value;
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
concept unsigned_integral = integral<T> && !signed_integral<T>;
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
concept floating_point = std::is_floating_point<T>::value;
|
2021-09-09 01:56:48 +02:00
|
|
|
|
2021-08-29 22:15:18 +02:00
|
|
|
}
|
|
|
|
|
2021-08-30 19:12:19 +02:00
|
|
|
namespace hex {
|
|
|
|
|
|
|
|
template<typename T>
|
2022-01-24 20:53:17 +01:00
|
|
|
struct always_false : std::false_type { };
|
2021-08-30 19:12:19 +02:00
|
|
|
|
|
|
|
template<typename T, size_t Size>
|
|
|
|
concept has_size = sizeof(T) == Size;
|
|
|
|
|
|
|
|
}
|
2022-01-31 14:37:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
namespace hex {
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class Cloneable {
|
|
|
|
public:
|
2022-02-27 23:25:39 +01:00
|
|
|
[[nodiscard]] virtual std::unique_ptr<T> clone() const = 0;
|
2022-01-31 14:37:12 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|