diff --git a/include/libsiedler2/ICloneable.h b/include/libsiedler2/ICloneable.h index 7a87700..c642c91 100644 --- a/include/libsiedler2/ICloneable.h +++ b/include/libsiedler2/ICloneable.h @@ -19,14 +19,17 @@ namespace detail { struct is_static_castable(std::declval())))> : std::true_type {}; + template + inline constexpr bool is_static_castable_v = is_static_castable::value; + template - std::enable_if_t::value, To*> safePtrCast(From* from) + std::enable_if_t, To*> safePtrCast(From* from) { return static_cast(from); } template - std::enable_if_t::value, To*> safePtrCast(From* from) + std::enable_if_t, To*> safePtrCast(From* from) { return dynamic_cast(from); } diff --git a/tests/testArchiv.cpp b/tests/testArchiv.cpp index 08a0003..c927f0c 100644 --- a/tests/testArchiv.cpp +++ b/tests/testArchiv.cpp @@ -159,10 +159,10 @@ struct TestItem : libsiedler2::ArchivItem RTTR_CLONEABLE(TestItem) }; -static_assert(!std::is_copy_constructible::value, "Should not be Copyable/Movable"); -static_assert(!std::is_move_constructible::value, "Should not be Copyable/Movable"); -static_assert(!std::is_copy_assignable::value, "Should not be Copyable/Movable"); -static_assert(!std::is_move_assignable::value, "Should not be Copyable/Movable"); +static_assert(!std::is_copy_constructible_v, "Should not be Copyable/Movable"); +static_assert(!std::is_move_constructible_v, "Should not be Copyable/Movable"); +static_assert(!std::is_copy_assignable_v, "Should not be Copyable/Movable"); +static_assert(!std::is_move_assignable_v, "Should not be Copyable/Movable"); int TestItem::numLiveItems = 0; diff --git a/tests/testClone.cpp b/tests/testClone.cpp index 70bf0d8..394343b 100644 --- a/tests/testClone.cpp +++ b/tests/testClone.cpp @@ -34,26 +34,26 @@ struct Bar : virtual BarBase using TestedTypes = boost::mpl::list; } // namespace -static_assert(detail::is_static_castable::value); -static_assert(detail::is_static_castable::value); -static_assert(detail::is_static_castable::value); -static_assert(!detail::is_static_castable::value); +static_assert(detail::is_static_castable_v); +static_assert(detail::is_static_castable_v); +static_assert(detail::is_static_castable_v); +static_assert(!detail::is_static_castable_v); -static_assert(detail::is_static_castable::value); -static_assert(detail::is_static_castable::value); -static_assert(!detail::is_static_castable::value); -static_assert(detail::is_static_castable::value); -static_assert(detail::is_static_castable::value); -static_assert(detail::is_static_castable::value); -static_assert(!detail::is_static_castable::value); +static_assert(detail::is_static_castable_v); +static_assert(detail::is_static_castable_v); +static_assert(!detail::is_static_castable_v); +static_assert(detail::is_static_castable_v); +static_assert(detail::is_static_castable_v); +static_assert(detail::is_static_castable_v); +static_assert(!detail::is_static_castable_v); -static_assert(detail::is_static_castable::value); -static_assert(detail::is_static_castable::value); -static_assert(detail::is_static_castable::value); -static_assert(detail::is_static_castable::value); +static_assert(detail::is_static_castable_v); +static_assert(detail::is_static_castable_v); +static_assert(detail::is_static_castable_v); +static_assert(detail::is_static_castable_v); // Virtual inheritance -> no base to derived cast -static_assert(!detail::is_static_castable::value); -static_assert(!detail::is_static_castable::value); +static_assert(!detail::is_static_castable_v); +static_assert(!detail::is_static_castable_v); BOOST_AUTO_TEST_CASE_TEMPLATE(CloneWorks, T, TestedTypes) { @@ -61,9 +61,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(CloneWorks, T, TestedTypes) auto f2 = clone(f); // By unique_ptr auto f3 = clone(f.get()); // By raw ptr auto f4 = clone(*f); // By reference - static_assert(std::is_same::value, "Must be the same"); - static_assert(std::is_same::value, "Must be the same"); - static_assert(std::is_same::value, "Must be the same"); + static_assert(std::is_same_v, "Must be the same"); + static_assert(std::is_same_v, "Must be the same"); + static_assert(std::is_same_v, "Must be the same"); BOOST_TEST((f && f2 && f3 && f4)); BOOST_TEST(f->i == 42); BOOST_TEST(f2->i == 42); @@ -76,7 +76,7 @@ BOOST_AUTO_TEST_CASE(CloneFromBasePtr) auto f = std::make_unique(42, 1337); auto* basePtr = static_cast(f.get()); auto f2 = clone(basePtr); - static_assert(std::is_same>::value, "Must be the same"); + static_assert(std::is_same_v>, "Must be the same"); BOOST_TEST((f && f2 && basePtr)); BOOST_TEST(f->i == 42); BOOST_TEST(f->j == 1337); @@ -89,8 +89,8 @@ BOOST_AUTO_TEST_CASE(CloneNull) std::unique_ptr f; auto f2 = clone(f); // By unique_ptr auto f3 = clone(f.get()); // By raw ptr - static_assert(std::is_same::value, "Must be the same"); - static_assert(std::is_same::value, "Must be the same"); + static_assert(std::is_same_v, "Must be the same"); + static_assert(std::is_same_v, "Must be the same"); BOOST_TEST(!f2); BOOST_TEST(!f3); }