diff options
Diffstat (limited to '')
20 files changed, 1241 insertions, 0 deletions
diff --git a/src/boost/libs/align/CMakeLists.txt b/src/boost/libs/align/CMakeLists.txt new file mode 100644 index 00000000..e07cf8da --- /dev/null +++ b/src/boost/libs/align/CMakeLists.txt @@ -0,0 +1,22 @@ +# Copyright 2018 Glen Joseph Fernandes +# (glenjofe@gmail.com) +# +# Distributed under the Boost Software License, Version 1.0. +# (http://www.boost.org/LICENSE_1_0.txt) + +cmake_minimum_required(VERSION 3.5) + +project(BoostAlign LANGUAGES CXX) + +add_library(boost_align INTERFACE) + +add_library(Boost::align ALIAS boost_align) + +target_include_directories(boost_align INTERFACE include) + +target_link_libraries(boost_align INTERFACE + Boost::assert + Boost::config + Boost::core + Boost::static_assert + Boost::throw_exception) diff --git a/src/boost/libs/align/README.md b/src/boost/libs/align/README.md new file mode 100644 index 00000000..983b806f --- /dev/null +++ b/src/boost/libs/align/README.md @@ -0,0 +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. + +### License + +Distributed under the +[Boost Software License, Version 1.0](http://www.boost.org/LICENSE_1_0.txt). diff --git a/src/boost/libs/align/index.html b/src/boost/libs/align/index.html new file mode 100644 index 00000000..a0714f04 --- /dev/null +++ b/src/boost/libs/align/index.html @@ -0,0 +1,22 @@ +<!DOCTYPE html> +<!-- +Copyright 2014-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +--> +<html> +<head> +<meta charset="utf-8"> +<meta http-equiv="refresh" content="0; url=../../doc/html/align.html"> +<title>Boost.Align</title> +</head> +<body> +<p> +Redirecting you to <a href="../../doc/html/align.html">Boost.Align</a> +</p> +<hr> +Copyright 2014-2015 Glen Fernandes +</body> +</html> diff --git a/src/boost/libs/align/meta/libraries.json b/src/boost/libs/align/meta/libraries.json new file mode 100644 index 00000000..ed342243 --- /dev/null +++ b/src/boost/libs/align/meta/libraries.json @@ -0,0 +1,14 @@ +{ + "key": "align", + "name": "Align", + "description": "Memory alignment functions, allocators, traits.", + "authors": [ + "Glen Fernandes" + ], + "maintainers": [ + "Glen Fernandes <glenjofe -at- gmail.com>" + ], + "category": [ + "Memory" + ] +} diff --git a/src/boost/libs/align/test/Jamfile b/src/boost/libs/align/test/Jamfile new file mode 100644 index 00000000..803af854 --- /dev/null +++ b/src/boost/libs/align/test/Jamfile @@ -0,0 +1,24 @@ +# Copyright 2014-2015 Glen Joseph Fernandes +# (glenjofe@gmail.com) +# +# Distributed under the Boost Software License, Version 1.0. +# (http://www.boost.org/LICENSE_1_0.txt) + +import testing ; + +run align_test.cpp ; +run align_down_test.cpp ; +run align_down_integral_test.cpp ; +run align_up_test.cpp ; +run align_up_integral_test.cpp ; +run aligned_alloc_test.cpp ; +run aligned_allocator_test.cpp ; +run aligned_allocator_adaptor_test.cpp ; +run aligned_delete_test.cpp ; +run alignment_of_test.cpp ; +run assume_aligned_test.cpp ; +run is_aligned_test.cpp ; +run is_aligned_integral_test.cpp ; + +compile aligned_allocator_incomplete_test.cpp ; +compile aligned_allocator_adaptor_incomplete_test.cpp ; diff --git a/src/boost/libs/align/test/align_down_integral_test.cpp b/src/boost/libs/align/test/align_down_integral_test.cpp new file mode 100644 index 00000000..c05a7d84 --- /dev/null +++ b/src/boost/libs/align/test/align_down_integral_test.cpp @@ -0,0 +1,59 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/align/align_down.hpp> +#include <boost/core/lightweight_test.hpp> + +template<std::size_t N> +struct A { }; + +template<class T, std::size_t N> +void test(A<N>) +{ + T v1 = N; + BOOST_TEST(boost::alignment::align_down(v1, N) == v1); + T v2 = N + 1; + BOOST_TEST(boost::alignment::align_down(v2, N) == v1); +} + +template<class T> +void test(A<1>) +{ + T v = 1; + BOOST_TEST(boost::alignment::align_down(v, 1) == v); +} + +template<class T> +void test() +{ + test<T>(A<1>()); + test<T>(A<2>()); + test<T>(A<4>()); + test<T>(A<8>()); + test<T>(A<16>()); + test<T>(A<32>()); + test<T>(A<64>()); + test<T>(A<128>()); +} + +int main() +{ + test<int>(); + test<unsigned>(); + test<long>(); + test<unsigned long>(); + test<short>(); + test<unsigned short>(); +#if !defined(BOOST_NO_LONG_LONG) + test<long long>(); + test<unsigned long long>(); +#endif + test<std::size_t>(); + test<std::ptrdiff_t>(); + + return boost::report_errors(); +} diff --git a/src/boost/libs/align/test/align_down_test.cpp b/src/boost/libs/align/test/align_down_test.cpp new file mode 100644 index 00000000..6b4d64dd --- /dev/null +++ b/src/boost/libs/align/test/align_down_test.cpp @@ -0,0 +1,43 @@ +/* +Copyright 2015 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/align/align_down.hpp> +#include <boost/align/is_aligned.hpp> +#include <boost/core/lightweight_test.hpp> + +template<std::size_t Alignment> +void test() +{ + char s[Alignment << 1]; + char* b = s; + while (!boost::alignment::is_aligned(b, Alignment)) { + ++b; + } + { + void* p = &b[Alignment]; + BOOST_TEST(boost::alignment::align_down(p, Alignment) == p); + } + { + void* p = &b[Alignment - 1]; + void* q = b; + BOOST_TEST(boost::alignment::align_down(p, Alignment) == q); + } +} + +int main() +{ + test<1>(); + test<2>(); + test<4>(); + test<8>(); + test<16>(); + test<32>(); + test<64>(); + test<128>(); + + return boost::report_errors(); +} diff --git a/src/boost/libs/align/test/align_test.cpp b/src/boost/libs/align/test/align_test.cpp new file mode 100644 index 00000000..beea710a --- /dev/null +++ b/src/boost/libs/align/test/align_test.cpp @@ -0,0 +1,68 @@ +/* +Copyright 2014-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/align/align.hpp> +#include <boost/align/is_aligned.hpp> +#include <boost/core/lightweight_test.hpp> + +template<std::size_t Alignment> +void test() +{ + char s[Alignment << 1]; + char* b = s; + while (!boost::alignment::is_aligned(b, Alignment)) { + ++b; + } + { + std::size_t n = Alignment; + void* p = b; + void* q = boost::alignment::align(Alignment, 1, p, n); + BOOST_TEST(q == p); + BOOST_TEST(q == b); + BOOST_TEST(boost::alignment::is_aligned(q, Alignment)); + BOOST_TEST(n == Alignment); + } + { + std::size_t n = 0; + void* p = b; + void* q = boost::alignment::align(Alignment, 1, p, n); + BOOST_TEST(q == 0); + BOOST_TEST(p == b); + BOOST_TEST(n == 0); + } + { + std::size_t n = Alignment - 1; + void* p = &b[1]; + void* q = boost::alignment::align(Alignment, 1, p, n); + BOOST_TEST(q == 0); + BOOST_TEST(p == &b[1]); + BOOST_TEST(n == Alignment - 1); + } + { + std::size_t n = Alignment; + void* p = &b[1]; + void* q = boost::alignment::align(Alignment, 1, p, n); + BOOST_TEST(q == p); + BOOST_TEST(p == &b[Alignment]); + BOOST_TEST(boost::alignment::is_aligned(q, Alignment)); + BOOST_TEST(n == 1); + } +} + +int main() +{ + test<1>(); + test<2>(); + test<4>(); + test<8>(); + test<16>(); + test<32>(); + test<64>(); + test<128>(); + + return boost::report_errors(); +} diff --git a/src/boost/libs/align/test/align_up_integral_test.cpp b/src/boost/libs/align/test/align_up_integral_test.cpp new file mode 100644 index 00000000..ed26fb3b --- /dev/null +++ b/src/boost/libs/align/test/align_up_integral_test.cpp @@ -0,0 +1,63 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/align/align_up.hpp> +#include <boost/core/lightweight_test.hpp> + +template<std::size_t N> +struct A { }; + +template<class T, std::size_t N> +void test(A<N>) +{ + T v1 = N; + BOOST_TEST(boost::alignment::align_up(v1, N) == v1); + T v2 = N - 1; + BOOST_TEST(boost::alignment::align_up(v2, N) == v1); + T v3 = N + N; + BOOST_TEST(boost::alignment::align_up(v3, N) == v3); + T v4 = N + 1; + BOOST_TEST(boost::alignment::align_up(v4, N) == v3); +} + +template<class T> +void test(A<1>) +{ + T v = 1; + BOOST_TEST(boost::alignment::align_up(v, 1) == v); +} + +template<class T> +void test() +{ + test<T>(A<1>()); + test<T>(A<2>()); + test<T>(A<4>()); + test<T>(A<8>()); + test<T>(A<16>()); + test<T>(A<32>()); + test<T>(A<64>()); + test<T>(A<128>()); +} + +int main() +{ + test<int>(); + test<unsigned>(); + test<long>(); + test<unsigned long>(); + test<short>(); + test<unsigned short>(); +#if !defined(BOOST_NO_LONG_LONG) + test<long long>(); + test<unsigned long long>(); +#endif + test<std::size_t>(); + test<std::ptrdiff_t>(); + + return boost::report_errors(); +} diff --git a/src/boost/libs/align/test/align_up_test.cpp b/src/boost/libs/align/test/align_up_test.cpp new file mode 100644 index 00000000..4faa1ffd --- /dev/null +++ b/src/boost/libs/align/test/align_up_test.cpp @@ -0,0 +1,43 @@ +/* +Copyright 2015 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/align/align_up.hpp> +#include <boost/align/is_aligned.hpp> +#include <boost/core/lightweight_test.hpp> + +template<std::size_t Alignment> +void test() +{ + char s[Alignment << 1]; + char* b = s; + while (!boost::alignment::is_aligned(b, Alignment)) { + ++b; + } + { + void* p = b; + BOOST_TEST(boost::alignment::align_up(p, Alignment) == p); + } + { + void* p = &b[Alignment]; + void* q = &b[1]; + BOOST_TEST(boost::alignment::align_up(q, Alignment) == p); + } +} + +int main() +{ + test<1>(); + test<2>(); + test<4>(); + test<8>(); + test<16>(); + test<32>(); + test<64>(); + test<128>(); + + return boost::report_errors(); +} diff --git a/src/boost/libs/align/test/aligned_alloc_test.cpp b/src/boost/libs/align/test/aligned_alloc_test.cpp new file mode 100644 index 00000000..925d77f8 --- /dev/null +++ b/src/boost/libs/align/test/aligned_alloc_test.cpp @@ -0,0 +1,47 @@ +/* +Copyright 2014 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/align/aligned_alloc.hpp> +#include <boost/align/is_aligned.hpp> +#include <boost/core/lightweight_test.hpp> +#include <cstring> + +void test(std::size_t alignment) +{ + { + void* p = boost::alignment::aligned_alloc(alignment, alignment + 1); + BOOST_TEST(p != 0); + BOOST_TEST(boost::alignment::is_aligned(p, alignment)); + std::memset(p, 0, alignment); + boost::alignment::aligned_free(p); + } + { + void* p = boost::alignment::aligned_alloc(alignment, 1); + BOOST_TEST(p != 0); + BOOST_TEST(boost::alignment::is_aligned(p, alignment)); + std::memset(p, 0, 1); + boost::alignment::aligned_free(p); + } + { + void* p = boost::alignment::aligned_alloc(alignment, 0); + boost::alignment::aligned_free(p); + } +} + +int main() +{ + test(1); + test(2); + test(4); + test(8); + test(16); + test(32); + test(64); + test(128); + + return boost::report_errors(); +} diff --git a/src/boost/libs/align/test/aligned_allocator_adaptor_incomplete_test.cpp b/src/boost/libs/align/test/aligned_allocator_adaptor_incomplete_test.cpp new file mode 100644 index 00000000..fb72a281 --- /dev/null +++ b/src/boost/libs/align/test/aligned_allocator_adaptor_incomplete_test.cpp @@ -0,0 +1,74 @@ +/* +Copyright 2018 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/align/aligned_allocator_adaptor.hpp> + +template<class T> +class A { +public: + typedef T value_type; + typedef T* pointer; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + + template<class U> + struct rebind { + typedef A<U> other; + }; + + A(int state) + : state_(state) { } + + template<class U> + A(const A<U>& other) + : state_(other.state()) { } + + T* allocate(std::size_t size, const void* = 0) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } + + int state() const { + return state_; + } + +private: + int state_; +}; + +template<class T, class U> +inline bool +operator==(const A<T>& a, const A<U>& b) +{ + return a.state() == b.state(); +} + +template<class T, class U> +inline bool +operator!=(const A<T>& a, const A<U>& b) +{ + return !(a == b); +} + +struct S; +struct V { }; + +void value_test() +{ + boost::alignment::aligned_allocator_adaptor<A<S> > a(A<S>(1)); + (void)a; +} + +void rebind_test() +{ + boost::alignment::aligned_allocator_adaptor<A<V> > a(A<V>(1)); + boost::alignment::aligned_allocator_adaptor<A<V> >::rebind<S>::other r(a); + (void)r; +} diff --git a/src/boost/libs/align/test/aligned_allocator_adaptor_test.cpp b/src/boost/libs/align/test/aligned_allocator_adaptor_test.cpp new file mode 100644 index 00000000..720cb657 --- /dev/null +++ b/src/boost/libs/align/test/aligned_allocator_adaptor_test.cpp @@ -0,0 +1,156 @@ +/* +Copyright 2014 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/align/aligned_allocator_adaptor.hpp> +#include <boost/align/is_aligned.hpp> +#include <boost/core/lightweight_test.hpp> +#include <new> +#include <cstring> + +template<class T> +class A { +public: + typedef T value_type; + typedef T* pointer; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + + template<class U> + struct rebind { + typedef A<U> other; + }; + + A(int state) + : state_(state) { } + + template<class U> + A(const A<U>& other) + : state_(other.state()) { } + + T* allocate(std::size_t size, const void* = 0) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } + + void construct(T* ptr, const T& value) { + ::new(static_cast<void*>(ptr)) T(value); + } + + void destroy(T* ptr) { + ptr->~T(); + } + + int state() const { + return state_; + } + +private: + int state_; +}; + +template<class T, class U> +inline bool +operator==(const A<T>& a, const A<U>& b) +{ + return a.state() == b.state(); +} + +template<class T, class U> +inline bool +operator!=(const A<T>& a, const A<U>& b) +{ + return !(a == b); +} + +template<std::size_t Alignment> +void test_allocate() +{ + { + 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)); + std::memset(p, 0, 1); + a.deallocate(p, 1); + } + { + 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); + BOOST_TEST(boost::alignment::is_aligned(q, Alignment)); + std::memset(q, 0, 1); + a.deallocate(q, 1); + a.deallocate(p, 1); + } + { + boost::alignment::aligned_allocator_adaptor<A<int>, Alignment> a(5); + int* p = a.allocate(0); + a.deallocate(p, 0); + } +} + +template<std::size_t Alignment> +void test_construct() +{ + boost::alignment::aligned_allocator_adaptor<A<int>, Alignment> a(5); + int* p = a.allocate(1); + a.construct(p, 1); + BOOST_TEST(*p == 1); + a.destroy(p); + a.deallocate(p, 1); +} + +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_TEST(b == a); + } + { + A<int> a(5); + boost::alignment::aligned_allocator_adaptor<A<int>, Alignment> b(a); + BOOST_TEST(b.base() == a); + } +} + +template<std::size_t Alignment> +void test_rebind() +{ + 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); +} + +template<std::size_t Alignment> +void test() +{ + test_allocate<Alignment>(); + test_construct<Alignment>(); + test_constructor<Alignment>(); + test_rebind<Alignment>(); +} + +int main() +{ + test<1>(); + test<2>(); + test<4>(); + test<8>(); + test<16>(); + test<32>(); + test<64>(); + test<128>(); + + return boost::report_errors(); +} diff --git a/src/boost/libs/align/test/aligned_allocator_incomplete_test.cpp b/src/boost/libs/align/test/aligned_allocator_incomplete_test.cpp new file mode 100644 index 00000000..3ab6135e --- /dev/null +++ b/src/boost/libs/align/test/aligned_allocator_incomplete_test.cpp @@ -0,0 +1,24 @@ +/* +Copyright 2018 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/align/aligned_allocator.hpp> + +struct S; +struct V { }; + +void value_test() +{ + boost::alignment::aligned_allocator<S> a; + (void)a; +} + +void rebind_test() +{ + boost::alignment::aligned_allocator<V> a; + boost::alignment::aligned_allocator<V>::rebind<S>::other r(a); + (void)r; +} diff --git a/src/boost/libs/align/test/aligned_allocator_test.cpp b/src/boost/libs/align/test/aligned_allocator_test.cpp new file mode 100644 index 00000000..c8fdf8ed --- /dev/null +++ b/src/boost/libs/align/test/aligned_allocator_test.cpp @@ -0,0 +1,106 @@ +/* +Copyright 2014 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/align/aligned_allocator.hpp> +#include <boost/align/is_aligned.hpp> +#include <boost/core/lightweight_test.hpp> +#include <cstring> + +template<std::size_t Alignment> +void test_allocate() +{ + { + boost::alignment::aligned_allocator<int, Alignment> a; + int* p = a.allocate(1); + BOOST_TEST(p != 0); + BOOST_TEST(boost::alignment::is_aligned(p, Alignment)); + std::memset(p, 0, 1); + a.deallocate(p, 1); + } + { + boost::alignment::aligned_allocator<int, Alignment> a; + int* p = a.allocate(0); + a.deallocate(p, 0); + } +} + +template<std::size_t Alignment> +void test_construct() +{ + boost::alignment::aligned_allocator<int, Alignment> a; + int* p = a.allocate(1); + a.construct(p, 1); + BOOST_TEST(*p == 1); + a.destroy(p); + a.deallocate(p, 1); +} + +template<std::size_t Alignment> +void test_constructor() +{ + { + boost::alignment::aligned_allocator<char, Alignment> a1; + boost::alignment::aligned_allocator<int, Alignment> a2(a1); + BOOST_TEST(a2 == a1); + } + { + boost::alignment::aligned_allocator<char, Alignment> a1; + boost::alignment::aligned_allocator<void, Alignment> a2(a1); + BOOST_TEST(a2 == a1); + } + { + boost::alignment::aligned_allocator<void, Alignment> a1; + boost::alignment::aligned_allocator<char, Alignment> a2(a1); + BOOST_TEST(a2 == a1); + } +} + +template<std::size_t Alignment> +void test_rebind() +{ + { + boost::alignment::aligned_allocator<char, Alignment> a1; + typename boost::alignment::aligned_allocator<char, + Alignment>::template rebind<int>::other a2(a1); + BOOST_TEST(a2 == a1); + } + { + boost::alignment::aligned_allocator<char, Alignment> a1; + typename boost::alignment::aligned_allocator<char, + Alignment>::template rebind<void>::other a2(a1); + BOOST_TEST(a2 == a1); + } + { + boost::alignment::aligned_allocator<void, Alignment> a1; + typename boost::alignment::aligned_allocator<void, + Alignment>::template rebind<char>::other a2(a1); + BOOST_TEST(a2 == a1); + } +} + +template<std::size_t Alignment> +void test() +{ + test_allocate<Alignment>(); + test_construct<Alignment>(); + test_constructor<Alignment>(); + test_rebind<Alignment>(); +} + +int main() +{ + test<1>(); + test<2>(); + test<4>(); + test<8>(); + test<16>(); + test<32>(); + test<64>(); + test<128>(); + + return boost::report_errors(); +} diff --git a/src/boost/libs/align/test/aligned_delete_test.cpp b/src/boost/libs/align/test/aligned_delete_test.cpp new file mode 100644 index 00000000..0a00b71a --- /dev/null +++ b/src/boost/libs/align/test/aligned_delete_test.cpp @@ -0,0 +1,51 @@ +/* +Copyright 2014 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/align/aligned_alloc.hpp> +#include <boost/align/aligned_delete.hpp> +#include <boost/align/alignment_of.hpp> +#include <boost/core/lightweight_test.hpp> +#include <new> + +class type { +public: + static unsigned count; + + type() { + ++count; + } + + ~type() { + --count; + } + +private: + type(const type&); + type& operator=(const type&); +}; + +unsigned type::count = 0; + +int main() +{ + { + void* p = boost::alignment::aligned_alloc(1, 1); + char* q = ::new(p) char; + boost::alignment::aligned_delete()(q); + } + { + enum { + N = boost::alignment::alignment_of<type>::value + }; + void* p = boost::alignment::aligned_alloc(N, sizeof(type)); + type* q = ::new(p) type; + BOOST_TEST(type::count == 1); + boost::alignment::aligned_delete()(q); + BOOST_TEST(type::count == 0); + } + return boost::report_errors(); +} diff --git a/src/boost/libs/align/test/alignment_of_test.cpp b/src/boost/libs/align/test/alignment_of_test.cpp new file mode 100644 index 00000000..7df84c6c --- /dev/null +++ b/src/boost/libs/align/test/alignment_of_test.cpp @@ -0,0 +1,219 @@ +/* +Copyright 2014 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/align/alignment_of.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/config.hpp> +#include <cstddef> + +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_cv { + typedef T type; +}; + +template<class T> +struct remove_cv<const T> { + typedef T type; +}; + +template<class T> +struct remove_cv<volatile T> { + typedef T type; +}; + +template<class T> +struct remove_cv<const volatile T> { + typedef T type; +}; + +template<class T> +struct offset_value { + char value; + typename remove_cv<typename remove_all_extents<typename + remove_reference<T>::type>::type>::type object; +}; + +template<class T> +void test_type() +{ + enum { + N = boost::alignment::alignment_of<T>::value + }; + BOOST_TEST(offsetof(offset_value<T>, object) == N); +} + +template<class T> +void test_reference() +{ + test_type<T>(); + test_type<T&>(); + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + test_type<T&&>(); +#endif +} + +template<class T> +void test_array() +{ + test_reference<T>(); + test_reference<T[2]>(); + test_type<T[]>(); +} + +template<class T> +void test_cv() +{ + test_array<T>(); + test_array<const T>(); + test_array<volatile T>(); + test_array<const volatile T>(); +} + +template<class T> +struct Struct { + T t; +}; + +template<class T> +union Union { + T t; +}; + +template<class T> +void test() +{ + test_cv<T>(); + test_cv<Struct<T> >(); + test_cv<Union<T> >(); +} + +void test_integral() +{ + test<bool>(); + test<char>(); + test<signed char>(); + test<unsigned char>(); + test<wchar_t>(); + +#if !defined(BOOST_NO_CXX11_CHAR16_T) + test<char16_t>(); +#endif + +#if !defined(BOOST_NO_CXX11_CHAR32_T) + test<char32_t>(); +#endif + + test<short>(); + test<unsigned short>(); + test<int>(); + test<unsigned int>(); + test<long>(); + test<unsigned long>(); + +#if !defined(BOOST_NO_LONG_LONG) + test<long long>(); + test<unsigned long long>(); +#endif +} + +void test_floating_point() +{ + test<float>(); + test<double>(); + test<long double>(); +} + +void test_nullptr_t() +{ +#if !defined(BOOST_NO_CXX11_NULLPTR) && \ + !defined(BOOST_NO_CXX11_DECLTYPE) + test<decltype(nullptr)>(); +#endif +} + +class X; + +void test_pointer() +{ + test<void*>(); + test<char*>(); + test<int*>(); + test<X*>(); + test<void(*)()>(); +} + +void test_member_pointer() +{ + test<int X::*>(); + test<int(X::*)()>(); +} + +enum E { + V = 1 +}; + +void test_enum() +{ + test<E>(); +} + +struct S { }; +class C { }; +union U { }; + +void test_class() +{ + test<S>(); + test<C>(); + test<U>(); +} + +int main() +{ + test_integral(); + test_floating_point(); + test_nullptr_t(); + test_pointer(); + test_member_pointer(); + test_enum(); + test_class(); + + return boost::report_errors(); +} diff --git a/src/boost/libs/align/test/assume_aligned_test.cpp b/src/boost/libs/align/test/assume_aligned_test.cpp new file mode 100644 index 00000000..bf863399 --- /dev/null +++ b/src/boost/libs/align/test/assume_aligned_test.cpp @@ -0,0 +1,61 @@ +/* +Copyright 2015 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/align/assume_aligned.hpp> + +void* test1(void* p) +{ + BOOST_ALIGN_ASSUME_ALIGNED(p, 1); + return p; +} + +void* test2(void* p) +{ + BOOST_ALIGN_ASSUME_ALIGNED(p, 2); + return p; +} + +void* test4(void* p) +{ + BOOST_ALIGN_ASSUME_ALIGNED(p, 4); + return p; +} + +void* test8(void* p) +{ + BOOST_ALIGN_ASSUME_ALIGNED(p, 8); + return p; +} + +void* test16(void* p) +{ + BOOST_ALIGN_ASSUME_ALIGNED(p, 16); + return p; +} + +void* test32(void* p) +{ + BOOST_ALIGN_ASSUME_ALIGNED(p, 32); + return p; +} + +void* test64(void* p) +{ + BOOST_ALIGN_ASSUME_ALIGNED(p, 64); + return p; +} + +void* test128(void* p) +{ + BOOST_ALIGN_ASSUME_ALIGNED(p, 128); + return p; +} + +int main() +{ + return 0; +} diff --git a/src/boost/libs/align/test/is_aligned_integral_test.cpp b/src/boost/libs/align/test/is_aligned_integral_test.cpp new file mode 100644 index 00000000..862feac2 --- /dev/null +++ b/src/boost/libs/align/test/is_aligned_integral_test.cpp @@ -0,0 +1,63 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/align/is_aligned.hpp> +#include <boost/core/lightweight_test.hpp> + +template<std::size_t N> +struct A { }; + +template<class T, std::size_t N> +void test(A<N>) +{ + T v1 = N; + BOOST_TEST(boost::alignment::is_aligned(v1, N)); + T v2 = N - 1; + BOOST_TEST(!boost::alignment::is_aligned(v2, N)); + T v3 = N + 1; + BOOST_TEST(!boost::alignment::is_aligned(v3, N)); + T v4 = N + N; + BOOST_TEST(boost::alignment::is_aligned(v4, N)); +} + +template<class T> +void test(A<1>) +{ + T v = 1; + BOOST_TEST(boost::alignment::is_aligned(v, 1)); +} + +template<class T> +void test() +{ + test<T>(A<1>()); + test<T>(A<2>()); + test<T>(A<4>()); + test<T>(A<8>()); + test<T>(A<16>()); + test<T>(A<32>()); + test<T>(A<64>()); + test<T>(A<128>()); +} + +int main() +{ + test<int>(); + test<unsigned>(); + test<long>(); + test<unsigned long>(); + test<short>(); + test<unsigned short>(); +#if !defined(BOOST_NO_LONG_LONG) + test<long long>(); + test<unsigned long long>(); +#endif + test<std::size_t>(); + test<std::ptrdiff_t>(); + + return boost::report_errors(); +} diff --git a/src/boost/libs/align/test/is_aligned_test.cpp b/src/boost/libs/align/test/is_aligned_test.cpp new file mode 100644 index 00000000..3098e8d0 --- /dev/null +++ b/src/boost/libs/align/test/is_aligned_test.cpp @@ -0,0 +1,73 @@ +/* +Copyright 2014-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/align/alignment_of.hpp> +#include <boost/align/is_aligned.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/config.hpp> + +template<std::size_t N> +struct A { }; + +template<std::size_t N> +void test(char* p, A<N>) +{ + BOOST_TEST(boost::alignment::is_aligned(p, N)); + BOOST_TEST(!boost::alignment::is_aligned(p + 1, N)); +} + +void test(char* p, A<1>) +{ + BOOST_TEST(boost::alignment::is_aligned(p, 1)); +} + +template<class T> +void test() +{ + T o; + test(reinterpret_cast<char*>(&o), + A<boost::alignment::alignment_of<T>::value>()); +} + +class X; + +int main() +{ + test<bool>(); + test<char>(); + test<wchar_t>(); +#if !defined(BOOST_NO_CXX11_CHAR16_T) + test<char16_t>(); +#endif +#if !defined(BOOST_NO_CXX11_CHAR32_T) + test<char32_t>(); +#endif + test<short>(); + test<int>(); + test<long>(); +#if !defined(BOOST_NO_LONG_LONG) && !defined(_MSC_VER) + test<long long>(); +#endif + test<float>(); +#if !defined(BOOST_MSVC) + test<double>(); + test<long double>(); +#endif + test<void*>(); + test<char*>(); + test<int*>(); + test<X*>(); + test<void(*)()>(); +#if !defined(_MSC_VER) || !defined(__clang__) +#if !defined(BOOST_MSVC) + test<int X::*>(); + test<int(X::*)()>(); +#endif +#endif + + return boost::report_errors(); +} |