mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-16 22:17:02 +07:00
reduce the number of ::instance() calls
This commit is contained in:
@@ -50,6 +50,8 @@ TEST_CASE("meta/meta_utilities/arg7") {
|
||||
TEST_CASE("meta/meta_utilities/arg7/cast/to_void") {
|
||||
namespace meta = meta_hpp;
|
||||
using meta::detail::uarg;
|
||||
using meta::detail::type_registry;
|
||||
type_registry& r{type_registry::instance()};
|
||||
|
||||
SUBCASE("int* -> void*") {
|
||||
int i{42};
|
||||
@@ -57,11 +59,11 @@ TEST_CASE("meta/meta_utilities/arg7/cast/to_void") {
|
||||
static_assert(std::is_invocable_v<void(void*), int*>);
|
||||
static_assert(std::is_invocable_v<void(const void*), int*>);
|
||||
|
||||
CHECK(uarg{&i}.can_cast_to<void*>());
|
||||
CHECK(uarg{&i}.can_cast_to<const void*>());
|
||||
CHECK(uarg{r, &i}.can_cast_to<void*>(r));
|
||||
CHECK(uarg{r, &i}.can_cast_to<const void*>(r));
|
||||
|
||||
CHECK(uarg{&i}.cast<void*>() == &i);
|
||||
CHECK(uarg{&i}.cast<const void*>() == &i);
|
||||
CHECK(uarg{r, &i}.cast<void*>(r) == &i);
|
||||
CHECK(uarg{r, &i}.cast<const void*>(r) == &i);
|
||||
}
|
||||
|
||||
SUBCASE("const int* -> void*") {
|
||||
@@ -70,11 +72,11 @@ TEST_CASE("meta/meta_utilities/arg7/cast/to_void") {
|
||||
static_assert(!std::is_invocable_v<void(void*), const int*>);
|
||||
static_assert(std::is_invocable_v<void(const void*), const int*>);
|
||||
|
||||
CHECK_FALSE(uarg{&i}.can_cast_to<void*>());
|
||||
CHECK(uarg{&i}.can_cast_to<const void*>());
|
||||
CHECK_FALSE(uarg{r, &i}.can_cast_to<void*>(r));
|
||||
CHECK(uarg{r, &i}.can_cast_to<const void*>(r));
|
||||
|
||||
// CHECK_THROWS(std::ignore = uarg{&i}.cast<void*>());
|
||||
CHECK(uarg{&i}.cast<const void*>() == &i);
|
||||
// CHECK_THROWS(std::ignore = uarg{r, &i}.cast<void*>(r));
|
||||
CHECK(uarg{r, &i}.cast<const void*>(r) == &i);
|
||||
}
|
||||
|
||||
SUBCASE("D* -> void*") {
|
||||
@@ -83,11 +85,11 @@ TEST_CASE("meta/meta_utilities/arg7/cast/to_void") {
|
||||
static_assert(std::is_invocable_v<void(void*), D*>);
|
||||
static_assert(std::is_invocable_v<void(const void*), D*>);
|
||||
|
||||
CHECK(uarg{&d}.can_cast_to<void*>());
|
||||
CHECK(uarg{&d}.can_cast_to<const void*>());
|
||||
CHECK(uarg{r, &d}.can_cast_to<void*>(r));
|
||||
CHECK(uarg{r, &d}.can_cast_to<const void*>(r));
|
||||
|
||||
CHECK(uarg{&d}.cast<void*>() == &d);
|
||||
CHECK(uarg{&d}.cast<const void*>() == &d);
|
||||
CHECK(uarg{r, &d}.cast<void*>(r) == &d);
|
||||
CHECK(uarg{r, &d}.cast<const void*>(r) == &d);
|
||||
}
|
||||
|
||||
SUBCASE("const D* -> void*") {
|
||||
@@ -96,11 +98,11 @@ TEST_CASE("meta/meta_utilities/arg7/cast/to_void") {
|
||||
static_assert(!std::is_invocable_v<void(void*), const D*>);
|
||||
static_assert(std::is_invocable_v<void(const void*), const D*>);
|
||||
|
||||
CHECK_FALSE(uarg{&d}.can_cast_to<void*>());
|
||||
CHECK(uarg{&d}.can_cast_to<const void*>());
|
||||
CHECK_FALSE(uarg{r, &d}.can_cast_to<void*>(r));
|
||||
CHECK(uarg{r, &d}.can_cast_to<const void*>(r));
|
||||
|
||||
// CHECK_THROWS(std::ignore = uarg{&d}.cast<void*>());
|
||||
CHECK(uarg{&d}.cast<const void*>() == &d);
|
||||
// CHECK_THROWS(std::ignore = uarg{r, &d}.cast<void*>(r));
|
||||
CHECK(uarg{r, &d}.cast<const void*>(r) == &d);
|
||||
}
|
||||
|
||||
SUBCASE("D[2] -> void*") {
|
||||
@@ -109,11 +111,11 @@ TEST_CASE("meta/meta_utilities/arg7/cast/to_void") {
|
||||
static_assert(std::is_invocable_v<void(void*), D (&) [2]>);
|
||||
static_assert(std::is_invocable_v<void(const void*), D (&) [2]>);
|
||||
|
||||
CHECK(uarg{arr}.can_cast_to<void*>());
|
||||
CHECK(uarg{arr}.can_cast_to<const void*>());
|
||||
CHECK(uarg{r, arr}.can_cast_to<void*>(r));
|
||||
CHECK(uarg{r, arr}.can_cast_to<const void*>(r));
|
||||
|
||||
CHECK(uarg{arr}.cast<void*>() == &arr);
|
||||
CHECK(uarg{arr}.cast<const void*>() == &arr);
|
||||
CHECK(uarg{r, arr}.cast<void*>(r) == &arr);
|
||||
CHECK(uarg{r, arr}.cast<const void*>(r) == &arr);
|
||||
}
|
||||
|
||||
SUBCASE("const D[2] -> void*") {
|
||||
@@ -122,17 +124,19 @@ TEST_CASE("meta/meta_utilities/arg7/cast/to_void") {
|
||||
static_assert(!std::is_invocable_v<void(void*), const D (&) [2]>);
|
||||
static_assert(std::is_invocable_v<void(const void*), const D (&) [2]>);
|
||||
|
||||
CHECK_FALSE(uarg{arr}.can_cast_to<void*>());
|
||||
CHECK(uarg{arr}.can_cast_to<const void*>());
|
||||
CHECK_FALSE(uarg{r, arr}.can_cast_to<void*>(r));
|
||||
CHECK(uarg{r, arr}.can_cast_to<const void*>(r));
|
||||
|
||||
// CHECK_THROWS(std::ignore = uarg{arr}.cast<void*>());
|
||||
CHECK(uarg{arr}.cast<const void*>() == &arr);
|
||||
// CHECK_THROWS(std::ignore = uarg{r, arr}.cast<void*>(r));
|
||||
CHECK(uarg{r, arr}.cast<const void*>(r) == &arr);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("meta/meta_utilities/arg7/cast/from_nullptr") {
|
||||
namespace meta = meta_hpp;
|
||||
using meta::detail::uarg;
|
||||
using meta::detail::type_registry;
|
||||
type_registry& r{type_registry::instance()};
|
||||
|
||||
SUBCASE("nullptr -> *") {
|
||||
static_assert(std::is_invocable_v<void(int*), std::nullptr_t>);
|
||||
@@ -152,46 +156,46 @@ TEST_CASE("meta/meta_utilities/arg7/cast/from_nullptr") {
|
||||
std::nullptr_t n1{nullptr};
|
||||
const std::nullptr_t n2{nullptr};
|
||||
|
||||
CHECK(uarg{n1}.can_cast_to<int*>());
|
||||
CHECK(uarg{std::move(n1)}.can_cast_to<int*>());
|
||||
CHECK(uarg{n2}.can_cast_to<int*>());
|
||||
CHECK(uarg{std::move(n2)}.can_cast_to<int*>());
|
||||
CHECK(uarg{r, n1}.can_cast_to<int*>(r));
|
||||
CHECK(uarg{r, std::move(n1)}.can_cast_to<int*>(r));
|
||||
CHECK(uarg{r, n2}.can_cast_to<int*>(r));
|
||||
CHECK(uarg{r, std::move(n2)}.can_cast_to<int*>(r));
|
||||
|
||||
CHECK(uarg{n1}.can_cast_to<const int*>());
|
||||
CHECK(uarg{std::move(n1)}.can_cast_to<const int*>());
|
||||
CHECK(uarg{n2}.can_cast_to<const int*>());
|
||||
CHECK(uarg{std::move(n2)}.can_cast_to<const int*>());
|
||||
CHECK(uarg{r, n1}.can_cast_to<const int*>(r));
|
||||
CHECK(uarg{r, std::move(n1)}.can_cast_to<const int*>(r));
|
||||
CHECK(uarg{r, n2}.can_cast_to<const int*>(r));
|
||||
CHECK(uarg{r, std::move(n2)}.can_cast_to<const int*>(r));
|
||||
|
||||
CHECK(uarg{n1}.can_cast_to<D*>());
|
||||
CHECK(uarg{std::move(n1)}.can_cast_to<D*>());
|
||||
CHECK(uarg{n2}.can_cast_to<D*>());
|
||||
CHECK(uarg{std::move(n2)}.can_cast_to<D*>());
|
||||
CHECK(uarg{r, n1}.can_cast_to<D*>(r));
|
||||
CHECK(uarg{r, std::move(n1)}.can_cast_to<D*>(r));
|
||||
CHECK(uarg{r, n2}.can_cast_to<D*>(r));
|
||||
CHECK(uarg{r, std::move(n2)}.can_cast_to<D*>(r));
|
||||
|
||||
CHECK(uarg{n1}.can_cast_to<const D*>());
|
||||
CHECK(uarg{std::move(n1)}.can_cast_to<const D*>());
|
||||
CHECK(uarg{n2}.can_cast_to<const D*>());
|
||||
CHECK(uarg{std::move(n2)}.can_cast_to<const D*>());
|
||||
CHECK(uarg{r, n1}.can_cast_to<const D*>(r));
|
||||
CHECK(uarg{r, std::move(n1)}.can_cast_to<const D*>(r));
|
||||
CHECK(uarg{r, n2}.can_cast_to<const D*>(r));
|
||||
CHECK(uarg{r, std::move(n2)}.can_cast_to<const D*>(r));
|
||||
|
||||
//
|
||||
|
||||
CHECK(uarg{n1}.cast<int*>() == nullptr);
|
||||
CHECK(uarg{std::move(n1)}.cast<int*>() == nullptr);
|
||||
CHECK(uarg{n2}.cast<int*>() == nullptr);
|
||||
CHECK(uarg{std::move(n2)}.cast<int*>() == nullptr);
|
||||
CHECK(uarg{r, n1}.cast<int*>(r) == nullptr);
|
||||
CHECK(uarg{r, std::move(n1)}.cast<int*>(r) == nullptr);
|
||||
CHECK(uarg{r, n2}.cast<int*>(r) == nullptr);
|
||||
CHECK(uarg{r, std::move(n2)}.cast<int*>(r) == nullptr);
|
||||
|
||||
CHECK(uarg{n1}.cast<const int*>() == nullptr);
|
||||
CHECK(uarg{std::move(n1)}.cast<const int*>() == nullptr);
|
||||
CHECK(uarg{n2}.cast<const int*>() == nullptr);
|
||||
CHECK(uarg{std::move(n2)}.cast<const int*>() == nullptr);
|
||||
CHECK(uarg{r, n1}.cast<const int*>(r) == nullptr);
|
||||
CHECK(uarg{r, std::move(n1)}.cast<const int*>(r) == nullptr);
|
||||
CHECK(uarg{r, n2}.cast<const int*>(r) == nullptr);
|
||||
CHECK(uarg{r, std::move(n2)}.cast<const int*>(r) == nullptr);
|
||||
|
||||
CHECK(uarg{n1}.cast<D*>() == nullptr);
|
||||
CHECK(uarg{std::move(n1)}.cast<D*>() == nullptr);
|
||||
CHECK(uarg{n2}.cast<D*>() == nullptr);
|
||||
CHECK(uarg{std::move(n2)}.cast<D*>() == nullptr);
|
||||
CHECK(uarg{r, n1}.cast<D*>(r) == nullptr);
|
||||
CHECK(uarg{r, std::move(n1)}.cast<D*>(r) == nullptr);
|
||||
CHECK(uarg{r, n2}.cast<D*>(r) == nullptr);
|
||||
CHECK(uarg{r, std::move(n2)}.cast<D*>(r) == nullptr);
|
||||
|
||||
CHECK(uarg{n1}.cast<const D*>() == nullptr);
|
||||
CHECK(uarg{std::move(n1)}.cast<const D*>() == nullptr);
|
||||
CHECK(uarg{n2}.cast<const D*>() == nullptr);
|
||||
CHECK(uarg{std::move(n2)}.cast<const D*>() == nullptr);
|
||||
CHECK(uarg{r, n1}.cast<const D*>(r) == nullptr);
|
||||
CHECK(uarg{r, std::move(n1)}.cast<const D*>(r) == nullptr);
|
||||
CHECK(uarg{r, n2}.cast<const D*>(r) == nullptr);
|
||||
CHECK(uarg{r, std::move(n2)}.cast<const D*>(r) == nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user