2
0
mirror of https://github.com/boostorg/align.git synced 2026-01-19 04:02:08 +00:00

Reformat source; wrap at 80 characters

This commit is contained in:
Glen Fernandes
2017-05-03 08:44:31 -04:00
parent 0d6e14e133
commit 6147f01a6d
8 changed files with 32 additions and 56 deletions

View File

@@ -1,10 +1,9 @@
# Boost.Align
The Boost Align C++ library provides functions, classes, templates,
traits, and macros, for the control, inspection, and diagnostic of
memory alignment.
The Boost Align C++ library provides functions, classes, templates, traits,
and macros, for the control, inspection, and diagnostic of memory alignment.
### License
Distributed under the
[Boost Software License, Version 1.0](http://boost.org/LICENSE_1_0.txt).
[Boost Software License, Version 1.0](http://www.boost.org/LICENSE_1_0.txt).

View File

@@ -28,8 +28,7 @@ namespace alignment {
template<class T, std::size_t Alignment>
class aligned_allocator {
BOOST_STATIC_ASSERT(detail::
is_alignment_constant<Alignment>::value);
BOOST_STATIC_ASSERT(detail::is_alignment_constant<Alignment>::value);
public:
typedef T value_type;
@@ -124,8 +123,7 @@ public:
template<std::size_t Alignment>
class aligned_allocator<void, Alignment> {
BOOST_STATIC_ASSERT(detail::
is_alignment_constant<Alignment>::value);
BOOST_STATIC_ASSERT(detail::is_alignment_constant<Alignment>::value);
public:
typedef void value_type;

View File

@@ -32,39 +32,30 @@ namespace alignment {
template<class Allocator, std::size_t Alignment>
class aligned_allocator_adaptor
: public Allocator {
BOOST_STATIC_ASSERT(detail::
is_alignment_constant<Alignment>::value);
BOOST_STATIC_ASSERT(detail::is_alignment_constant<Alignment>::value);
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
typedef std::allocator_traits<Allocator> traits;
typedef typename traits::
template rebind_alloc<char> char_alloc;
typedef typename traits::
template rebind_traits<char> char_traits;
typedef typename traits::template rebind_alloc<char> char_alloc;
typedef typename traits::template rebind_traits<char> char_traits;
typedef typename char_traits::pointer char_ptr;
#else
typedef typename Allocator::
template rebind<char>::other char_alloc;
typedef typename Allocator::template rebind<char>::other char_alloc;
typedef typename char_alloc::pointer char_ptr;
#endif
public:
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
typedef typename traits::value_type value_type;
typedef typename traits::size_type size_type;
#else
typedef typename Allocator::value_type value_type;
typedef typename Allocator::size_type size_type;
#endif
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef void* void_pointer;
typedef const void* const_void_pointer;
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
private:
@@ -77,11 +68,11 @@ public:
template<class U>
struct rebind {
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
typedef aligned_allocator_adaptor<typename traits::
template rebind_alloc<U>, Alignment> other;
typedef aligned_allocator_adaptor<typename traits::template
rebind_alloc<U>, Alignment> other;
#else
typedef aligned_allocator_adaptor<typename Allocator::
template rebind<U>::other, Alignment> other;
typedef aligned_allocator_adaptor<typename Allocator::template
rebind<U>::other, Alignment> other;
#endif
};
@@ -122,8 +113,7 @@ public:
char_ptr p = a.allocate(sizeof p + n);
void* r = detail::addressof(*p) + sizeof p;
(void)align(min_align, s, r, n);
::new(static_cast<void*>(static_cast<char_ptr*>(r)
- 1)) char_ptr(p);
::new(static_cast<void*>(static_cast<char_ptr*>(r) - 1)) char_ptr(p);
return static_cast<pointer>(r);
}
@@ -142,8 +132,7 @@ public:
#endif
void* r = detail::addressof(*p) + sizeof p;
(void)align(min_align, s, r, n);
::new(static_cast<void*>(static_cast<char_ptr*>(r)
- 1)) char_ptr(p);
::new(static_cast<void*>(static_cast<char_ptr*>(r) - 1)) char_ptr(p);
return static_cast<pointer>(r);
}
@@ -152,8 +141,7 @@ public:
char_ptr r = *p;
p->~char_ptr();
char_alloc a(base());
a.deallocate(r, sizeof r + size * sizeof(value_type) +
min_align - 1);
a.deallocate(r, sizeof r + size * sizeof(value_type) + min_align - 1);
}
};

View File

@@ -20,8 +20,8 @@ align(std::size_t alignment, std::size_t size, void*& ptr,
{
BOOST_ASSERT(detail::is_alignment(alignment));
if (size <= space) {
char* p = reinterpret_cast<char*>((reinterpret_cast<std::
size_t>(ptr) + alignment - 1) & ~(alignment - 1));
char* p = reinterpret_cast<char*>(~(alignment - 1) &
(reinterpret_cast<std::size_t>(ptr) + alignment - 1));
std::size_t n = space - (p - static_cast<char*>(ptr));
if (size <= n) {
ptr = p;

View File

@@ -18,8 +18,8 @@ inline void*
align_down(void* ptr, std::size_t alignment) BOOST_NOEXCEPT
{
BOOST_ASSERT(detail::is_alignment(alignment));
return reinterpret_cast<void*>(reinterpret_cast<std::
size_t>(ptr) & ~(alignment - 1));
return reinterpret_cast<void*>(~(alignment - 1) &
reinterpret_cast<std::size_t>(ptr));
}
} /* alignment */

View File

@@ -18,8 +18,8 @@ inline void*
align_up(void* ptr, std::size_t alignment) BOOST_NOEXCEPT
{
BOOST_ASSERT(detail::is_alignment(alignment));
return reinterpret_cast<void*>((reinterpret_cast<std::
size_t>(ptr) + alignment - 1) & ~(alignment - 1));
return reinterpret_cast<void*>(~(alignment - 1) &
(reinterpret_cast<std::size_t>(ptr) + alignment - 1));
}
} /* alignment */

View File

@@ -23,8 +23,7 @@ struct offset_value {
template<class T>
struct alignment_of
: min_size<sizeof(T),
sizeof(offset_value<T>) - (sizeof(T) << 1)> { };
: min_size<sizeof(T), sizeof(offset_value<T>) - (sizeof(T) << 1)> { };
} /* detail */
} /* alignment */

View File

@@ -73,8 +73,7 @@ template<std::size_t Alignment>
void test_allocate()
{
{
boost::alignment::aligned_allocator_adaptor<A<int>,
Alignment> a(5);
boost::alignment::aligned_allocator_adaptor<A<int>, Alignment> a(5);
int* p = a.allocate(1);
BOOST_TEST(p != 0);
BOOST_TEST(boost::alignment::is_aligned(p, Alignment));
@@ -82,8 +81,7 @@ void test_allocate()
a.deallocate(p, 1);
}
{
boost::alignment::aligned_allocator_adaptor<A<int>,
Alignment> a(5);
boost::alignment::aligned_allocator_adaptor<A<int>, Alignment> a(5);
int* p = a.allocate(1);
int* q = a.allocate(1, p);
BOOST_TEST(q != 0);
@@ -93,8 +91,7 @@ void test_allocate()
a.deallocate(p, 1);
}
{
boost::alignment::aligned_allocator_adaptor<A<int>,
Alignment> a(5);
boost::alignment::aligned_allocator_adaptor<A<int>, Alignment> a(5);
int* p = a.allocate(0);
a.deallocate(p, 0);
}
@@ -103,8 +100,7 @@ void test_allocate()
template<std::size_t Alignment>
void test_construct()
{
boost::alignment::aligned_allocator_adaptor<A<int>,
Alignment> a(5);
boost::alignment::aligned_allocator_adaptor<A<int>, Alignment> a(5);
int* p = a.allocate(1);
a.construct(p, 1);
BOOST_TEST(*p == 1);
@@ -116,16 +112,13 @@ template<std::size_t Alignment>
void test_constructor()
{
{
boost::alignment::aligned_allocator_adaptor<A<char>,
Alignment> a(5);
boost::alignment::aligned_allocator_adaptor<A<int>,
Alignment> b(a);
boost::alignment::aligned_allocator_adaptor<A<char>, Alignment> a(5);
boost::alignment::aligned_allocator_adaptor<A<int>, Alignment> b(a);
BOOST_TEST(b == a);
}
{
A<int> a(5);
boost::alignment::aligned_allocator_adaptor<A<int>,
Alignment> b(a);
boost::alignment::aligned_allocator_adaptor<A<int>, Alignment> b(a);
BOOST_TEST(b.base() == a);
}
}
@@ -133,8 +126,7 @@ void test_constructor()
template<std::size_t Alignment>
void test_rebind()
{
boost::alignment::aligned_allocator_adaptor<A<int>,
Alignment> a(5);
boost::alignment::aligned_allocator_adaptor<A<int>, Alignment> a(5);
typename boost::alignment::aligned_allocator_adaptor<A<int>,
Alignment>::template rebind<int>::other b(a);
BOOST_TEST(b == a);