From 63589908b5e0ca56860ec5b4d73de8b46770f6c3 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 6 Oct 2024 20:29:27 +0300 Subject: [PATCH] Add sp_type_identity --- .../boost/smart_ptr/detail/sp_type_traits.hpp | 7 +++++ test/Jamfile | 1 + test/sp_type_identity_test.cpp | 31 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 test/sp_type_identity_test.cpp diff --git a/include/boost/smart_ptr/detail/sp_type_traits.hpp b/include/boost/smart_ptr/detail/sp_type_traits.hpp index 6e0dcee..35b702a 100644 --- a/include/boost/smart_ptr/detail/sp_type_traits.hpp +++ b/include/boost/smart_ptr/detail/sp_type_traits.hpp @@ -32,6 +32,13 @@ template struct sp_is_unbounded_array< T[] >: std::true_type { }; +// std::type_identity (C++20) + +template struct sp_type_identity +{ + typedef T type; +}; + } // namespace detail } // namespace boost diff --git a/test/Jamfile b/test/Jamfile index 8c67901..c6f0b67 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -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 ; diff --git a/test/sp_type_identity_test.cpp b/test/sp_type_identity_test.cpp new file mode 100644 index 0000000..ed425f0 --- /dev/null +++ b/test/sp_type_identity_test.cpp @@ -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 +#include + +struct X; + +int main() +{ + using boost::detail::sp_type_identity; + + BOOST_TEST_TRAIT_SAME( sp_type_identity::type, void ); + BOOST_TEST_TRAIT_SAME( sp_type_identity::type, int ); + BOOST_TEST_TRAIT_SAME( sp_type_identity::type, X ); + + BOOST_TEST_TRAIT_SAME( sp_type_identity::type, void const ); + BOOST_TEST_TRAIT_SAME( sp_type_identity::type, int const ); + BOOST_TEST_TRAIT_SAME( sp_type_identity::type, X const ); + + BOOST_TEST_TRAIT_SAME( sp_type_identity::type, void(int, X) ); + + BOOST_TEST_TRAIT_SAME( sp_type_identity::type, int[] ); + BOOST_TEST_TRAIT_SAME( sp_type_identity::type, X[] ); + + BOOST_TEST_TRAIT_SAME( sp_type_identity::type, int[1] ); + BOOST_TEST_TRAIT_SAME( sp_type_identity::type, X[2] ); + + return boost::report_errors(); +}