remove some cv from type traits

This commit is contained in:
BlackMATov
2024-02-04 22:34:35 +07:00
parent 41bba15c1b
commit 02089116b9
14 changed files with 141 additions and 22 deletions

View File

@@ -5,7 +5,6 @@
- type conversions
- fix all includes to work with the library more flexible
- test and support shared libraries
- add volatile support for uarg/variable
## Version 1.0

View File

@@ -16,6 +16,34 @@ TEST_CASE("meta/meta_types/array_type") {
CHECK_FALSE(type.is_valid());
}
SUBCASE("traits") {
using meta::detail::array_traits;
static_assert(array_traits<int[]>::extent == 0);
static_assert(array_traits<const int[]>::extent == 0);
static_assert(array_traits<const volatile int[]>::extent == 0);
static_assert(array_traits<int[42]>::extent == 42);
static_assert(array_traits<const int[42]>::extent == 42);
static_assert(array_traits<const volatile int[42]>::extent == 42);
static_assert(!array_traits<int[42]>::is_readonly);
static_assert(array_traits<const int[42]>::is_readonly);
static_assert(array_traits<const volatile int[42]>::is_readonly);
static_assert(!array_traits<int[42]>::is_volatile);
static_assert(!array_traits<const int[42]>::is_volatile);
static_assert(array_traits<const volatile int[42]>::is_volatile);
static_assert(std::is_same_v<array_traits<int[42]>::data_type, int>);
static_assert(std::is_same_v<array_traits<const int[42]>::data_type, int>);
static_assert(std::is_same_v<array_traits<const volatile int[42]>::data_type, int>);
static_assert(std::is_same_v<array_traits<int[42]>::cv_data_type, int>);
static_assert(std::is_same_v<array_traits<const int[42]>::cv_data_type, const int>);
static_assert(std::is_same_v<array_traits<const volatile int[42]>::cv_data_type, const volatile int>);
}
SUBCASE("int[]") {
const meta::array_type type = meta::resolve_type<int[]>();
REQUIRE(type);

View File

@@ -24,6 +24,24 @@ TEST_CASE("meta/meta_types/member_type") {
CHECK_FALSE(type.is_valid());
}
SUBCASE("traits") {
using meta::detail::member_traits;
static_assert(!member_traits<int clazz_1::*>::is_readonly);
static_assert(member_traits<const int clazz_1::*>::is_readonly);
static_assert(!member_traits<int clazz_1::*>::is_volatile);
static_assert(member_traits<volatile int clazz_1::*>::is_volatile);
static_assert(std::is_same_v<member_traits<int clazz_1::*>::value_type, int>);
static_assert(std::is_same_v<member_traits<const int clazz_1::*>::value_type, int>);
static_assert(std::is_same_v<member_traits<const volatile int clazz_1::*>::value_type, int>);
static_assert(std::is_same_v<member_traits<int clazz_1::*>::cv_value_type, int>);
static_assert(std::is_same_v<member_traits<const int clazz_1::*>::cv_value_type, const int>);
static_assert(std::is_same_v<member_traits<const volatile int clazz_1::*>::cv_value_type, const volatile int>);
}
SUBCASE("int") {
const meta::member_type type = meta::resolve_type(&clazz_1::int_member);
REQUIRE(type);

View File

@@ -16,6 +16,30 @@ TEST_CASE("meta/meta_types/pointer_type") {
CHECK_FALSE(type.is_valid());
}
SUBCASE("traits") {
using meta::detail::pointer_traits;
static_assert(!pointer_traits<int*>::is_readonly);
static_assert(!pointer_traits<volatile int*>::is_readonly);
static_assert(pointer_traits<const int*>::is_readonly);
static_assert(pointer_traits<const volatile int*>::is_readonly);
static_assert(!pointer_traits<int*>::is_volatile);
static_assert(pointer_traits<volatile int*>::is_volatile);
static_assert(!pointer_traits<const int*>::is_volatile);
static_assert(pointer_traits<const volatile int*>::is_volatile);
static_assert(std::is_same_v<pointer_traits<int*>::data_type, int>);
static_assert(std::is_same_v<pointer_traits<const int*>::data_type, int>);
static_assert(std::is_same_v<pointer_traits<volatile int*>::data_type, int>);
static_assert(std::is_same_v<pointer_traits<const volatile int*>::data_type, int>);
static_assert(std::is_same_v<pointer_traits<int*>::cv_data_type, int>);
static_assert(std::is_same_v<pointer_traits<const int*>::cv_data_type, const int>);
static_assert(std::is_same_v<pointer_traits<volatile int*>::cv_data_type, volatile int>);
static_assert(std::is_same_v<pointer_traits<const volatile int*>::cv_data_type, const volatile int>);
}
SUBCASE("int*") {
const meta::pointer_type type = meta::resolve_type<int*>();
REQUIRE(type);

View File

@@ -16,6 +16,30 @@ TEST_CASE("meta/meta_types/reference_type") {
CHECK_FALSE(type.is_valid());
}
SUBCASE("traits") {
using meta::detail::reference_traits;
static_assert(!reference_traits<int&>::is_readonly);
static_assert(!reference_traits<volatile int&>::is_readonly);
static_assert(reference_traits<const int&>::is_readonly);
static_assert(reference_traits<const volatile int&>::is_readonly);
static_assert(!reference_traits<int&>::is_volatile);
static_assert(reference_traits<volatile int&>::is_volatile);
static_assert(!reference_traits<const int&>::is_volatile);
static_assert(reference_traits<const volatile int&>::is_volatile);
static_assert(std::is_same_v<reference_traits<int&>::data_type, int>);
static_assert(std::is_same_v<reference_traits<const int&>::data_type, int>);
static_assert(std::is_same_v<reference_traits<volatile int&>::data_type, int>);
static_assert(std::is_same_v<reference_traits<const volatile int&>::data_type, int>);
static_assert(std::is_same_v<reference_traits<int&>::cv_data_type, int>);
static_assert(std::is_same_v<reference_traits<const int&>::cv_data_type, const int>);
static_assert(std::is_same_v<reference_traits<volatile int&>::cv_data_type, volatile int>);
static_assert(std::is_same_v<reference_traits<const volatile int&>::cv_data_type, const volatile int>);
}
SUBCASE("int&") {
const meta::reference_type type = meta::resolve_type<int&>();
REQUIRE(type);

View File

@@ -11,8 +11,10 @@
namespace meta_hpp::detail
{
enum class array_flags : std::uint32_t {
is_bounded = 1 << 0,
is_unbounded = 1 << 1,
is_readonly = 1 << 0,
is_volatile = 1 << 1,
is_bounded = 1 << 2,
is_unbounded = 1 << 3,
};
using array_bitflags = bitflags<array_flags>;
@@ -25,11 +27,23 @@ namespace meta_hpp::detail
struct array_traits {
static constexpr std::size_t extent{std::extent_v<Array>};
using data_type = std::remove_extent_t<Array>;
using cv_data_type = std::remove_extent_t<Array>;
inline static constexpr bool is_readonly = std::is_const_v<cv_data_type>;
inline static constexpr bool is_volatile = std::is_volatile_v<cv_data_type>;
using data_type = std::remove_cv_t<cv_data_type>;
[[nodiscard]] static constexpr array_bitflags make_flags() noexcept {
array_bitflags flags{};
if constexpr ( is_readonly ) {
flags.set(array_flags::is_readonly);
}
if constexpr ( is_volatile ) {
flags.set(array_flags::is_volatile);
}
if constexpr ( std::is_bounded_array_v<Array> ) {
flags.set(array_flags::is_bounded);
}

View File

@@ -25,7 +25,7 @@ namespace meta_hpp::detail
static constexpr std::size_t arity{sizeof...(Args)};
using class_type = Class;
using argument_types = type_list<Args...>;
using argument_types = type_list<std::remove_cv_t<Args>...>;
[[nodiscard]] static constexpr constructor_bitflags make_flags() noexcept {
constructor_bitflags flags{};

View File

@@ -27,8 +27,8 @@ namespace meta_hpp::detail
struct function_traits<R(Args...)> {
static constexpr std::size_t arity{sizeof...(Args)};
using return_type = R;
using argument_types = type_list<Args...>;
using return_type = std::remove_cv_t<R>;
using argument_types = type_list<std::remove_cv_t<Args>...>;
[[nodiscard]] static constexpr function_bitflags make_flags() noexcept {
return {};

View File

@@ -26,17 +26,21 @@ namespace meta_hpp::detail
template < typename V, typename C >
struct member_traits<V C::*> {
using cv_value_type = V;
inline static constexpr bool is_readonly = std::is_const_v<cv_value_type>;
inline static constexpr bool is_volatile = std::is_volatile_v<cv_value_type>;
using class_type = C;
using value_type = V;
using value_type = std::remove_cv_t<cv_value_type>;
[[nodiscard]] static constexpr member_bitflags make_flags() noexcept {
member_bitflags flags{};
if constexpr ( std::is_const_v<value_type> ) {
if constexpr ( is_readonly ) {
flags.set(member_flags::is_readonly);
}
if constexpr ( std::is_volatile_v<value_type> ) {
if constexpr ( is_volatile ) {
flags.set(member_flags::is_volatile);
}

View File

@@ -31,9 +31,9 @@ namespace meta_hpp::detail
static constexpr std::size_t arity{sizeof...(Args)};
using class_type = C;
using return_type = R;
using return_type = std::remove_cv_t<R>;
using qualified_type = C;
using argument_types = type_list<Args...>;
using argument_types = type_list<std::remove_cv_t<Args>...>;
[[nodiscard]] static constexpr method_bitflags make_flags() noexcept {
return {};

View File

@@ -23,16 +23,20 @@ namespace meta_hpp::detail
{
template < pointer_kind Pointer >
struct pointer_traits {
using data_type = std::remove_pointer_t<Pointer>;
using cv_data_type = std::remove_pointer_t<Pointer>;
inline static constexpr bool is_readonly = std::is_const_v<cv_data_type>;
inline static constexpr bool is_volatile = std::is_volatile_v<cv_data_type>;
using data_type = std::remove_cv_t<cv_data_type>;
[[nodiscard]] static constexpr pointer_bitflags make_flags() noexcept {
pointer_bitflags flags{};
if constexpr ( std::is_const_v<data_type> ) {
if constexpr ( is_readonly ) {
flags.set(pointer_flags::is_readonly);
}
if constexpr ( std::is_volatile_v<data_type> ) {
if constexpr ( is_volatile ) {
flags.set(pointer_flags::is_volatile);
}

View File

@@ -25,16 +25,20 @@ namespace meta_hpp::detail
{
template < reference_kind Reference >
struct reference_traits {
using data_type = std::remove_reference_t<Reference>;
using cv_data_type = std::remove_reference_t<Reference>;
inline static constexpr bool is_readonly = std::is_const_v<cv_data_type>;
inline static constexpr bool is_volatile = std::is_volatile_v<cv_data_type>;
using data_type = std::remove_cv_t<cv_data_type>;
[[nodiscard]] static constexpr reference_bitflags make_flags() noexcept {
reference_bitflags flags{};
if constexpr ( std::is_const_v<data_type> ) {
if constexpr ( is_readonly ) {
flags.set(reference_flags::is_readonly);
}
if constexpr ( std::is_volatile_v<data_type> ) {
if constexpr ( is_volatile ) {
flags.set(reference_flags::is_volatile);
}

View File

@@ -102,7 +102,7 @@ namespace meta_hpp::detail
using class_type = typename mt::class_type;
using value_type = typename mt::value_type;
if constexpr ( std::is_const_v<value_type> ) {
if constexpr ( mt::is_readonly ) {
(void)registry;
(void)member_ptr;
(void)inst;
@@ -134,7 +134,7 @@ namespace meta_hpp::detail
using class_type = typename mt::class_type;
using value_type = typename mt::value_type;
if constexpr ( std::is_const_v<value_type> ) {
if constexpr ( mt::is_readonly ) {
(void)registry;
(void)inst;
(void)arg;

View File

@@ -52,7 +52,7 @@ namespace meta_hpp::detail
using pt = pointer_traits<Pointer>;
using data_type = typename pt::data_type;
if constexpr ( std::is_const_v<data_type> ) {
if constexpr ( pt::is_readonly ) {
(void)registry;
(void)variable_ptr;
(void)arg;
@@ -72,7 +72,7 @@ namespace meta_hpp::detail
using pt = pointer_traits<Pointer>;
using data_type = typename pt::data_type;
if constexpr ( std::is_const_v<data_type> ) {
if constexpr ( pt::is_readonly ) {
(void)registry;
(void)arg;
return uerror{error_code::bad_const_access};