diff --git a/STL_Extension/include/CGAL/type_traits.h b/STL_Extension/include/CGAL/type_traits.h index c68386c7f76..f64e7c0c57f 100644 --- a/STL_Extension/include/CGAL/type_traits.h +++ b/STL_Extension/include/CGAL/type_traits.h @@ -29,6 +29,12 @@ struct is_same_or_derived : namespace cpp20 { + template + struct type_identity { using type = T; }; + + template + using type_identity_t = typename type_identity::type; + template< class T > struct remove_cvref { typedef std::remove_cv_t> type; @@ -39,6 +45,26 @@ namespace cpp20 { } // end namespace cpp20 +namespace details { + template + struct is_convertible_without_narrowing : std::false_type + {}; + + template + struct is_convertible_without_narrowing{std::declval()})>> + : std::is_convertible + {}; +} + +template +struct is_convertible_without_narrowing : details::is_convertible_without_narrowing +{}; + +template +inline constexpr bool is_convertible_without_narrowing_v = is_convertible_without_narrowing::value; + } // end namespace CGAL #endif // CGAL_TYPE_TRAITS_H diff --git a/STL_Extension/test/STL_Extension/test_type_traits.cpp b/STL_Extension/test/STL_Extension/test_type_traits.cpp index 77586b50c89..caa0e3afa36 100644 --- a/STL_Extension/test/STL_Extension/test_type_traits.cpp +++ b/STL_Extension/test/STL_Extension/test_type_traits.cpp @@ -18,14 +18,22 @@ struct B : public A {}; typedef A C; int main() { - assert( ( ::CGAL::is_same_or_derived< A,A >::value == 1 ) ); - assert( ( ::CGAL::is_same_or_derived< A,B >::value == 1 ) ); - assert( ( ::CGAL::is_same_or_derived< B,A >::value == 0 ) ); - assert( ( ::CGAL::is_same_or_derived< B,B >::value == 1 ) ); - assert( ( ::CGAL::is_same_or_derived< A,C >::value == 1 ) ); - assert( ( ::CGAL::is_same_or_derived< B,C >::value == 0 ) ); - assert( ( ::CGAL::is_same_or_derived< C,C >::value == 1 ) ); - assert( ( ::CGAL::is_same_or_derived< C,A >::value == 1 ) ); - assert( ( ::CGAL::is_same_or_derived< C,B >::value == 1 ) ); + static_assert( ( ::CGAL::is_same_or_derived< A,A >::value == 1 ) ); + static_assert( ( ::CGAL::is_same_or_derived< A,B >::value == 1 ) ); + static_assert( ( ::CGAL::is_same_or_derived< B,A >::value == 0 ) ); + static_assert( ( ::CGAL::is_same_or_derived< B,B >::value == 1 ) ); + static_assert( ( ::CGAL::is_same_or_derived< A,C >::value == 1 ) ); + static_assert( ( ::CGAL::is_same_or_derived< B,C >::value == 0 ) ); + static_assert( ( ::CGAL::is_same_or_derived< C,C >::value == 1 ) ); + static_assert( ( ::CGAL::is_same_or_derived< C,A >::value == 1 ) ); + static_assert( ( ::CGAL::is_same_or_derived< C,B >::value == 1 ) ); + + static_assert( CGAL::is_convertible_without_narrowing_v ); + static_assert( ! CGAL::is_convertible_without_narrowing_v ); + static_assert( CGAL::is_convertible_without_narrowing_v ); + static_assert( ! CGAL::is_convertible_without_narrowing_v ); + static_assert( CGAL::is_convertible_without_narrowing_v ); + static_assert( ! CGAL::is_convertible_without_narrowing_v ); + static_assert( ! CGAL::is_convertible_without_narrowing_v ); return 0; }