Skip to content

Commit beaf20e

Browse files
committed
Add sp_type_with_alignment
1 parent 5e6b3a9 commit beaf20e

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

include/boost/smart_ptr/detail/sp_type_traits.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ template<class T> struct sp_type_identity
3939
typedef T type;
4040
};
4141

42+
// boost::type_with_alignment
43+
44+
template<std::size_t A> struct sp_type_with_alignment
45+
{
46+
struct alignas(A) type
47+
{
48+
unsigned char padding[ A ];
49+
};
50+
};
51+
4252
} // namespace detail
4353
} // namespace boost
4454

test/Jamfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,3 +428,4 @@ run sp_move_only_deleter.cpp ;
428428
run sp_is_bounded_array_test.cpp ;
429429
run sp_is_unbounded_array_test.cpp ;
430430
run sp_type_identity_test.cpp ;
431+
run sp_type_with_alignment_test.cpp ;

test/sp_type_with_alignment_test.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2024 Peter Dimov
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// https://www.boost.org/LICENSE_1_0.txt
4+
5+
#include <boost/smart_ptr/detail/sp_type_traits.hpp>
6+
#include <boost/core/lightweight_test.hpp>
7+
8+
int main()
9+
{
10+
using boost::detail::sp_type_with_alignment;
11+
12+
BOOST_TEST_EQ( alignof( sp_type_with_alignment<1>::type ), 1 );
13+
BOOST_TEST_EQ( alignof( sp_type_with_alignment<2>::type ), 2 );
14+
BOOST_TEST_EQ( alignof( sp_type_with_alignment<4>::type ), 4 );
15+
BOOST_TEST_EQ( alignof( sp_type_with_alignment<8>::type ), 8 );
16+
17+
return boost::report_errors();
18+
}

0 commit comments

Comments
 (0)