Add sp_type_with_alignment

This commit is contained in:
Peter Dimov
2024-10-06 20:56:48 +03:00
parent 5e6b3a9702
commit beaf20e7b5
3 changed files with 29 additions and 0 deletions

View File

@ -39,6 +39,16 @@ template<class T> struct sp_type_identity
typedef T type;
};
// boost::type_with_alignment
template<std::size_t A> struct sp_type_with_alignment
{
struct alignas(A) type
{
unsigned char padding[ A ];
};
};
} // namespace detail
} // namespace boost

View File

@ -428,3 +428,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 ;
run sp_type_with_alignment_test.cpp ;

View File

@ -0,0 +1,18 @@
// 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.hpp>
int main()
{
using boost::detail::sp_type_with_alignment;
BOOST_TEST_EQ( alignof( sp_type_with_alignment<1>::type ), 1 );
BOOST_TEST_EQ( alignof( sp_type_with_alignment<2>::type ), 2 );
BOOST_TEST_EQ( alignof( sp_type_with_alignment<4>::type ), 4 );
BOOST_TEST_EQ( alignof( sp_type_with_alignment<8>::type ), 8 );
return boost::report_errors();
}