summaryrefslogtreecommitdiff
path: root/boost/align/detail
diff options
context:
space:
mode:
Diffstat (limited to 'boost/align/detail')
-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
18 files changed, 129 insertions, 96 deletions
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 {