From beaf20e7b5a36fc330da7deb49a71d452e23823b Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 6 Oct 2024 20:56:48 +0300 Subject: [PATCH] Add sp_type_with_alignment --- .../boost/smart_ptr/detail/sp_type_traits.hpp | 10 ++++++++++ test/Jamfile | 1 + test/sp_type_with_alignment_test.cpp | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 test/sp_type_with_alignment_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 35b702a..a717f92 100644 --- a/include/boost/smart_ptr/detail/sp_type_traits.hpp +++ b/include/boost/smart_ptr/detail/sp_type_traits.hpp @@ -39,6 +39,16 @@ template struct sp_type_identity typedef T type; }; +// boost::type_with_alignment + +template struct sp_type_with_alignment +{ + struct alignas(A) type + { + unsigned char padding[ A ]; + }; +}; + } // namespace detail } // namespace boost diff --git a/test/Jamfile b/test/Jamfile index c6f0b67..59b9208 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -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 ; diff --git a/test/sp_type_with_alignment_test.cpp b/test/sp_type_with_alignment_test.cpp new file mode 100644 index 0000000..5bb5ed8 --- /dev/null +++ b/test/sp_type_with_alignment_test.cpp @@ -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 +#include + +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(); +}