summaryrefslogtreecommitdiff
path: root/boost/align
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2016-10-06 10:38:45 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2016-10-06 10:39:52 +0900
commit5cde13f21d36c7224b0e13d11c4b49379ae5210d (patch)
treee8269ac85a4b0f7d416e2565fa4f451b5cb41351 /boost/align
parentd9ec475d945d3035377a0d89ed42e382d8988891 (diff)
downloadboost-5cde13f21d36c7224b0e13d11c4b49379ae5210d.tar.gz
boost-5cde13f21d36c7224b0e13d11c4b49379ae5210d.tar.bz2
boost-5cde13f21d36c7224b0e13d11c4b49379ae5210d.zip
Imported Upstream version 1.61.0
Change-Id: I96a1f878d1e6164f01e9aadd5147f38fca448d90 Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'boost/align')
-rw-r--r--boost/align/align.hpp2
-rw-r--r--boost/align/align_down.hpp27
-rw-r--r--boost/align/align_down_forward.hpp24
-rw-r--r--boost/align/align_up.hpp27
-rw-r--r--boost/align/align_up_forward.hpp24
-rw-r--r--boost/align/aligned_alloc.hpp6
-rw-r--r--boost/align/aligned_allocator.hpp45
-rw-r--r--boost/align/aligned_allocator_adaptor.hpp57
-rw-r--r--boost/align/aligned_delete.hpp6
-rw-r--r--boost/align/aligned_delete_forward.hpp4
-rw-r--r--boost/align/alignment_of.hpp13
-rw-r--r--boost/align/detail/address.hpp29
-rw-r--r--boost/align/detail/align.hpp24
-rw-r--r--boost/align/detail/align_down.hpp29
-rw-r--r--boost/align/detail/align_up.hpp29
-rw-r--r--boost/align/detail/aligned_alloc.hpp30
-rw-r--r--boost/align/detail/aligned_alloc_android.hpp4
-rw-r--r--boost/align/detail/aligned_alloc_macos.hpp4
-rw-r--r--boost/align/detail/aligned_alloc_msvc.hpp4
-rw-r--r--boost/align/detail/aligned_alloc_posix.hpp4
-rw-r--r--boost/align/detail/aligned_alloc_sunos.hpp4
-rw-r--r--boost/align/detail/assume_aligned.hpp2
-rw-r--r--boost/align/detail/assume_aligned_clang.hpp6
-rw-r--r--boost/align/detail/assume_aligned_gcc.hpp4
-rw-r--r--boost/align/detail/assume_aligned_intel.hpp4
-rw-r--r--boost/align/detail/assume_aligned_msvc.hpp6
-rw-r--r--boost/align/detail/element_type.hpp (renamed from boost/align/detail/remove_traits.hpp)26
-rw-r--r--boost/align/detail/is_aligned.hpp15
-rw-r--r--boost/align/detail/max_align.hpp1
-rw-r--r--boost/align/is_aligned.hpp13
-rw-r--r--boost/align/is_aligned_forward.hpp24
31 files changed, 330 insertions, 167 deletions
diff --git a/boost/align/align.hpp b/boost/align/align.hpp
index 648a65e295..3582dcc051 100644
--- a/boost/align/align.hpp
+++ b/boost/align/align.hpp
@@ -1,5 +1,5 @@
/*
-(c) 2014 Glen Joseph Fernandes
+(c) 2014-2015 Glen Joseph Fernandes
<glenjofe -at- gmail.com>
Distributed under the Boost Software
diff --git a/boost/align/align_down.hpp b/boost/align/align_down.hpp
new file mode 100644
index 0000000000..f437f8e5b3
--- /dev/null
+++ b/boost/align/align_down.hpp
@@ -0,0 +1,27 @@
+/*
+(c) 2015 Glen Joseph Fernandes
+<glenjofe -at- gmail.com>
+
+Distributed under the Boost Software
+License, Version 1.0.
+http://boost.org/LICENSE_1_0.txt
+*/
+#ifndef BOOST_ALIGN_ALIGN_DOWN_HPP
+#define BOOST_ALIGN_ALIGN_DOWN_HPP
+
+#include <boost/align/detail/align_down.hpp>
+#include <boost/align/align_down_forward.hpp>
+
+namespace boost {
+namespace alignment {
+
+BOOST_CONSTEXPR inline std::size_t align_down(std::size_t value,
+ std::size_t alignment) BOOST_NOEXCEPT
+{
+ return value & ~(alignment - 1);
+}
+
+} /* .alignment */
+} /* .boost */
+
+#endif
diff --git a/boost/align/align_down_forward.hpp b/boost/align/align_down_forward.hpp
new file mode 100644
index 0000000000..6d124e8901
--- /dev/null
+++ b/boost/align/align_down_forward.hpp
@@ -0,0 +1,24 @@
+/*
+(c) 2015 Glen Joseph Fernandes
+<glenjofe -at- gmail.com>
+
+Distributed under the Boost Software
+License, Version 1.0.
+http://boost.org/LICENSE_1_0.txt
+*/
+#ifndef BOOST_ALIGN_ALIGN_DOWN_FORWARD_HPP
+#define BOOST_ALIGN_ALIGN_DOWN_FORWARD_HPP
+
+#include <boost/config.hpp>
+#include <cstddef>
+
+namespace boost {
+namespace alignment {
+
+BOOST_CONSTEXPR std::size_t align_down(std::size_t value,
+ std::size_t alignment) BOOST_NOEXCEPT;
+
+} /* .alignment */
+} /* .boost */
+
+#endif
diff --git a/boost/align/align_up.hpp b/boost/align/align_up.hpp
new file mode 100644
index 0000000000..b1cec1911e
--- /dev/null
+++ b/boost/align/align_up.hpp
@@ -0,0 +1,27 @@
+/*
+(c) 2015 Glen Joseph Fernandes
+<glenjofe -at- gmail.com>
+
+Distributed under the Boost Software
+License, Version 1.0.
+http://boost.org/LICENSE_1_0.txt
+*/
+#ifndef BOOST_ALIGN_ALIGN_UP_HPP
+#define BOOST_ALIGN_ALIGN_UP_HPP
+
+#include <boost/align/detail/align_up.hpp>
+#include <boost/align/align_up_forward.hpp>
+
+namespace boost {
+namespace alignment {
+
+BOOST_CONSTEXPR inline std::size_t align_up(std::size_t value,
+ std::size_t alignment) BOOST_NOEXCEPT
+{
+ return (value + alignment - 1) & ~(alignment - 1);
+}
+
+} /* .alignment */
+} /* .boost */
+
+#endif
diff --git a/boost/align/align_up_forward.hpp b/boost/align/align_up_forward.hpp
new file mode 100644
index 0000000000..47fdfcd0ba
--- /dev/null
+++ b/boost/align/align_up_forward.hpp
@@ -0,0 +1,24 @@
+/*
+(c) 2015 Glen Joseph Fernandes
+<glenjofe -at- gmail.com>
+
+Distributed under the Boost Software
+License, Version 1.0.
+http://boost.org/LICENSE_1_0.txt
+*/
+#ifndef BOOST_ALIGN_ALIGN_UP_FORWARD_HPP
+#define BOOST_ALIGN_ALIGN_UP_FORWARD_HPP
+
+#include <boost/config.hpp>
+#include <cstddef>
+
+namespace boost {
+namespace alignment {
+
+BOOST_CONSTEXPR std::size_t align_up(std::size_t value,
+ std::size_t alignment) BOOST_NOEXCEPT;
+
+} /* .alignment */
+} /* .boost */
+
+#endif
diff --git a/boost/align/aligned_alloc.hpp b/boost/align/aligned_alloc.hpp
index b70f4bc632..7f2c0bb363 100644
--- a/boost/align/aligned_alloc.hpp
+++ b/boost/align/aligned_alloc.hpp
@@ -1,5 +1,5 @@
/*
-(c) 2014 Glen Joseph Fernandes
+(c) 2014-2015 Glen Joseph Fernandes
<glenjofe -at- gmail.com>
Distributed under the Boost Software
@@ -19,7 +19,9 @@ http://boost.org/LICENSE_1_0.txt
#include <AvailabilityMacros.h>
#endif
-#if defined(_MSC_VER)
+#if defined(BOOST_ALIGN_USE_ALLOCATE)
+#include <boost/align/detail/aligned_alloc.hpp>
+#elif defined(_MSC_VER) && !defined(UNDER_CE)
#include <boost/align/detail/aligned_alloc_msvc.hpp>
#elif defined(__MINGW32__) && (__MSVCRT_VERSION__ >= 0x0700)
#include <boost/align/detail/aligned_alloc_msvc.hpp>
diff --git a/boost/align/aligned_allocator.hpp b/boost/align/aligned_allocator.hpp
index 9655e3dfb2..83af070c7a 100644
--- a/boost/align/aligned_allocator.hpp
+++ b/boost/align/aligned_allocator.hpp
@@ -9,16 +9,15 @@ http://boost.org/LICENSE_1_0.txt
#ifndef BOOST_ALIGN_ALIGNED_ALLOCATOR_HPP
#define BOOST_ALIGN_ALIGNED_ALLOCATOR_HPP
-#include <boost/config.hpp>
-#include <boost/static_assert.hpp>
-#include <boost/throw_exception.hpp>
-#include <boost/align/aligned_alloc.hpp>
-#include <boost/align/aligned_allocator_forward.hpp>
-#include <boost/align/alignment_of.hpp>
#include <boost/align/detail/addressof.hpp>
#include <boost/align/detail/is_alignment_constant.hpp>
#include <boost/align/detail/max_objects.hpp>
#include <boost/align/detail/max_size.hpp>
+#include <boost/align/aligned_alloc.hpp>
+#include <boost/align/aligned_allocator_forward.hpp>
+#include <boost/align/alignment_of.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/throw_exception.hpp>
#include <new>
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
@@ -72,15 +71,17 @@ public:
return detail::addressof(value);
}
- const_pointer address(const_reference value) const
- BOOST_NOEXCEPT {
+ const_pointer address(const_reference value) const BOOST_NOEXCEPT {
return detail::addressof(value);
}
pointer allocate(size_type size, const_void_pointer = 0) {
- void* p = aligned_alloc(min_align, sizeof(T) * size);
- if (size > 0 && !p) {
- ::boost::throw_exception(std::bad_alloc());
+ void* p = 0;
+ if (size > 0) {
+ p = aligned_alloc(min_align, sizeof(T) * size);
+ if (!p) {
+ ::boost::throw_exception(std::bad_alloc());
+ }
}
return static_cast<T*>(p);
}
@@ -97,28 +98,24 @@ public:
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template<class U, class... Args>
void construct(U* ptr, Args&&... args) {
- void* p = ptr;
- ::new(p) U(std::forward<Args>(args)...);
+ ::new(static_cast<void*>(ptr)) U(std::forward<Args>(args)...);
}
#else
template<class U, class V>
void construct(U* ptr, V&& value) {
- void* p = ptr;
- ::new(p) U(std::forward<V>(value));
+ ::new(static_cast<void*>(ptr)) U(std::forward<V>(value));
}
#endif
#else
template<class U, class V>
void construct(U* ptr, const V& value) {
- void* p = ptr;
- ::new(p) U(value);
+ ::new(static_cast<void*>(ptr)) U(value);
}
#endif
template<class U>
void construct(U* ptr) {
- void* p = ptr;
- ::new(p) U();
+ ::new(static_cast<void*>(ptr)) U();
}
template<class U>
@@ -145,17 +142,15 @@ public:
};
template<class T1, class T2, std::size_t Alignment>
-inline bool operator==(const aligned_allocator<T1,
- Alignment>&, const aligned_allocator<T2,
- Alignment>&) BOOST_NOEXCEPT
+inline bool operator==(const aligned_allocator<T1, Alignment>&,
+ const aligned_allocator<T2, Alignment>&) BOOST_NOEXCEPT
{
return true;
}
template<class T1, class T2, std::size_t Alignment>
-inline bool operator!=(const aligned_allocator<T1,
- Alignment>&, const aligned_allocator<T2,
- Alignment>&) BOOST_NOEXCEPT
+inline bool operator!=(const aligned_allocator<T1, Alignment>&,
+ const aligned_allocator<T2, Alignment>&) BOOST_NOEXCEPT
{
return false;
}
diff --git a/boost/align/aligned_allocator_adaptor.hpp b/boost/align/aligned_allocator_adaptor.hpp
index 19777173f1..29d13874ad 100644
--- a/boost/align/aligned_allocator_adaptor.hpp
+++ b/boost/align/aligned_allocator_adaptor.hpp
@@ -9,15 +9,14 @@ http://boost.org/LICENSE_1_0.txt
#ifndef BOOST_ALIGN_ALIGNED_ALLOCATOR_ADAPTOR_HPP
#define BOOST_ALIGN_ALIGNED_ALLOCATOR_ADAPTOR_HPP
-#include <boost/config.hpp>
-#include <boost/static_assert.hpp>
-#include <boost/align/align.hpp>
-#include <boost/align/aligned_allocator_adaptor_forward.hpp>
-#include <boost/align/alignment_of.hpp>
#include <boost/align/detail/addressof.hpp>
#include <boost/align/detail/is_alignment_constant.hpp>
#include <boost/align/detail/max_align.hpp>
#include <boost/align/detail/max_size.hpp>
+#include <boost/align/align.hpp>
+#include <boost/align/aligned_allocator_adaptor_forward.hpp>
+#include <boost/align/alignment_of.hpp>
+#include <boost/static_assert.hpp>
#include <new>
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
@@ -54,10 +53,6 @@ class aligned_allocator_adaptor
typedef typename char_alloc::pointer char_ptr;
#endif
- enum {
- ptr_align = alignment_of<char_ptr>::value
- };
-
public:
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
typedef typename traits::value_type value_type;
@@ -127,44 +122,44 @@ public:
}
pointer allocate(size_type size) {
- std::size_t n1 = size * sizeof(value_type);
- std::size_t n2 = n1 + min_align - ptr_align;
+ std::size_t s = size * sizeof(value_type);
+ std::size_t n = s + min_align - 1;
char_alloc a(base());
- char_ptr p1 = a.allocate(sizeof p1 + n2);
- void* p2 = detail::addressof(*p1) + sizeof p1;
- (void)align(min_align, n1, p2, n2);
- void* p3 = static_cast<char_ptr*>(p2) - 1;
- ::new(p3) char_ptr(p1);
- return static_cast<pointer>(p2);
+ 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);
+ return static_cast<pointer>(r);
}
pointer allocate(size_type size, const_void_pointer hint) {
- std::size_t n1 = size * sizeof(value_type);
- std::size_t n2 = n1 + min_align - ptr_align;
+ std::size_t s = size * sizeof(value_type);
+ std::size_t n = s + min_align - 1;
char_ptr h = char_ptr();
if (hint) {
h = *(static_cast<const char_ptr*>(hint) - 1);
}
char_alloc a(base());
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
- char_ptr p1 = char_traits::allocate(a, sizeof p1 + n2, h);
+ char_ptr p = char_traits::allocate(a, sizeof p + n, h);
#else
- char_ptr p1 = a.allocate(sizeof p1 + n2, h);
+ char_ptr p = a.allocate(sizeof p + n, h);
#endif
- void* p2 = detail::addressof(*p1) + sizeof p1;
- (void)align(min_align, n1, p2, n2);
- void* p3 = static_cast<char_ptr*>(p2) - 1;
- ::new(p3) char_ptr(p1);
- return static_cast<pointer>(p2);
+ 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);
+ return static_cast<pointer>(r);
}
void deallocate(pointer ptr, size_type size) {
- char_ptr* p1 = reinterpret_cast<char_ptr*>(ptr) - 1;
- char_ptr p2 = *p1;
- p1->~char_ptr();
+ char_ptr* p = reinterpret_cast<char_ptr*>(ptr) - 1;
+ char_ptr r = *p;
+ p->~char_ptr();
char_alloc a(base());
- a.deallocate(p2, size * sizeof(value_type) +
- min_align - ptr_align + sizeof p2);
+ a.deallocate(r, sizeof r + size * sizeof(value_type) +
+ min_align - 1);
}
};
diff --git a/boost/align/aligned_delete.hpp b/boost/align/aligned_delete.hpp
index c8ad64e4da..6db2bd80d0 100644
--- a/boost/align/aligned_delete.hpp
+++ b/boost/align/aligned_delete.hpp
@@ -1,5 +1,5 @@
/*
-(c) 2014 Glen Joseph Fernandes
+(c) 2014-2015 Glen Joseph Fernandes
<glenjofe -at- gmail.com>
Distributed under the Boost Software
@@ -9,15 +9,13 @@ http://boost.org/LICENSE_1_0.txt
#ifndef BOOST_ALIGN_ALIGNED_DELETE_HPP
#define BOOST_ALIGN_ALIGNED_DELETE_HPP
-#include <boost/config.hpp>
#include <boost/align/aligned_alloc.hpp>
#include <boost/align/aligned_delete_forward.hpp>
namespace boost {
namespace alignment {
-class aligned_delete {
-public:
+struct aligned_delete {
template<class T>
void operator()(T* ptr) const
BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT_EXPR(ptr->~T())) {
diff --git a/boost/align/aligned_delete_forward.hpp b/boost/align/aligned_delete_forward.hpp
index 375e576cb5..7334bebdef 100644
--- a/boost/align/aligned_delete_forward.hpp
+++ b/boost/align/aligned_delete_forward.hpp
@@ -1,5 +1,5 @@
/*
-(c) 2014 Glen Joseph Fernandes
+(c) 2014-2015 Glen Joseph Fernandes
<glenjofe -at- gmail.com>
Distributed under the Boost Software
@@ -12,7 +12,7 @@ http://boost.org/LICENSE_1_0.txt
namespace boost {
namespace alignment {
-class aligned_delete;
+struct aligned_delete;
} /* .alignment */
} /* .boost */
diff --git a/boost/align/alignment_of.hpp b/boost/align/alignment_of.hpp
index 2531ced105..fee91838af 100644
--- a/boost/align/alignment_of.hpp
+++ b/boost/align/alignment_of.hpp
@@ -9,9 +9,8 @@ http://boost.org/LICENSE_1_0.txt
#ifndef BOOST_ALIGN_ALIGNMENT_OF_HPP
#define BOOST_ALIGN_ALIGNMENT_OF_HPP
-#include <boost/config.hpp>
+#include <boost/align/detail/element_type.hpp>
#include <boost/align/alignment_of_forward.hpp>
-#include <boost/align/detail/remove_traits.hpp>
#if defined(BOOST_MSVC)
#include <boost/align/detail/alignment_of_msvc.hpp>
@@ -41,12 +40,14 @@ namespace alignment {
template<class T>
struct alignment_of
: detail::alignment_of<typename
- detail::remove_cv<typename
- detail::remove_all_extents<typename
- detail::remove_reference<T>::
- type>::type>::type>::type {
+ detail::element_type<T>::type>::type {
};
+#if !defined(BOOST_NO_CXX14_VARIABLE_TEMPLATES)
+template<class T>
+constexpr std::size_t alignment_of_v = alignment_of<T>::value;
+#endif
+
} /* .alignment */
} /* .boost */
diff --git a/boost/align/detail/address.hpp b/boost/align/detail/address.hpp
deleted file mode 100644
index b38e571534..0000000000
--- a/boost/align/detail/address.hpp
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
-(c) 2014 Glen Joseph Fernandes
-<glenjofe -at- gmail.com>
-
-Distributed under the Boost Software
-License, Version 1.0.
-http://boost.org/LICENSE_1_0.txt
-*/
-#ifndef BOOST_ALIGN_DETAIL_ADDRESS_HPP
-#define BOOST_ALIGN_DETAIL_ADDRESS_HPP
-
-#include <boost/cstdint.hpp>
-#include <cstddef>
-
-namespace boost {
-namespace alignment {
-namespace detail {
-
-#if defined(BOOST_HAS_INTPTR_T)
-typedef boost::uintptr_t address;
-#else
-typedef std::size_t address;
-#endif
-
-} /* .detail */
-} /* .alignment */
-} /* .boost */
-
-#endif
diff --git a/boost/align/detail/align.hpp b/boost/align/detail/align.hpp
index d2404b3e6d..0828c58365 100644
--- a/boost/align/detail/align.hpp
+++ b/boost/align/detail/align.hpp
@@ -9,10 +9,8 @@ http://boost.org/LICENSE_1_0.txt
#ifndef BOOST_ALIGN_DETAIL_ALIGN_HPP
#define BOOST_ALIGN_DETAIL_ALIGN_HPP
-#include <boost/assert.hpp>
-#include <boost/align/detail/address.hpp>
#include <boost/align/detail/is_alignment.hpp>
-#include <cstddef>
+#include <boost/assert.hpp>
namespace boost {
namespace alignment {
@@ -21,17 +19,17 @@ inline void* align(std::size_t alignment, std::size_t size,
void*& ptr, std::size_t& space)
{
BOOST_ASSERT(detail::is_alignment(alignment));
- std::size_t n = detail::address(ptr) & (alignment - 1);
- if (n != 0) {
- n = alignment - n;
- }
- void* p = 0;
- if (n <= space && size <= space - n) {
- p = static_cast<char*>(ptr) + n;
- ptr = p;
- space -= n;
+ if (size <= space) {
+ char* p = reinterpret_cast<char*>((reinterpret_cast<std::
+ size_t>(ptr) + alignment - 1) & ~(alignment - 1));
+ std::ptrdiff_t n = p - static_cast<char*>(ptr);
+ if (size <= space - n) {
+ ptr = p;
+ space -= n;
+ return p;
+ }
}
- return p;
+ return 0;
}
} /* .alignment */
diff --git a/boost/align/detail/align_down.hpp b/boost/align/detail/align_down.hpp
new file mode 100644
index 0000000000..a7a72efaf9
--- /dev/null
+++ b/boost/align/detail/align_down.hpp
@@ -0,0 +1,29 @@
+/*
+(c) 2015 Glen Joseph Fernandes
+<glenjofe -at- gmail.com>
+
+Distributed under the Boost Software
+License, Version 1.0.
+http://boost.org/LICENSE_1_0.txt
+*/
+#ifndef BOOST_ALIGN_DETAIL_ALIGN_DOWN_HPP
+#define BOOST_ALIGN_DETAIL_ALIGN_DOWN_HPP
+
+#include <boost/align/detail/is_alignment.hpp>
+#include <boost/align/align_down_forward.hpp>
+#include <boost/assert.hpp>
+
+namespace boost {
+namespace alignment {
+
+inline void* align_down(void* ptr, std::size_t alignment) BOOST_NOEXCEPT
+{
+ BOOST_ASSERT(detail::is_alignment(alignment));
+ return reinterpret_cast<void*>(align_down(reinterpret_cast<std::
+ size_t>(ptr), alignment));
+}
+
+} /* .alignment */
+} /* .boost */
+
+#endif
diff --git a/boost/align/detail/align_up.hpp b/boost/align/detail/align_up.hpp
new file mode 100644
index 0000000000..d52e0993ce
--- /dev/null
+++ b/boost/align/detail/align_up.hpp
@@ -0,0 +1,29 @@
+/*
+(c) 2015 Glen Joseph Fernandes
+<glenjofe -at- gmail.com>
+
+Distributed under the Boost Software
+License, Version 1.0.
+http://boost.org/LICENSE_1_0.txt
+*/
+#ifndef BOOST_ALIGN_DETAIL_ALIGN_UP_HPP
+#define BOOST_ALIGN_DETAIL_ALIGN_UP_HPP
+
+#include <boost/align/detail/is_alignment.hpp>
+#include <boost/align/align_up_forward.hpp>
+#include <boost/assert.hpp>
+
+namespace boost {
+namespace alignment {
+
+inline void* align_up(void* ptr, std::size_t alignment) BOOST_NOEXCEPT
+{
+ BOOST_ASSERT(detail::is_alignment(alignment));
+ return reinterpret_cast<void*>(align_up(reinterpret_cast<std::
+ size_t>(ptr), alignment));
+}
+
+} /* .alignment */
+} /* .boost */
+
+#endif
diff --git a/boost/align/detail/aligned_alloc.hpp b/boost/align/detail/aligned_alloc.hpp
index 28c0d2938e..0488847bbd 100644
--- a/boost/align/detail/aligned_alloc.hpp
+++ b/boost/align/detail/aligned_alloc.hpp
@@ -9,11 +9,10 @@ http://boost.org/LICENSE_1_0.txt
#ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_HPP
#define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_HPP
-#include <boost/assert.hpp>
-#include <boost/config.hpp>
+#include <boost/align/detail/is_alignment.hpp>
#include <boost/align/align.hpp>
#include <boost/align/alignment_of.hpp>
-#include <boost/align/detail/is_alignment.hpp>
+#include <boost/assert.hpp>
#include <cstdlib>
namespace boost {
@@ -24,27 +23,26 @@ inline void* aligned_alloc(std::size_t alignment, std::size_t size)
{
BOOST_ASSERT(detail::is_alignment(alignment));
enum {
- N = alignment_of<void*>::value
+ min_align = alignment_of<void*>::value
};
- if (alignment < N) {
- alignment = N;
+ if (alignment < min_align) {
+ alignment = min_align;
}
- std::size_t n = size + alignment - N;
- void* p1 = 0;
- void* p2 = std::malloc(n + sizeof p1);
- if (p2) {
- p1 = static_cast<char*>(p2) + sizeof p1;
- (void)align(alignment, size, p1, n);
- *(static_cast<void**>(p1) - 1) = p2;
+ std::size_t n = size + alignment - min_align;
+ void* r = 0;
+ void* p = std::malloc(sizeof(void*) + n);
+ if (p) {
+ r = static_cast<char*>(p) + sizeof p;
+ (void)align(alignment, size, r, n);
+ *(static_cast<void**>(r) - 1) = p;
}
- return p1;
+ return r;
}
inline void aligned_free(void* ptr) BOOST_NOEXCEPT
{
if (ptr) {
- void* p = *(static_cast<void**>(ptr) - 1);
- std::free(p);
+ std::free(*(static_cast<void**>(ptr) - 1));
}
}
diff --git a/boost/align/detail/aligned_alloc_android.hpp b/boost/align/detail/aligned_alloc_android.hpp
index 2381d8be9c..0ed28a45eb 100644
--- a/boost/align/detail/aligned_alloc_android.hpp
+++ b/boost/align/detail/aligned_alloc_android.hpp
@@ -9,10 +9,8 @@ http://boost.org/LICENSE_1_0.txt
#ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_ANDROID_HPP
#define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_ANDROID_HPP
-#include <boost/assert.hpp>
-#include <boost/config.hpp>
#include <boost/align/detail/is_alignment.hpp>
-#include <cstddef>
+#include <boost/assert.hpp>
#include <malloc.h>
namespace boost {
diff --git a/boost/align/detail/aligned_alloc_macos.hpp b/boost/align/detail/aligned_alloc_macos.hpp
index da3270b084..0bdb7c2eb1 100644
--- a/boost/align/detail/aligned_alloc_macos.hpp
+++ b/boost/align/detail/aligned_alloc_macos.hpp
@@ -9,10 +9,8 @@ http://boost.org/LICENSE_1_0.txt
#ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_MACOS_HPP
#define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_MACOS_HPP
-#include <boost/assert.hpp>
-#include <boost/config.hpp>
#include <boost/align/detail/is_alignment.hpp>
-#include <cstddef>
+#include <boost/assert.hpp>
#include <stdlib.h>
namespace boost {
diff --git a/boost/align/detail/aligned_alloc_msvc.hpp b/boost/align/detail/aligned_alloc_msvc.hpp
index 92f4291893..abeccfc4e4 100644
--- a/boost/align/detail/aligned_alloc_msvc.hpp
+++ b/boost/align/detail/aligned_alloc_msvc.hpp
@@ -9,10 +9,8 @@ http://boost.org/LICENSE_1_0.txt
#ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_MSVC_HPP
#define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_MSVC_HPP
-#include <boost/assert.hpp>
-#include <boost/config.hpp>
#include <boost/align/detail/is_alignment.hpp>
-#include <cstddef>
+#include <boost/assert.hpp>
#include <malloc.h>
namespace boost {
diff --git a/boost/align/detail/aligned_alloc_posix.hpp b/boost/align/detail/aligned_alloc_posix.hpp
index df64d75da3..931b0c4bd6 100644
--- a/boost/align/detail/aligned_alloc_posix.hpp
+++ b/boost/align/detail/aligned_alloc_posix.hpp
@@ -9,10 +9,8 @@ http://boost.org/LICENSE_1_0.txt
#ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_POSIX_HPP
#define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_POSIX_HPP
-#include <boost/assert.hpp>
-#include <boost/config.hpp>
#include <boost/align/detail/is_alignment.hpp>
-#include <cstddef>
+#include <boost/assert.hpp>
#include <stdlib.h>
namespace boost {
diff --git a/boost/align/detail/aligned_alloc_sunos.hpp b/boost/align/detail/aligned_alloc_sunos.hpp
index 0114597bad..5039c733c6 100644
--- a/boost/align/detail/aligned_alloc_sunos.hpp
+++ b/boost/align/detail/aligned_alloc_sunos.hpp
@@ -9,10 +9,8 @@ http://boost.org/LICENSE_1_0.txt
#ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_SUNOS_HPP
#define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_SUNOS_HPP
-#include <boost/assert.hpp>
-#include <boost/config.hpp>
#include <boost/align/detail/is_alignment.hpp>
-#include <cstddef>
+#include <boost/assert.hpp>
#include <stdlib.h>
namespace boost {
diff --git a/boost/align/detail/assume_aligned.hpp b/boost/align/detail/assume_aligned.hpp
index cf77086624..a1c632b94d 100644
--- a/boost/align/detail/assume_aligned.hpp
+++ b/boost/align/detail/assume_aligned.hpp
@@ -12,6 +12,6 @@ http://boost.org/LICENSE_1_0.txt
#ifndef BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_HPP
#define BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_HPP
-#define BOOST_ALIGN_ASSUME_ALIGNED(ptr, alignment)
+#define BOOST_ALIGN_ASSUME_ALIGNED(p, n)
#endif
diff --git a/boost/align/detail/assume_aligned_clang.hpp b/boost/align/detail/assume_aligned_clang.hpp
index 2ba41c6970..76046efd6d 100644
--- a/boost/align/detail/assume_aligned_clang.hpp
+++ b/boost/align/detail/assume_aligned_clang.hpp
@@ -10,10 +10,10 @@ http://boost.org/LICENSE_1_0.txt
#define BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_CLANG_HPP
#if __has_builtin(__builtin_assume_aligned)
-#define BOOST_ALIGN_ASSUME_ALIGNED(ptr, alignment) \
-(ptr) = __builtin_assume_aligned((ptr), (alignment))
+#define BOOST_ALIGN_ASSUME_ALIGNED(p, n) \
+(p) = static_cast<__typeof__(p)>(__builtin_assume_aligned((p), (n)))
#else
-#define BOOST_ALIGN_ASSUME_ALIGNED(ptr, alignment)
+#define BOOST_ALIGN_ASSUME_ALIGNED(p, n)
#endif
#endif
diff --git a/boost/align/detail/assume_aligned_gcc.hpp b/boost/align/detail/assume_aligned_gcc.hpp
index f7a545851c..38fab66175 100644
--- a/boost/align/detail/assume_aligned_gcc.hpp
+++ b/boost/align/detail/assume_aligned_gcc.hpp
@@ -12,7 +12,7 @@ http://boost.org/LICENSE_1_0.txt
#ifndef BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_GCC_HPP
#define BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_GCC_HPP
-#define BOOST_ALIGN_ASSUME_ALIGNED(ptr, alignment) \
-(ptr) = __builtin_assume_aligned((ptr), (alignment))
+#define BOOST_ALIGN_ASSUME_ALIGNED(p, n) \
+(p) = static_cast<__typeof__(p)>(__builtin_assume_aligned((p), (n)))
#endif
diff --git a/boost/align/detail/assume_aligned_intel.hpp b/boost/align/detail/assume_aligned_intel.hpp
index e9ec2dbeb4..1944f3de51 100644
--- a/boost/align/detail/assume_aligned_intel.hpp
+++ b/boost/align/detail/assume_aligned_intel.hpp
@@ -12,7 +12,7 @@ http://boost.org/LICENSE_1_0.txt
#ifndef BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_INTEL_HPP
#define BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_INTEL_HPP
-#define BOOST_ALIGN_ASSUME_ALIGNED(ptr, alignment) \
-__assume_aligned((ptr), (alignment))
+#define BOOST_ALIGN_ASSUME_ALIGNED(p, n) \
+__assume_aligned((p), (n))
#endif
diff --git a/boost/align/detail/assume_aligned_msvc.hpp b/boost/align/detail/assume_aligned_msvc.hpp
index 97c1fb1add..84c4d59220 100644
--- a/boost/align/detail/assume_aligned_msvc.hpp
+++ b/boost/align/detail/assume_aligned_msvc.hpp
@@ -12,9 +12,9 @@ http://boost.org/LICENSE_1_0.txt
#ifndef BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_MSVC_HPP
#define BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_MSVC_HPP
-#include <stddef.h>
+#include <cstddef>
-#define BOOST_ALIGN_ASSUME_ALIGNED(ptr, alignment) \
-__assume((uintptr_t(ptr) & ((alignment) - 1)) == 0)
+#define BOOST_ALIGN_ASSUME_ALIGNED(p, n) \
+__assume((reinterpret_cast<std::size_t>(p) & ((n) - 1)) == 0)
#endif
diff --git a/boost/align/detail/remove_traits.hpp b/boost/align/detail/element_type.hpp
index 86a98d459a..793e25ed39 100644
--- a/boost/align/detail/remove_traits.hpp
+++ b/boost/align/detail/element_type.hpp
@@ -1,13 +1,13 @@
/*
-(c) 2014 Glen Joseph Fernandes
+(c) 2015 Glen Joseph Fernandes
<glenjofe -at- gmail.com>
Distributed under the Boost Software
License, Version 1.0.
http://boost.org/LICENSE_1_0.txt
*/
-#ifndef BOOST_ALIGN_DETAIL_REMOVE_TRAITS_HPP
-#define BOOST_ALIGN_DETAIL_REMOVE_TRAITS_HPP
+#ifndef BOOST_ALIGN_DETAIL_ELEMENT_TYPE_HPP
+#define BOOST_ALIGN_DETAIL_ELEMENT_TYPE_HPP
#include <boost/config.hpp>
@@ -22,9 +22,14 @@ namespace alignment {
namespace detail {
#if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
-using std::remove_reference;
-using std::remove_all_extents;
-using std::remove_cv;
+template<class T>
+struct element_type {
+ typedef typename
+ std::remove_cv<typename
+ std::remove_all_extents<typename
+ std::remove_reference<T>::
+ type>::type>::type type;
+};
#else
template<class T>
struct remove_reference {
@@ -83,6 +88,15 @@ struct remove_cv {
typedef typename remove_volatile<typename
remove_const<T>::type>::type type;
};
+
+template<class T>
+struct element_type {
+ typedef typename
+ remove_cv<typename
+ remove_all_extents<typename
+ remove_reference<T>::
+ type>::type>::type type;
+};
#endif
} /* .detail */
diff --git a/boost/align/detail/is_aligned.hpp b/boost/align/detail/is_aligned.hpp
index cb45be3433..e9c97ec711 100644
--- a/boost/align/detail/is_aligned.hpp
+++ b/boost/align/detail/is_aligned.hpp
@@ -9,20 +9,25 @@ http://boost.org/LICENSE_1_0.txt
#ifndef BOOST_ALIGN_DETAIL_IS_ALIGNED_HPP
#define BOOST_ALIGN_DETAIL_IS_ALIGNED_HPP
-#include <boost/assert.hpp>
-#include <boost/config.hpp>
-#include <boost/align/detail/address.hpp>
#include <boost/align/detail/is_alignment.hpp>
-#include <cstddef>
+#include <boost/align/is_aligned_forward.hpp>
+#include <boost/assert.hpp>
namespace boost {
namespace alignment {
+inline bool is_aligned(const void* ptr, std::size_t alignment)
+ BOOST_NOEXCEPT
+{
+ BOOST_ASSERT(detail::is_alignment(alignment));
+ return is_aligned(reinterpret_cast<std::size_t>(ptr), alignment);
+}
+
inline bool is_aligned(std::size_t alignment, const void* ptr)
BOOST_NOEXCEPT
{
BOOST_ASSERT(detail::is_alignment(alignment));
- return (detail::address(ptr) & (alignment - 1)) == 0;
+ return is_aligned(reinterpret_cast<std::size_t>(ptr), alignment);
}
} /* .alignment */
diff --git a/boost/align/detail/max_align.hpp b/boost/align/detail/max_align.hpp
index daa0413935..8ae6901c19 100644
--- a/boost/align/detail/max_align.hpp
+++ b/boost/align/detail/max_align.hpp
@@ -11,7 +11,6 @@ http://boost.org/LICENSE_1_0.txt
#include <boost/align/detail/max_size.hpp>
#include <boost/align/alignment_of.hpp>
-#include <cstddef>
namespace boost {
namespace alignment {
diff --git a/boost/align/is_aligned.hpp b/boost/align/is_aligned.hpp
index 5d99847e4a..cbace96077 100644
--- a/boost/align/is_aligned.hpp
+++ b/boost/align/is_aligned.hpp
@@ -10,5 +10,18 @@ http://boost.org/LICENSE_1_0.txt
#define BOOST_ALIGN_IS_ALIGNED_HPP
#include <boost/align/detail/is_aligned.hpp>
+#include <boost/align/is_aligned_forward.hpp>
+
+namespace boost {
+namespace alignment {
+
+BOOST_CONSTEXPR inline bool is_aligned(std::size_t value,
+ std::size_t alignment) BOOST_NOEXCEPT
+{
+ return (value & (alignment - 1)) == 0;
+}
+
+} /* .alignment */
+} /* .boost */
#endif
diff --git a/boost/align/is_aligned_forward.hpp b/boost/align/is_aligned_forward.hpp
new file mode 100644
index 0000000000..d1bcbc19dd
--- /dev/null
+++ b/boost/align/is_aligned_forward.hpp
@@ -0,0 +1,24 @@
+/*
+(c) 2015 Glen Joseph Fernandes
+<glenjofe -at- gmail.com>
+
+Distributed under the Boost Software
+License, Version 1.0.
+http://boost.org/LICENSE_1_0.txt
+*/
+#ifndef BOOST_ALIGN_IS_ALIGNED_FORWARD_HPP
+#define BOOST_ALIGN_IS_ALIGNED_FORWARD_HPP
+
+#include <boost/config.hpp>
+#include <cstddef>
+
+namespace boost {
+namespace alignment {
+
+BOOST_CONSTEXPR bool is_aligned(std::size_t value,
+ std::size_t alignment) BOOST_NOEXCEPT;
+
+} /* .alignment */
+} /* .boost */
+
+#endif