diff options
author | Chanho Park <chanho61.park@samsung.com> | 2014-12-11 18:55:56 +0900 |
---|---|---|
committer | Chanho Park <chanho61.park@samsung.com> | 2014-12-11 18:55:56 +0900 |
commit | 08c1e93fa36a49f49325a07fe91ff92c964c2b6c (patch) | |
tree | 7a7053ceb8874b28ec4b868d4c49b500008a102e /boost/align | |
parent | bb4dd8289b351fae6b55e303f189127a394a1edd (diff) | |
download | boost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.tar.gz boost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.tar.bz2 boost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.zip |
Imported Upstream version 1.57.0upstream/1.57.0
Diffstat (limited to 'boost/align')
36 files changed, 1428 insertions, 0 deletions
diff --git a/boost/align/align.hpp b/boost/align/align.hpp new file mode 100644 index 0000000000..1600a243c0 --- /dev/null +++ b/boost/align/align.hpp @@ -0,0 +1,20 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + http://boost.org/LICENSE_1_0.txt +*/ +#ifndef BOOST_ALIGN_ALIGN_HPP +#define BOOST_ALIGN_ALIGN_HPP + +#include <boost/config.hpp> + +#if !defined(BOOST_NO_CXX11_STD_ALIGN) +#include <boost/align/detail/align_cxx11.hpp> +#else +#include <boost/align/detail/align.hpp> +#endif + +#endif diff --git a/boost/align/aligned_alloc.hpp b/boost/align/aligned_alloc.hpp new file mode 100644 index 0000000000..1e4f2b783b --- /dev/null +++ b/boost/align/aligned_alloc.hpp @@ -0,0 +1,42 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + http://boost.org/LICENSE_1_0.txt +*/ +#ifndef BOOST_ALIGN_ALIGNED_ALLOC_HPP +#define BOOST_ALIGN_ALIGNED_ALLOC_HPP + +#include <boost/config.hpp> + +#if defined(BOOST_HAS_UNISTD_H) +#include <unistd.h> +#endif + +#if defined(__APPLE__) || defined(__APPLE_CC__) || defined(macintosh) +#include <AvailabilityMacros.h> +#endif + +#if defined(_MSC_VER) +#include <boost/align/detail/aligned_alloc_msvc.hpp> +#elif defined(__MINGW32__) && (__MSVCRT_VERSION__ >= 0x0700) +#include <boost/align/detail/aligned_alloc_msvc.hpp> +#elif MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 +#include <boost/align/detail/aligned_alloc_posix.hpp> +#elif MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 +#include <boost/align/detail/aligned_alloc_macos.hpp> +#elif defined(__ANDROID__) +#include <boost/align/detail/aligned_alloc_android.hpp> +#elif defined(__SunOS_5_11) || defined(__SunOS_5_12) +#include <boost/align/detail/aligned_alloc_posix.hpp> +#elif defined(sun) || defined(__sun) +#include <boost/align/detail/aligned_alloc_sunos.hpp> +#elif (_POSIX_C_SOURCE >= 200112L) || (_XOPEN_SOURCE >= 600) +#include <boost/align/detail/aligned_alloc_posix.hpp> +#else +#include <boost/align/detail/aligned_alloc.hpp> +#endif + +#endif diff --git a/boost/align/aligned_allocator.hpp b/boost/align/aligned_allocator.hpp new file mode 100644 index 0000000000..114e37bb1c --- /dev/null +++ b/boost/align/aligned_allocator.hpp @@ -0,0 +1,168 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + 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_align.hpp> +#include <boost/align/detail/max_count_of.hpp> +#include <new> + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) +#include <utility> +#endif + +namespace boost { + namespace alignment { + template<class T, std::size_t Alignment> + class aligned_allocator { + BOOST_STATIC_ASSERT(detail:: + is_alignment_constant<Alignment>::value); + + public: + typedef T value_type; + typedef T* pointer; + typedef const T* const_pointer; + typedef void* void_pointer; + typedef const void* const_void_pointer; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + typedef T& reference; + typedef const T& const_reference; + + private: + typedef detail::max_align<Alignment, + alignment_of<value_type>::value> MaxAlign; + + public: + template<class U> + struct rebind { + typedef aligned_allocator<U, Alignment> other; + }; + +#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) + aligned_allocator() + BOOST_NOEXCEPT = default; +#else + aligned_allocator() + BOOST_NOEXCEPT { + } +#endif + + template<class U> + aligned_allocator(const aligned_allocator<U, + Alignment>&) BOOST_NOEXCEPT { + } + + pointer address(reference value) const + BOOST_NOEXCEPT { + return detail::addressof(value); + } + + 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(MaxAlign::value, + sizeof(T) * size); + if (!p && size > 0) { + boost::throw_exception(std::bad_alloc()); + } + return static_cast<T*>(p); + } + + void deallocate(pointer ptr, size_type) { + alignment::aligned_free(ptr); + } + + BOOST_CONSTEXPR size_type max_size() const + BOOST_NOEXCEPT { + return detail::max_count_of<T>::value; + } + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) +#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)...); + } +#else + template<class U, class V> + void construct(U* ptr, V&& value) { + void* p = ptr; + ::new(p) 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); + } +#endif + + template<class U> + void construct(U* ptr) { + void* p = ptr; + ::new(p) U(); + } + + template<class U> + void destroy(U* ptr) { + (void)ptr; + ptr->~U(); + } + }; + + template<std::size_t Alignment> + class aligned_allocator<void, Alignment> { + BOOST_STATIC_ASSERT(detail:: + is_alignment_constant<Alignment>::value); + + public: + typedef void value_type; + typedef void* pointer; + typedef const void* const_pointer; + + template<class U> + struct rebind { + typedef aligned_allocator<U, Alignment> other; + }; + }; + + template<class T1, class T2, std::size_t Alignment> + 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 + { + return false; + } + } +} + +#endif diff --git a/boost/align/aligned_allocator_adaptor.hpp b/boost/align/aligned_allocator_adaptor.hpp new file mode 100644 index 0000000000..f6e0bef8aa --- /dev/null +++ b/boost/align/aligned_allocator_adaptor.hpp @@ -0,0 +1,187 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + 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 <new> + +#if !defined(BOOST_NO_CXX11_ALLOCATOR) +#include <memory> +#endif + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) +#include <utility> +#endif + +namespace boost { + namespace alignment { + template<class Allocator, std::size_t Alignment> + class aligned_allocator_adaptor + : public Allocator { + 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> CharAlloc; + + typedef typename Traits:: + template rebind_traits<char> CharTraits; + + typedef typename CharTraits::pointer CharPtr; +#else + typedef typename Allocator:: + template rebind<char>::other CharAlloc; + + typedef typename CharAlloc::pointer CharPtr; +#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::ptrdiff_t difference_type; + + private: + typedef detail::max_align<Alignment, + detail::max_align<alignment_of<value_type>::value, + alignment_of<CharPtr>::value>::value> MaxAlign; + + public: + template<class U> + struct rebind { +#if !defined(BOOST_NO_CXX11_ALLOCATOR) + 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; +#endif + }; + +#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) + aligned_allocator_adaptor() = default; +#else + aligned_allocator_adaptor() + : Allocator() { + } +#endif + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + template<class A> + explicit aligned_allocator_adaptor(A&& alloc) + BOOST_NOEXCEPT + : Allocator(std::forward<A>(alloc)) { + } +#else + template<class A> + explicit aligned_allocator_adaptor(const A& alloc) + BOOST_NOEXCEPT + : Allocator(alloc) { + } +#endif + + template<class U> + aligned_allocator_adaptor(const + aligned_allocator_adaptor<U, Alignment>& other) + BOOST_NOEXCEPT + : Allocator(other.base()) { + } + + Allocator& base() + BOOST_NOEXCEPT { + return static_cast<Allocator&>(*this); + } + + const Allocator& base() const + BOOST_NOEXCEPT { + return static_cast<const Allocator&>(*this); + } + + pointer allocate(size_type size) { + std::size_t n1 = size * sizeof(value_type); + std::size_t n2 = n1 + MaxAlign::value - 1; + CharAlloc a(base()); + CharPtr p1 = a.allocate(sizeof p1 + n2); + void* p2 = detail::addressof(*p1) + sizeof p1; + (void)align(MaxAlign::value, n1, p2, n2); + void* p3 = static_cast<CharPtr*>(p2) - 1; + ::new(p3) CharPtr(p1); + return static_cast<pointer>(p2); + } + + pointer allocate(size_type size, const_void_pointer hint) { + std::size_t n1 = size * sizeof(value_type); + std::size_t n2 = n1 + MaxAlign::value - 1; + CharPtr h = CharPtr(); + if (hint) { + h = *(static_cast<const CharPtr*>(hint) - 1); + } + CharAlloc a(base()); +#if !defined(BOOST_NO_CXX11_ALLOCATOR) + CharPtr p1 = CharTraits::allocate(a, sizeof p1 + + n2, h); +#else + CharPtr p1 = a.allocate(sizeof p1 + n2, h); +#endif + void* p2 = detail::addressof(*p1) + sizeof p1; + (void)align(MaxAlign::value, n1, p2, n2); + void* p3 = static_cast<CharPtr*>(p2) - 1; + ::new(p3) CharPtr(p1); + return static_cast<pointer>(p2); + } + + void deallocate(pointer ptr, size_type size) { + CharPtr* p1 = reinterpret_cast<CharPtr*>(ptr) - 1; + CharPtr p2 = *p1; + p1->~CharPtr(); + CharAlloc a(base()); + a.deallocate(p2, size * sizeof(value_type) + + MaxAlign::value + sizeof p2); + } + }; + + template<class A1, class A2, std::size_t Alignment> + inline bool operator==(const aligned_allocator_adaptor<A1, + Alignment>& a, const aligned_allocator_adaptor<A2, + Alignment>& b) BOOST_NOEXCEPT + { + return a.base() == b.base(); + } + + template<class A1, class A2, std::size_t Alignment> + inline bool operator!=(const aligned_allocator_adaptor<A1, + Alignment>& a, const aligned_allocator_adaptor<A2, + Alignment>& b) BOOST_NOEXCEPT + { + return !(a == b); + } + } +} + +#endif diff --git a/boost/align/aligned_allocator_adaptor_forward.hpp b/boost/align/aligned_allocator_adaptor_forward.hpp new file mode 100644 index 0000000000..2bd8deecfa --- /dev/null +++ b/boost/align/aligned_allocator_adaptor_forward.hpp @@ -0,0 +1,21 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + http://boost.org/LICENSE_1_0.txt +*/ +#ifndef BOOST_ALIGN_ALIGNED_ALLOCATOR_ADAPTOR_FORWARD_HPP +#define BOOST_ALIGN_ALIGNED_ALLOCATOR_ADAPTOR_FORWARD_HPP + +#include <cstddef> + +namespace boost { + namespace alignment { + template<class Allocator, std::size_t Alignment = 1> + class aligned_allocator_adaptor; + } +} + +#endif diff --git a/boost/align/aligned_allocator_forward.hpp b/boost/align/aligned_allocator_forward.hpp new file mode 100644 index 0000000000..48120e2e7d --- /dev/null +++ b/boost/align/aligned_allocator_forward.hpp @@ -0,0 +1,21 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + http://boost.org/LICENSE_1_0.txt +*/ +#ifndef BOOST_ALIGN_ALIGNED_ALLOCATOR_FORWARD_HPP +#define BOOST_ALIGN_ALIGNED_ALLOCATOR_FORWARD_HPP + +#include <cstddef> + +namespace boost { + namespace alignment { + template<class T, std::size_t Alignment = 1> + class aligned_allocator; + } +} + +#endif diff --git a/boost/align/aligned_delete.hpp b/boost/align/aligned_delete.hpp new file mode 100644 index 0000000000..479fbb16be --- /dev/null +++ b/boost/align/aligned_delete.hpp @@ -0,0 +1,32 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + 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: + template<class T> + void operator()(T* ptr) const + BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT_EXPR(ptr->~T())) { + if (ptr) { + ptr->~T(); + alignment::aligned_free(ptr); + } + } + }; + } +} + +#endif diff --git a/boost/align/aligned_delete_forward.hpp b/boost/align/aligned_delete_forward.hpp new file mode 100644 index 0000000000..9392025375 --- /dev/null +++ b/boost/align/aligned_delete_forward.hpp @@ -0,0 +1,18 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + http://boost.org/LICENSE_1_0.txt +*/ +#ifndef BOOST_ALIGN_ALIGNED_DELETE_FORWARD_HPP +#define BOOST_ALIGN_ALIGNED_DELETE_FORWARD_HPP + +namespace boost { + namespace alignment { + class aligned_delete; + } +} + +#endif diff --git a/boost/align/alignment_of.hpp b/boost/align/alignment_of.hpp new file mode 100644 index 0000000000..1862f0f892 --- /dev/null +++ b/boost/align/alignment_of.hpp @@ -0,0 +1,49 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + 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/alignment_of_forward.hpp> +#include <boost/align/detail/remove_traits.hpp> + +#if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) +#include <boost/align/detail/alignment_of_cxx11.hpp> +#elif defined(BOOST_MSVC) +#include <boost/align/detail/alignment_of_msvc.hpp> +#elif defined(BOOST_CLANG) +#include <boost/align/detail/alignment_of_clang.hpp> +#elif defined(__ghs__) && (__GHS_VERSION_NUMBER >= 600) +#include <boost/align/detail/alignment_of_gcc.hpp> +#elif defined(__CODEGEARC__) +#include <boost/align/detail/alignment_of_codegear.hpp> +#elif defined(__GNUC__) && defined(__unix__) && !defined(__LP64__) +#include <boost/align/detail/alignment_of.hpp> +#elif __GNUC__ > 4 +#include <boost/align/detail/alignment_of_gcc.hpp> +#elif (__GNUC__ == 4) && (__GNUC_MINOR__ >= 3) +#include <boost/align/detail/alignment_of_gcc.hpp> +#else +#include <boost/align/detail/alignment_of.hpp> +#endif + +namespace boost { + 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 { + }; + } +} + +#endif diff --git a/boost/align/alignment_of_forward.hpp b/boost/align/alignment_of_forward.hpp new file mode 100644 index 0000000000..47785e24b4 --- /dev/null +++ b/boost/align/alignment_of_forward.hpp @@ -0,0 +1,19 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + http://boost.org/LICENSE_1_0.txt +*/ +#ifndef BOOST_ALIGN_ALIGNMENT_OF_FORWARD_HPP +#define BOOST_ALIGN_ALIGNMENT_OF_FORWARD_HPP + +namespace boost { + namespace alignment { + template<class T> + struct alignment_of; + } +} + +#endif diff --git a/boost/align/detail/address.hpp b/boost/align/detail/address.hpp new file mode 100644 index 0000000000..a4f3a6e84d --- /dev/null +++ b/boost/align/detail/address.hpp @@ -0,0 +1,27 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot 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_t; +#else + typedef std::size_t address_t; +#endif + } + } +} + +#endif diff --git a/boost/align/detail/addressof.hpp b/boost/align/detail/addressof.hpp new file mode 100644 index 0000000000..d9d6f78ebc --- /dev/null +++ b/boost/align/detail/addressof.hpp @@ -0,0 +1,32 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + http://boost.org/LICENSE_1_0.txt +*/ +#ifndef BOOST_ALIGN_DETAIL_ADDRESSOF_HPP +#define BOOST_ALIGN_DETAIL_ADDRESSOF_HPP + +#include <boost/config.hpp> + +#if !defined(BOOST_NO_CXX11_ADDRESSOF) +#include <memory> +#else +#include <boost/core/addressof.hpp> +#endif + +namespace boost { + namespace alignment { + namespace detail { +#if !defined(BOOST_NO_CXX11_ADDRESSOF) + using std::addressof; +#else + using boost::addressof; +#endif + } + } +} + +#endif diff --git a/boost/align/detail/align.hpp b/boost/align/detail/align.hpp new file mode 100644 index 0000000000..e3a90dffda --- /dev/null +++ b/boost/align/detail/align.hpp @@ -0,0 +1,38 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + 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> + +namespace boost { + namespace alignment { + 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_t(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; + } + return p; + } + } +} + +#endif diff --git a/boost/align/detail/align_cxx11.hpp b/boost/align/detail/align_cxx11.hpp new file mode 100644 index 0000000000..6672a7e0e9 --- /dev/null +++ b/boost/align/detail/align_cxx11.hpp @@ -0,0 +1,20 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + http://boost.org/LICENSE_1_0.txt +*/ +#ifndef BOOST_ALIGN_DETAIL_ALIGN_CXX11_HPP +#define BOOST_ALIGN_DETAIL_ALIGN_CXX11_HPP + +#include <memory> + +namespace boost { + namespace alignment { + using std::align; + } +} + +#endif diff --git a/boost/align/detail/aligned_alloc.hpp b/boost/align/detail/aligned_alloc.hpp new file mode 100644 index 0000000000..147b0de0f9 --- /dev/null +++ b/boost/align/detail/aligned_alloc.hpp @@ -0,0 +1,50 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + 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/align.hpp> +#include <boost/align/alignment_of.hpp> +#include <boost/align/detail/is_alignment.hpp> +#include <cstdlib> + +namespace boost { + namespace alignment { + inline void* aligned_alloc(std::size_t alignment, + std::size_t size) BOOST_NOEXCEPT + { + BOOST_ASSERT(detail::is_alignment(alignment)); + if (alignment < alignment_of<void*>::value) { + alignment = alignment_of<void*>::value; + } + std::size_t n = size + alignment - 1; + 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; + } + return p1; + } + + inline void aligned_free(void* ptr) + BOOST_NOEXCEPT + { + if (ptr) { + void* p = *(static_cast<void**>(ptr) - 1); + std::free(p); + } + } + } +} + +#endif diff --git a/boost/align/detail/aligned_alloc_android.hpp b/boost/align/detail/aligned_alloc_android.hpp new file mode 100644 index 0000000000..2b813becae --- /dev/null +++ b/boost/align/detail/aligned_alloc_android.hpp @@ -0,0 +1,35 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + 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 <malloc.h> + +namespace boost { + namespace alignment { + inline void* aligned_alloc(std::size_t alignment, + std::size_t size) BOOST_NOEXCEPT + { + BOOST_ASSERT(detail::is_alignment(alignment)); + return ::memalign(alignment, size); + } + + inline void aligned_free(void* ptr) + BOOST_NOEXCEPT + { + ::free(ptr); + } + } +} + +#endif diff --git a/boost/align/detail/aligned_alloc_macos.hpp b/boost/align/detail/aligned_alloc_macos.hpp new file mode 100644 index 0000000000..346eabfc58 --- /dev/null +++ b/boost/align/detail/aligned_alloc_macos.hpp @@ -0,0 +1,45 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + 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 <stdlib.h> + +namespace boost { + namespace alignment { + inline void* aligned_alloc(std::size_t alignment, + std::size_t size) BOOST_NOEXCEPT + { + BOOST_ASSERT(detail::is_alignment(alignment)); + if (!size) { + return 0; + } + if (alignment < sizeof(void*)) { + alignment = sizeof(void*); + } + void* p; + if (::posix_memalign(&p, alignment, size) != 0) { + p = 0; + } + return p; + } + + inline void aligned_free(void* ptr) + BOOST_NOEXCEPT + { + ::free(ptr); + } + } +} + +#endif diff --git a/boost/align/detail/aligned_alloc_msvc.hpp b/boost/align/detail/aligned_alloc_msvc.hpp new file mode 100644 index 0000000000..570a898c59 --- /dev/null +++ b/boost/align/detail/aligned_alloc_msvc.hpp @@ -0,0 +1,35 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + 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 <malloc.h> + +namespace boost { + namespace alignment { + inline void* aligned_alloc(std::size_t alignment, + std::size_t size) BOOST_NOEXCEPT + { + BOOST_ASSERT(detail::is_alignment(alignment)); + return ::_aligned_malloc(size, alignment); + } + + inline void aligned_free(void* ptr) + BOOST_NOEXCEPT + { + ::_aligned_free(ptr); + } + } +} + +#endif diff --git a/boost/align/detail/aligned_alloc_posix.hpp b/boost/align/detail/aligned_alloc_posix.hpp new file mode 100644 index 0000000000..ceab4cbe9c --- /dev/null +++ b/boost/align/detail/aligned_alloc_posix.hpp @@ -0,0 +1,42 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + 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 <stdlib.h> + +namespace boost { + namespace alignment { + inline void* aligned_alloc(std::size_t alignment, + std::size_t size) BOOST_NOEXCEPT + { + BOOST_ASSERT(detail::is_alignment(alignment)); + if (alignment < sizeof(void*)) { + alignment = sizeof(void*); + } + void* p; + if (::posix_memalign(&p, alignment, size) != 0) { + p = 0; + } + return p; + } + + inline void aligned_free(void* ptr) + BOOST_NOEXCEPT + { + ::free(ptr); + } + } +} + +#endif diff --git a/boost/align/detail/aligned_alloc_sunos.hpp b/boost/align/detail/aligned_alloc_sunos.hpp new file mode 100644 index 0000000000..a2373bd26b --- /dev/null +++ b/boost/align/detail/aligned_alloc_sunos.hpp @@ -0,0 +1,35 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + 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 <stdlib.h> + +namespace boost { + namespace alignment { + inline void* aligned_alloc(std::size_t alignment, + std::size_t size) BOOST_NOEXCEPT + { + BOOST_ASSERT(detail::is_alignment(alignment)); + return ::memalign(alignment, size); + } + + inline void aligned_free(void* ptr) + BOOST_NOEXCEPT + { + ::free(ptr); + } + } +} + +#endif diff --git a/boost/align/detail/alignment_of.hpp b/boost/align/detail/alignment_of.hpp new file mode 100644 index 0000000000..1fa3070ce0 --- /dev/null +++ b/boost/align/detail/alignment_of.hpp @@ -0,0 +1,27 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + http://boost.org/LICENSE_1_0.txt +*/ +#ifndef BOOST_ALIGN_DETAIL_ALIGNMENT_OF_HPP +#define BOOST_ALIGN_DETAIL_ALIGNMENT_OF_HPP + +#include <boost/align/detail/min_size.hpp> +#include <boost/align/detail/offset_object.hpp> + +namespace boost { + namespace alignment { + namespace detail { + template<class T> + struct alignment_of + : min_size<sizeof(T), + sizeof(offset_object<T>) - sizeof(T)>::type { + }; + } + } +} + +#endif diff --git a/boost/align/detail/alignment_of_clang.hpp b/boost/align/detail/alignment_of_clang.hpp new file mode 100644 index 0000000000..18d7c718db --- /dev/null +++ b/boost/align/detail/alignment_of_clang.hpp @@ -0,0 +1,26 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + http://boost.org/LICENSE_1_0.txt +*/ +#ifndef BOOST_ALIGN_DETAIL_ALIGNMENT_OF_CLANG_HPP +#define BOOST_ALIGN_DETAIL_ALIGNMENT_OF_CLANG_HPP + +#include <boost/align/detail/integral_constant.hpp> +#include <cstddef> + +namespace boost { + namespace alignment { + namespace detail { + template<class T> + struct alignment_of + : integral_constant<std::size_t, __alignof(T)> { + }; + } + } +} + +#endif diff --git a/boost/align/detail/alignment_of_codegear.hpp b/boost/align/detail/alignment_of_codegear.hpp new file mode 100644 index 0000000000..9074967f49 --- /dev/null +++ b/boost/align/detail/alignment_of_codegear.hpp @@ -0,0 +1,26 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + http://boost.org/LICENSE_1_0.txt +*/ +#ifndef BOOST_ALIGN_DETAIL_ALIGNMENT_OF_CODEGEAR_HPP +#define BOOST_ALIGN_DETAIL_ALIGNMENT_OF_CODEGEAR_HPP + +#include <boost/align/detail/integral_constant.hpp> +#include <cstddef> + +namespace boost { + namespace alignment { + namespace detail { + template<class T> + struct alignment_of + : integral_constant<std::size_t, alignof(T)> { + }; + } + } +} + +#endif diff --git a/boost/align/detail/alignment_of_cxx11.hpp b/boost/align/detail/alignment_of_cxx11.hpp new file mode 100644 index 0000000000..d5d00a08b4 --- /dev/null +++ b/boost/align/detail/alignment_of_cxx11.hpp @@ -0,0 +1,22 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + http://boost.org/LICENSE_1_0.txt +*/ +#ifndef BOOST_ALIGN_DETAIL_ALIGNMENT_OF_CXX11_HPP +#define BOOST_ALIGN_DETAIL_ALIGNMENT_OF_CXX11_HPP + +#include <type_traits> + +namespace boost { + namespace alignment { + namespace detail { + using std::alignment_of; + } + } +} + +#endif diff --git a/boost/align/detail/alignment_of_gcc.hpp b/boost/align/detail/alignment_of_gcc.hpp new file mode 100644 index 0000000000..3044b2a3ec --- /dev/null +++ b/boost/align/detail/alignment_of_gcc.hpp @@ -0,0 +1,26 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + http://boost.org/LICENSE_1_0.txt +*/ +#ifndef BOOST_ALIGN_DETAIL_ALIGNMENT_OF_GCC_HPP +#define BOOST_ALIGN_DETAIL_ALIGNMENT_OF_GCC_HPP + +#include <boost/align/detail/integral_constant.hpp> +#include <cstddef> + +namespace boost { + namespace alignment { + namespace detail { + template<class T> + struct alignment_of + : integral_constant<std::size_t, __alignof__(T)> { + }; + } + } +} + +#endif diff --git a/boost/align/detail/alignment_of_msvc.hpp b/boost/align/detail/alignment_of_msvc.hpp new file mode 100644 index 0000000000..a86f785ddc --- /dev/null +++ b/boost/align/detail/alignment_of_msvc.hpp @@ -0,0 +1,27 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + http://boost.org/LICENSE_1_0.txt +*/ +#ifndef BOOST_ALIGN_DETAIL_ALIGNMENT_OF_MSVC_HPP +#define BOOST_ALIGN_DETAIL_ALIGNMENT_OF_MSVC_HPP + +#include <boost/align/detail/min_size.hpp> +#include <boost/align/detail/offset_object.hpp> + +namespace boost { + namespace alignment { + namespace detail { + template<class T> + struct alignment_of + : min_size<sizeof(T), + offsetof(offset_object<T>, object)>::type { + }; + } + } +} + +#endif diff --git a/boost/align/detail/integral_constant.hpp b/boost/align/detail/integral_constant.hpp new file mode 100644 index 0000000000..332aade943 --- /dev/null +++ b/boost/align/detail/integral_constant.hpp @@ -0,0 +1,46 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + http://boost.org/LICENSE_1_0.txt +*/ +#ifndef BOOST_ALIGN_DETAIL_INTEGRAL_CONSTANT_HPP +#define BOOST_ALIGN_DETAIL_INTEGRAL_CONSTANT_HPP + +#include <boost/config.hpp> + +#if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) +#include <type_traits> +#endif + +namespace boost { + namespace alignment { + namespace detail { +#if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) + using std::integral_constant; +#else + template<class T, T Value> + struct integral_constant { + typedef T value_type; + typedef integral_constant<T, Value> type; + +#if !defined(BOOST_NO_CXX11_CONSTEXPR) + constexpr operator value_type() const { + return Value; + } + + static constexpr T value = Value; +#else + enum { + value = Value + }; +#endif + }; +#endif + } + } +} + +#endif diff --git a/boost/align/detail/is_aligned.hpp b/boost/align/detail/is_aligned.hpp new file mode 100644 index 0000000000..41fb80581f --- /dev/null +++ b/boost/align/detail/is_aligned.hpp @@ -0,0 +1,29 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + 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> + +namespace boost { + namespace alignment { + inline bool is_aligned(std::size_t alignment, + const void* ptr) BOOST_NOEXCEPT + { + BOOST_ASSERT(detail::is_alignment(alignment)); + return (detail::address_t(ptr) & (alignment - 1)) == 0; + } + } +} + +#endif diff --git a/boost/align/detail/is_alignment.hpp b/boost/align/detail/is_alignment.hpp new file mode 100644 index 0000000000..532198363f --- /dev/null +++ b/boost/align/detail/is_alignment.hpp @@ -0,0 +1,27 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + http://boost.org/LICENSE_1_0.txt +*/ +#ifndef BOOST_ALIGN_DETAIL_IS_ALIGNMENT_HPP +#define BOOST_ALIGN_DETAIL_IS_ALIGNMENT_HPP + +#include <boost/config.hpp> +#include <cstddef> + +namespace boost { + namespace alignment { + namespace detail { + BOOST_CONSTEXPR inline bool is_alignment(std::size_t + value) BOOST_NOEXCEPT + { + return (value > 0) && ((value & (value - 1)) == 0); + } + } + } +} + +#endif diff --git a/boost/align/detail/is_alignment_constant.hpp b/boost/align/detail/is_alignment_constant.hpp new file mode 100644 index 0000000000..8f422608ae --- /dev/null +++ b/boost/align/detail/is_alignment_constant.hpp @@ -0,0 +1,27 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + http://boost.org/LICENSE_1_0.txt +*/ +#ifndef BOOST_ALIGN_DETAIL_IS_ALIGNMENT_CONSTANT_HPP +#define BOOST_ALIGN_DETAIL_IS_ALIGNMENT_CONSTANT_HPP + +#include <boost/align/detail/integral_constant.hpp> +#include <cstddef> + +namespace boost { + namespace alignment { + namespace detail { + template<std::size_t N> + struct is_alignment_constant + : integral_constant<bool, + (N > 0) && ((N & (N - 1)) == 0)> { + }; + } + } +} + +#endif diff --git a/boost/align/detail/max_align.hpp b/boost/align/detail/max_align.hpp new file mode 100644 index 0000000000..775121d83a --- /dev/null +++ b/boost/align/detail/max_align.hpp @@ -0,0 +1,27 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + http://boost.org/LICENSE_1_0.txt +*/ +#ifndef BOOST_ALIGN_DETAIL_MAX_ALIGN_HPP +#define BOOST_ALIGN_DETAIL_MAX_ALIGN_HPP + +#include <boost/align/detail/integral_constant.hpp> +#include <cstddef> + +namespace boost { + namespace alignment { + namespace detail { + template<std::size_t A, std::size_t B> + struct max_align + : integral_constant<std::size_t, + (A > B) ? A : B> { + }; + } + } +} + +#endif diff --git a/boost/align/detail/max_count_of.hpp b/boost/align/detail/max_count_of.hpp new file mode 100644 index 0000000000..3ba4eae70e --- /dev/null +++ b/boost/align/detail/max_count_of.hpp @@ -0,0 +1,27 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + http://boost.org/LICENSE_1_0.txt +*/ +#ifndef BOOST_ALIGN_DETAIL_MAX_COUNT_OF_HPP +#define BOOST_ALIGN_DETAIL_MAX_COUNT_OF_HPP + +#include <boost/align/detail/integral_constant.hpp> +#include <cstddef> + +namespace boost { + namespace alignment { + namespace detail { + template<class T> + struct max_count_of + : integral_constant<std::size_t, + ~static_cast<std::size_t>(0) / sizeof(T)> { + }; + } + } +} + +#endif diff --git a/boost/align/detail/min_size.hpp b/boost/align/detail/min_size.hpp new file mode 100644 index 0000000000..80d3a7a6ed --- /dev/null +++ b/boost/align/detail/min_size.hpp @@ -0,0 +1,27 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + http://boost.org/LICENSE_1_0.txt +*/ +#ifndef BOOST_ALIGN_DETAIL_MIN_SIZE_HPP +#define BOOST_ALIGN_DETAIL_MIN_SIZE_HPP + +#include <boost/align/detail/integral_constant.hpp> +#include <cstddef> + +namespace boost { + namespace alignment { + namespace detail { + template<std::size_t A, std::size_t B> + struct min_size + : integral_constant<std::size_t, + (A < B) ? A : B> { + }; + } + } +} + +#endif diff --git a/boost/align/detail/offset_object.hpp b/boost/align/detail/offset_object.hpp new file mode 100644 index 0000000000..8168595230 --- /dev/null +++ b/boost/align/detail/offset_object.hpp @@ -0,0 +1,24 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + http://boost.org/LICENSE_1_0.txt +*/ +#ifndef BOOST_ALIGN_DETAIL_OFFSET_OBJECT_HPP +#define BOOST_ALIGN_DETAIL_OFFSET_OBJECT_HPP + +namespace boost { + namespace alignment { + namespace detail { + template<class T> + struct offset_object { + char offset; + T object; + }; + } + } +} + +#endif diff --git a/boost/align/detail/remove_traits.hpp b/boost/align/detail/remove_traits.hpp new file mode 100644 index 0000000000..d44860ed6b --- /dev/null +++ b/boost/align/detail/remove_traits.hpp @@ -0,0 +1,90 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot 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 + +#include <boost/config.hpp> + +#if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) +#include <type_traits> +#else +#include <cstddef> +#endif + +namespace boost { + 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; +#else + template<class T> + struct remove_reference { + typedef T type; + }; + + template<class T> + struct remove_reference<T&> { + typedef T type; + }; + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + template<class T> + struct remove_reference<T&&> { + typedef T type; + }; +#endif + + template<class T> + struct remove_all_extents { + typedef T type; + }; + + template<class T> + struct remove_all_extents<T[]> { + typedef typename remove_all_extents<T>::type type; + }; + + template<class T, std::size_t N> + struct remove_all_extents<T[N]> { + typedef typename remove_all_extents<T>::type type; + }; + + template<class T> + struct remove_const { + typedef T type; + }; + + template<class T> + struct remove_const<const T> { + typedef T type; + }; + + template<class T> + struct remove_volatile { + typedef T type; + }; + + template<class T> + struct remove_volatile<volatile T> { + typedef T type; + }; + + template<class T> + struct remove_cv { + typedef typename remove_volatile<typename + remove_const<T>::type>::type type; + }; +#endif + } + } +} + +#endif diff --git a/boost/align/is_aligned.hpp b/boost/align/is_aligned.hpp new file mode 100644 index 0000000000..de286655af --- /dev/null +++ b/boost/align/is_aligned.hpp @@ -0,0 +1,14 @@ +/* + (c) 2014 Glen Joseph Fernandes + glenjofe at gmail dot com + + Distributed under the Boost Software + License, Version 1.0. + http://boost.org/LICENSE_1_0.txt +*/ +#ifndef BOOST_ALIGN_IS_ALIGNED_HPP +#define BOOST_ALIGN_IS_ALIGNED_HPP + +#include <boost/align/detail/is_aligned.hpp> + +#endif |