Add sp_type_identity

This commit is contained in:
Peter Dimov
2024-10-06 20:29:27 +03:00
parent 9466e73cbe
commit 63589908b5
3 changed files with 39 additions and 0 deletions

View File

@@ -32,6 +32,13 @@ template<class T> struct sp_is_unbounded_array< T[] >: std::true_type
{
};
// std::type_identity (C++20)
template<class T> struct sp_type_identity
{
typedef T type;
};
} // namespace detail
} // namespace boost

View File

@@ -427,3 +427,4 @@ run sp_move_only_deleter.cpp ;
run sp_is_bounded_array_test.cpp ;
run sp_is_unbounded_array_test.cpp ;
run sp_type_identity_test.cpp ;

View File

@@ -0,0 +1,31 @@
// Copyright 2024 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/smart_ptr/detail/sp_type_traits.hpp>
#include <boost/core/lightweight_test_trait.hpp>
struct X;
int main()
{
using boost::detail::sp_type_identity;
BOOST_TEST_TRAIT_SAME( sp_type_identity<void>::type, void );
BOOST_TEST_TRAIT_SAME( sp_type_identity<int>::type, int );
BOOST_TEST_TRAIT_SAME( sp_type_identity<X>::type, X );
BOOST_TEST_TRAIT_SAME( sp_type_identity<void const>::type, void const );
BOOST_TEST_TRAIT_SAME( sp_type_identity<int const>::type, int const );
BOOST_TEST_TRAIT_SAME( sp_type_identity<X const>::type, X const );
BOOST_TEST_TRAIT_SAME( sp_type_identity<void(int, X)>::type, void(int, X) );
BOOST_TEST_TRAIT_SAME( sp_type_identity<int[]>::type, int[] );
BOOST_TEST_TRAIT_SAME( sp_type_identity<X[]>::type, X[] );
BOOST_TEST_TRAIT_SAME( sp_type_identity<int[1]>::type, int[1] );
BOOST_TEST_TRAIT_SAME( sp_type_identity<X[2]>::type, X[2] );
return boost::report_errors();
}