1
0
mirror of https://git.suyu.dev/suyu/suyu synced 2025-09-14 10:07:56 -05:00

Initial commit

This commit is contained in:
Crimson-Hawk
2024-03-05 16:42:40 +08:00
commit f1e4595ebf
39576 changed files with 7006612 additions and 0 deletions

View File

View File

View File

@@ -0,0 +1,66 @@
# Copyright 2017 Glen Joseph Fernandes
# (glenjofe@gmail.com)
#
# Distributed under the Boost Software License, Version 1.0.
# (http://www.boost.org/LICENSE_1_0.txt)
version: 1.0.{build}-{branch}
shallow_clone: true
branches:
only:
- master
- develop
environment:
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
TOOLSET: msvc-9.0
TARGET: 32
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
TOOLSET: msvc-10.0
TARGET: 32
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
TOOLSET: msvc-11.0
TARGET: 32
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
TOOLSET: msvc-12.0
TARGET: 32,64
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
TOOLSET: msvc-14.0
TARGET: 32,64
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
TOOLSET: msvc-14.1
TARGET: 32,64
STANDARD: 14,17
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
TOOLSET: msvc-14.2
TARGET: 32,64
STANDARD: 14,17
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
TOOLSET: clang-win
TARGET: 32,64
STANDARD: 14,17
install:
- cd ..
- git clone -b %APPVEYOR_REPO_BRANCH% https://github.com/boostorg/boost
- cd boost
- git submodule init libs/assert
- git submodule init libs/config
- git submodule init libs/core
- git submodule init libs/static_assert
- git submodule init libs/headers
- git submodule init tools/build
- git submodule init tools/boost_install
- git submodule update
- xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\align
- cmd /c bootstrap
- b2 headers
build: off
test_script:
- if not "%STANDARD%" == "" set STANDARD=cxxstd=%STANDARD%
- b2 libs/align/test toolset=%TOOLSET% address-model=%TARGET% %STANDARD%

View File

@@ -0,0 +1,185 @@
name: CI
on:
pull_request:
push:
branches:
- master
- develop
jobs:
posix:
strategy:
fail-fast: false
matrix:
include:
- toolset: gcc-4.8
standard: "03,11"
os: ubuntu-18.04
install: g++-4.8
- toolset: gcc-5
standard: "03,11,14,1z"
os: ubuntu-18.04
install: g++-5
- toolset: gcc-6
standard: "03,11,14,1z"
os: ubuntu-18.04
install: g++-6
- toolset: gcc-7
standard: "03,11,14,17"
os: ubuntu-18.04
- toolset: gcc-8
standard: "03,11,14,17,2a"
os: ubuntu-18.04
install: g++-8
- toolset: gcc-9
standard: "03,11,14,17,2a"
os: ubuntu-18.04
- toolset: gcc-10
standard: "03,11,14,17,2a"
os: ubuntu-20.04
install: g++-10
- toolset: gcc-11
standard: "03,11,14,17,2a"
os: ubuntu-20.04
install: g++-11
- toolset: clang
compiler: clang++-3.9
standard: "03,11,14"
os: ubuntu-18.04
install: clang-3.9
- toolset: clang
compiler: clang++-4.0
standard: "03,11,14"
os: ubuntu-18.04
install: clang-4.0
- toolset: clang
compiler: clang++-5.0
standard: "03,11,14,1z"
os: ubuntu-18.04
install: clang-5.0
- toolset: clang
compiler: clang++-6.0
standard: "03,11,14,17"
os: ubuntu-18.04
install: clang-6.0
- toolset: clang
compiler: clang++-7
standard: "03,11,14,17"
os: ubuntu-18.04
install: clang-7
- toolset: clang
compiler: clang++-8
standard: "03,11,14,17"
os: ubuntu-20.04
install: clang-8
- toolset: clang
compiler: clang++-9
standard: "03,11,14,17,2a"
os: ubuntu-20.04
install: clang-9
- toolset: clang
compiler: clang++-10
standard: "03,11,14,17,2a"
os: ubuntu-20.04
install: clang-10
- toolset: clang
compiler: clang++-11
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
install: clang-11
- toolset: clang
compiler: clang++-12
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
install: clang-12
- toolset: clang
standard: "03,11,14,17,2a"
os: macos-10.15
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- name: Install packages
if: matrix.install
run: sudo apt install ${{matrix.install}}
- name: Setup Boost
run: |
cd ..
git clone --depth 1 https://github.com/boostorg/boost
cd boost
cp -r $GITHUB_WORKSPACE/* libs/align
git submodule init libs/assert
git submodule init libs/config
git submodule init libs/core
git submodule init libs/static_assert
git submodule init libs/headers
git submodule init tools/build
git submodule init tools/boost_install
git submodule update
./bootstrap.sh
./b2 -d0 headers
- name: Create user-config.jam
if: matrix.compiler
run: |
echo "using ${{matrix.toolset}} : : ${{matrix.compiler}} ;" > ~/user-config.jam
- name: Run tests
run: |
cd ../boost
./b2 -j3 libs/align/test toolset=${{matrix.toolset}} cxxstd=${{matrix.standard}} variant=debug,release
windows:
strategy:
fail-fast: false
matrix:
include:
- toolset: msvc-14.1
standard: "14,17,latest"
target: 32,64
os: windows-2016
- toolset: msvc-14.2
standard: "14,17,latest"
target: 32,64
os: windows-2019
- toolset: msvc-14.3
cxxstd: "14,17,latest"
addrmd: 32,64
os: windows-2022
- toolset: gcc
standard: "03,11,14,17,2a"
target: 64
os: windows-2019
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- name: Setup Boost
shell: cmd
run: |
cd ..
git clone --depth 1 https://github.com/boostorg/boost boost
cd boost
xcopy /s /e /q %GITHUB_WORKSPACE% libs\align\
git submodule init libs/assert
git submodule init libs/config
git submodule init libs/core
git submodule init libs/static_assert
git submodule init libs/headers
git submodule init tools/build
git submodule init tools/boost_install
git submodule update
cmd /c bootstrap
b2 -d0 headers
- name: Run tests
shell: cmd
run: |
cd ../boost
b2 -j3 libs/align/test toolset=${{matrix.toolset}} cxxstd=${{matrix.standard}} address-model=${{matrix.target}} variant=debug,release

View File

@@ -0,0 +1,297 @@
# Copyright 2017 Glen Joseph Fernandes
# (glenjofe@gmail.com)
#
# Distributed under the Boost Software License, Version 1.0.
# (http://www.boost.org/LICENSE_1_0.txt)
language: cpp
sudo: false
dist: xenial
branches:
only:
- master
- develop
env:
matrix:
- EMPTY=true
matrix:
exclude:
- env: EMPTY=true
include:
- os: linux
compiler: g++
env: TOOLSET=gcc COMPILER=g++ STANDARD=03,11
- os: linux
compiler: g++-4.4
env: TOOLSET=gcc COMPILER=g++-4.4 STANDARD=98,0x
addons:
apt:
packages:
- g++-4.4
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: g++-4.6
env: TOOLSET=gcc COMPILER=g++-4.6 STANDARD=03,0x
addons:
apt:
packages:
- g++-4.6
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: g++-4.7
env: TOOLSET=gcc COMPILER=g++-4.7 STANDARD=03,11
addons:
apt:
packages:
- g++-4.7
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: g++-4.8
env: TOOLSET=gcc COMPILER=g++-4.8 STANDARD=03,11
addons:
apt:
packages:
- g++-4.8
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: g++-4.9
env: TOOLSET=gcc COMPILER=g++-4.9 STANDARD=03,11
addons:
apt:
packages:
- g++-4.9
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: g++-5
env: TOOLSET=gcc COMPILER=g++-5 STANDARD=03,11,14,1z
addons:
apt:
packages:
- g++-5
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: g++-6
env: TOOLSET=gcc COMPILER=g++-6 STANDARD=03,11,14,1z
addons:
apt:
packages:
- g++-6
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: g++-7
env: TOOLSET=gcc COMPILER=g++-7 STANDARD=03,11,14,17
addons:
apt:
packages:
- g++-7
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: g++-8
env: TOOLSET=gcc COMPILER=g++-8 STANDARD=03,11,14,17,2a
addons:
apt:
packages:
- g++-8
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: g++-9
env: TOOLSET=gcc COMPILER=g++-9 STANDARD=03,11,14,17,2a
addons:
apt:
packages:
- g++-9
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: clang++
env: TOOLSET=clang COMPILER=clang++ STANDARD=03,11
- os: linux
dist: trusty
compiler: /usr/bin/clang++
env: TOOLSET=clang COMPILER=/usr/bin/clang++ STANDARD=03,11
addons:
apt:
packages:
- clang-3.3
- os: linux
dist: trusty
compiler: /usr/bin/clang++
env: TOOLSET=clang COMPILER=/usr/bin/clang++ STANDARD=03,11
addons:
apt:
packages:
- clang-3.4
- os: linux
dist: trusty
compiler: clang++-3.5
env: TOOLSET=clang COMPILER=clang++-3.5 STANDARD=03,11,14,1z
addons:
apt:
packages:
- clang-3.5
- libstdc++-4.9-dev
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.5
- os: linux
compiler: clang++-3.6
env: TOOLSET=clang COMPILER=clang++-3.6 STANDARD=03,11,14,1z
addons:
apt:
packages:
- clang-3.6
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: clang++-3.7
env: TOOLSET=clang COMPILER=clang++-3.7 STANDARD=03,11,14,1z
addons:
apt:
packages:
- clang-3.7
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: clang++-3.8
env: TOOLSET=clang COMPILER=clang++-3.8 STANDARD=03,11,14,1z
addons:
apt:
packages:
- clang-3.8
- libstdc++-4.9-dev
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: clang++-3.9
env: TOOLSET=clang COMPILER=clang++-3.9 STANDARD=03,11,14,1z
addons:
apt:
packages:
- clang-3.9
- libstdc++-4.9-dev
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: clang++-4.0
env: TOOLSET=clang COMPILER=clang++-4.0 STANDARD=03,11,14,1z
addons:
apt:
packages:
- clang-4.0
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: clang++-5.0
env: TOOLSET=clang COMPILER=clang++-5.0 STANDARD=03,11,14,1z
addons:
apt:
packages:
- clang-5.0
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: clang++-6.0
env: TOOLSET=clang COMPILER=clang++-6.0 STANDARD=03,11,14,17,2a
addons:
apt:
packages:
- clang-6.0
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: clang++-7
env: TOOLSET=clang COMPILER=clang++-7 STANDARD=03,11,14,17,2a
addons:
apt:
packages:
- clang-7
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-xenial-7
- os: linux
compiler: clang++-8
env: TOOLSET=clang COMPILER=clang++-8 STANDARD=03,11,14,17,2a
addons:
apt:
packages:
- clang-8
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-xenial-8
- os: linux
dist: trusty
compiler: clang++-libc++
env: TOOLSET=clang COMPILER=clang++-libc++ STANDARD=03,11,14,1z
addons:
apt:
packages:
- libc++-dev
- os: osx
compiler: clang++
env: TOOLSET=clang COMPILER=clang++ STANDARD=03,11,14,1z
install:
- cd ..
- git clone -b $TRAVIS_BRANCH https://github.com/boostorg/boost
- cd boost
- git submodule init libs/assert
- git submodule init libs/config
- git submodule init libs/core
- git submodule init libs/static_assert
- git submodule init libs/headers
- git submodule init tools/build
- git submodule init tools/boost_install
- git submodule update
- cp -R $TRAVIS_BUILD_DIR/* libs/align
- ./bootstrap.sh
- ./b2 headers
script:
- |-
echo "using $TOOLSET : : $COMPILER ;" > ~/user-config.jam
- ./b2 libs/align/test toolset=$TOOLSET cxxstd=$STANDARD
notifications:
email:
on_success: always

View File

@@ -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...3.20)
project(boost_align VERSION "${BOOST_SUPERPROJECT_VERSION}" 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
)

View File

@@ -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).

View File

@@ -0,0 +1,19 @@
# 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)
import quickbook ;
xml align : align.qbk ;
boostbook standalone : align : <xsl:param>boost.root=../../../.. ;
alias boostdoc : align : : : ;
explicit boostdoc ;
alias boostrelease ;
explicit boostrelease ;

View File

@@ -0,0 +1,649 @@
[/
Copyright 2014-2017 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
]
[library Boost.Align
[quickbook 1.6]
[id align]
[copyright 2014-2017 Glen Joseph Fernandes]
[authors [Fernandes, Glen]]
[dirname align]
[license Distributed under the Boost Software License, Version 1.0.]]
[section Introduction]
The Boost Align C++ library provides functions, classes, templates, traits,
and macros, for the control, inspection, and diagnostic of memory alignment.
[endsect]
[section Rationale]
[heading Dynamic allocation]
C++11 added the ability to specify increased alignment (over-alignment) for
class types. Unfortunately, `::operator new` allocation functions, `new`
expressions and the Default Allocator, `std::allocator`, do not support
dynamic memory allocation of over-aligned data. This library provides
allocation functions and allocators that respect the alignment requirements of
a type and so are suitable for allocating memory for over-aligned types.
[variablelist
[[`aligned_alloc(alignment, size)`]
[Replaces `::operator new(size, std::nothrow)`]]
[[`aligned_free(pointer)`]
[Replaces `::operator delete(pointer, std::nothrow)`]]
[[`aligned_allocator<T>`][Replaces `std::allocator<T>`]]
[[`aligned_allocator_adaptor<Allocator>`][Replaces use of Allocator]]
[[`aligned_delete`][Replaces `std::default_delete<T>`]]]
[heading Pointer alignment]
C++11 provided `std::align` in the standard library to align a pointer value.
Unfortunately some C++ standard library implementations do not support it yet
(libstdc++ as far as gcc 4.8.0) and other standard library implementations
implement it incorrectly (dinkumware in msvc11.0). This library provides it
for those implementations and also for C++03 compilers where it is equally
useful.
[heading Querying alignment]
C++11 provided the `std::alignment_of` trait in the standard library to query
the alignment requirement of a type. Unfortunately some C++ standard library
vendors do not implement it in an entirely standard conforming manner, such as
for array types (libc++ as far as clang 3.4). Other vendor implementations
report incorrect values for certain types, such as pointer to members (msvc
14.0). This library provides it for those implementations and also for C++03
compilers where it is equally useful.
[heading Hinting alignment]
Allocating aligned memory is sometimes not enough to ensure that optimal code
is generated. Developers use specific compiler intrinsics to notify the
compiler of a given alignment property of a memory block. This library
provides a macro, `BOOST_ALIGN_ASSUME_ALIGNED`, to abstract that functionality
for compilers with the appropriate intrinsics.
[heading Checking alignment]
This library provides a function, `is_aligned` to test the alignment of a
pointer value. It is generally useful in assertions to validate that memory is
correctly aligned.
[endsect]
[section Examples]
[heading Aligned allocation]
To dynamically allocate storage with desired alignment, you can use the
`aligned_alloc` function:
[ordered_list
[`void* storage = boost::alignment::aligned_alloc(alignment, size);`]]
To deallocate storage allocated with the `aligned_alloc` function, use
the `aligned_free` function:
[ordered_list [`boost::alignment::aligned_free(storage);`]]
[heading Aligned allocator]
For C++ allocator aware code, you can use the `aligned_allocator` class
template for an allocator that respects over-alignment:
[ordered_list
[`std::vector<int128_t,
boost::alignment::aligned_allocator<int128_t> > vector;`]]
This template allows specifying minimum alignment for all dynamic allocations:
[ordered_list
[`std::vector<double,
boost::alignment::aligned_allocator<double, 64> > vector;`]]
[heading Aligned allocator adaptor]
To turn an allocator into an allocator that respects over-alignment, you can
use the `aligned_allocator_adaptor` class template:
[ordered_list
[`boost::alignment::aligned_allocator_adaptor<First> second(first);`]]
This template allows specifying minimum alignment for all dynamic
allocations:
[ordered_list
[`boost::alignment::aligned_allocator_adaptor<First, 64> second(first);`]]
[heading Aligned deleter]
For a deleter that can be paired with `aligned_alloc`, you can use the
`aligned_delete` class:
[ordered_list
[`std::unique_ptr<double, boost::alignment::aligned_delete> pointer;`]]
[heading Pointer alignment]
To advance a pointer to the next address with the desired alignment:
[ordered_list
[`void* pointer = storage;`]
[`std::size_t space = size;`]
[`void* result = boost::alignment::align(64, sizeof(double), pointer,
space);`]]
[heading Querying alignment]
To obtain the alignment of a given type at compie time, you can use:
[ordered_list [`boost::alignment::alignment_of<int128_t>::value`]]
If your compiler supports C++14 variable templates, you can also use:
[ordered_list [`boost::alignment::alignment_of_v<int128_t>`]]
[heading Hinting alignment]
To inform the compiler about the alignment of a pointer, you can use:
[ordered_list [`BOOST_ALIGN_ASSUME_ALIGNED(pointer, 64)`]]
[heading Checking alignment]
To check alignment of a pointer you can use the `is_aligned` function:
[ordered_list [`assert(boost::alignment::is_aligned(pointer, 64));`]]
[endsect]
[section Reference]
[section Functions]
[section align]
[variablelist
[[`void* align(std::size_t alignment, std::size_t size, void*& ptr,
std::size_t& space);`]
[[variablelist
[[Header][`#include <boost/align/align.hpp>`]]
[[Effects]
[If it is possible to fit `size` bytes of storage aligned by `alignment` into
the buffer pointed to by `ptr` with length `space`, the function updates `ptr`
to point to the first possible address of such storage and decreases `space` by
the number of bytes used for alignment. Otherwise, the function does nothing.]]
[[Requires]
[[itemized_list
[`alignment` shall be a power of two]
[`ptr` shall point to contiguous storage of at least `space` bytes]]]]
[[Returns]
[A null pointer if the requested aligned buffer would not fit into the
available space, otherwise the adjusted value of `ptr`.]]
[[Note]
[The function updates its `ptr` and `space` arguments so that it can be called
repeatedly with possibly different `alignment` and `size`arguments for the same
buffer.]]]]]]
[endsect]
[section align_up]
[variablelist
[[`template<class T> constexpr T align_up(T value, std::size_t alignment)
noexcept;`]
[[variablelist
[[Header][`#include <boost/align/align_up.hpp>`]]
[[Constraints][`T` is not a pointer type]]
[[Requires][`alignment` shall be a power of two]]
[[Returns][A value at or after `value` that is a multiple of `alignment`.]]]]]]
[endsect]
[section align_down]
[variablelist
[[`template<class T> constexpr T align_down(T value, std::size_t alignment)
noexcept;`]
[[variablelist
[[Header][`#include <boost/align/align_down.hpp>`]]
[[Constraints][`T` is not a pointer type]]
[[Requires][`alignment` shall be a power of two]]
[[Returns]
[A value at or before `value` that is a multiple of `alignment`.]]]]]]
[endsect]
[section aligned_alloc]
[variablelist
[[`void* aligned_alloc(std::size_t alignment, std::size_t size);`]
[[variablelist
[[Header][`#include <boost/align/aligned_alloc.hpp>`]]
[[Effects]
[Allocates space for an object whose alignment is specified by `alignment`,
whose size is specified by `size`, and whose value is indeterminate.]]
[[Requires][`alignment` shall be a power of two.]]
[[Returns][A null pointer or a pointer to the allocated space.]]
[[Note]
[On certain platforms, the space allocated may be slightly larger than
`size` bytes, to allow for alignment.]]]]]]
[endsect]
[section aligned_free]
[variablelist
[[`void aligned_free(void* ptr);`]
[[variablelist
[[Header][`#include <boost/align/aligned_alloc.hpp>`]]
[[Effects]
[Causes the space pointed to by `ptr` to be deallocated, that is, made
available for further allocation. If `ptr` is a null pointer, no action occurs.
Otherwise, if the argument does not match a pointer earlier returned by the
`aligned_alloc()` function, or if the space has been deallocated by a call to
`aligned_free()`, the behavior is undefined.]]
[[Requires]
[`ptr` is a null pointer or a pointer earlier returned by the `aligned_alloc()`
function that has not been deallocated by a call to `aligned_free()`.]]
[[Returns][The `aligned_free()` function returns no value.]]]]]]
[endsect]
[section is_aligned]
[variablelist
[[`bool is_aligned(const volatile void* ptr, std::size_t alignment) noexcept;`]
[[variablelist
[[Header][`#include <boost/align/is_aligned.hpp>`]]
[[Requires][`alignment` shall be a power of two.]]
[[Returns]
[`true` if `ptr` is aligned on the boundary specified by `alignment`, otherwise
`false`.]]]]]
[[`template<class T> constexpr bool is_aligned(T value, std::size_t alignment)
noexcept;`]
[[variablelist
[[Header][`#include <boost/align/is_aligned.hpp>`]]
[[Constraints][`T` is not a pointer type]]
[[Requires][`alignment` shall be a power of two.]]
[[Returns]
[`true` if the value of `value` is aligned on the boundary specified by
`alignment`, otherwise `false`.]]]]]]
[endsect]
[endsect]
[section Classes]
[section aligned_allocator]
[variablelist
[[`template<class T, std::size_t Alignment = 1> class aligned_allocator;`]
[[variablelist
[[Header][`#include <boost/align/aligned_allocator.hpp>`]]
[[Note]
[Using the aligned allocator with a minimum Alignment value is generally only
useful with containers that are not node-based such as `vector`. With
node-based containers, such as `list`, the node object would have the minimum
alignment instead of the value type object.]]]]]]
[heading Member types]
[ordered_list
[`typedef T value_type;`]
[`typedef T* pointer;`]
[`typedef const T* const_pointer;`]
[`typedef void* void_pointer;`]
[`typedef const void* const_void_pointer;`]
[`typedef std::add_lvalue_reference_t<T> reference;`]
[`typedef std::add_lvalue_reference_t<const T> const_reference;`]
[`typedef std::size_t size_type;`]
[`typedef std::ptrdiff_t difference_type;`]
[`typedef std::true_type propagate_on_container_move_assignment;`]
[`typedef std::true_type is_always_equal;`]
[`template<class U> struct rebind { typedef aligned_allocator<U, Alignment>
other; };`]]
[heading Constructors]
[variablelist
[[`aligned_allocator() = default;`]
[[variablelist [[Effects][Constructs the allocator.]]]]]
[[`template<class U> aligned_allocator(const aligned_allocator<U, Alignment>&)
noexcept;`]
[[variablelist [[Effects][Constructs the allocator.]]]]]]
[heading Member functions]
Except for the destructor, member functions of the aligned allocator shall not
introduce data races as a result of concurrent calls to those member functions
from different threads. Calls to these functions that allocate or deallocate a
particular unit of storage shall occur in a single total order, and each such
deallocation call shall happen before the next allocation (if any) in this
order.
[variablelist
[[`pointer allocate(size_type size, const_void_pointer = 0);`]
[[variablelist
[[Returns]
[A pointer to the initial element of an array of storage of size
`n * sizeof(T)`, aligned on the maximum of the minimum alignment specified and
the alignment of objects of type `T`.]]
[[Remark]
[The storage is obtained by calling `aligned_alloc(std::size_t,
std::size_t)`.]]
[[Throws][`std::bad_alloc` if the storage cannot be obtained.]]]]]
[[`void deallocate(pointer ptr, size_type);`]
[[variablelist
[[Requires]
[`ptr` shall be a pointer value obtained from `allocate()`.]]
[[Effects][Deallocates the storage referenced by `ptr`.]]
[[Remark][Uses `aligned_free(void*)`.]]]]]
[[`size_type max_size() const noexcept;`]
[[variablelist
[[Returns]
[The largest value `N` for which the call `allocate(N)` might succeed.]]]]]
[[`template<class U, class... Args> void construct(U* ptr, Args&&... args);`]
[[variablelist
[[Effects][`::new((void*)ptr) U(std::forward<Args>(args)...)`.]]]]]
[[`template<class U> void destroy(U* ptr);`]
[[variablelist [[Effects][`ptr->~U()`.]]]]]]
[heading Global operators]
[variablelist
[[`template<class T1, class T2, std::size_t Alignment> bool operator==(const
aligned_allocator<T1, Alignment>&, const aligned_allocator<T2, Alignment>&)
noexcept;`]
[[variablelist [[Returns][`true`]]]]]
[[`template<class T1, class T2, std::size_t Alignment> bool operator!=(const
aligned_allocator<T1, Alignment>&, const aligned_allocator<T2, Alignment>&)
noexcept;`]
[[variablelist [[Returns][`false`]]]]]]
[endsect]
[section aligned_allocator_adaptor]
[variablelist
[[`template<class Allocator, std::size_t Alignment = 1> class
aligned_allocator_adaptor;`]
[[variablelist
[[Header][`#include <boost/align/aligned_allocator_adaptor.hpp>`]]
[[Note]
[This adaptor can be used with a C++11 Allocator whose pointer type is a smart
pointer but the adaptor can choose to expose only raw pointer types.]]]]]]
[heading Member types]
[ordered_list
[`typedef typename Allocator::value_type value_type;`]
[`typedef value_type* pointer;`]
[`typedef const value_type* const_pointer;`]
[`typedef void* void_pointer;`]
[`typedef const void* const_void_pointer;`]
[`typedef std::size_t size_type;`]
[`typedef std::ptrdiff_t difference_type;`]
[`template<class U> struct rebind { typedef aligned_allocator_adaptor<typename
std::allocator_traits<Allocator>::template rebind_alloc<U>, Alignment>
other; };`]]
[heading Constructors]
[variablelist
[[`aligned_allocator_adaptor() = default;`]
[[variablelist [[Effects][Value-initializes the `Allocator` base class.]]]]]
[[`template<class A> aligned_allocator_adaptor(A&& alloc) noexcept;`]
[[variablelist [[Requires][`Allocator` shall be constructible from `A`.]]
[[Effects]
[Initializes the `Allocator` base class with `std::forward<A>(alloc)`.]]]]]
[[`template<class U> aligned_allocator_adaptor(const
aligned_allocator_adaptor<U, Alignment>& other) noexcept;`]
[[variablelist
[[Requires][`Allocator` shall be constructible from `A`.]]
[[Effects][Initializes the `Allocator` base class with `other.base()`.]]]]]]
[heading Member functions]
[variablelist
[[`Allocator& base() noexcept;`]
[[variablelist [[Returns][`static_cast<Allocator&>(*this)`]]]]]
[[`const Allocator& base() const noexcept;`]
[[variablelist [[Returns][`static_cast<const Allocator&>(*this)`]]]]]
[[`pointer allocate(size_type size);`]
[[variablelist
[[Returns]
[A pointer to the initial element of an array of storage of size
`n * sizeof(value_type)`, aligned on the maximum of the minimum alignment
specified and the alignment of objects of type `value_type`.]]
[[Remark]
[The storage is obtained by calling `A2::allocate()` on an object `a2`, where
`a2` of type `A2` is a rebound copy of `base()` where its `value_type` is
implementation defined.]]
[[Throws]
[Throws an exception thrown from `A2::allocate()` if the storage cannot be
obtained.]]]]]
[[`pointer allocate(size_type size, const_void_pointer hint);`]
[[variablelist
[[Requires]
[`hint` is a value obtained by calling `allocate()` on any equivalent allocator
object, or else a null pointer.]]
[[Returns]
[A pointer to the initial element of an array of storage of size
`n * sizeof(value_type)`, aligned on the maximum of the minimum alignment
specified and the alignment of objects of type `value_type`.]]
[[Remark]
[The storage is obtained by calling `A2::allocate()` on an object `a2`, where
`a2` of type `A2` is a rebound copy of `base()` where its `value_type` is an
implementation defined.]]
[[Throws]
[Throws an exception thrown from `A2::allocate()` if the storage cannot be
obtained.]]]]]
[[`void deallocate(pointer ptr, size_type size);`]
[[variablelist
[[Requires]
[[itemized_list
[`ptr` shall be a pointer value obtained from `allocate()`]
[`size` shall equal the value passed as the first argument to the invocation of
`allocate()` which returned `ptr`.]]]]
[[Effects][Deallocates the storage referenced by `ptr`.]]
[[Note]
[Uses `A2::deallocate()` on an object `a2`, where `a2` of type `A2` is a
rebound copy of `base()` where its `value_type` is implementation
defined.]]]]]]
[heading Global operators]
[variablelist
[[`template<class A1, class A2, std::size_t Alignment> bool operator==(const
aligned_allocator_adaptor<A1, Alignment>& a1, const
aligned_allocator_adaptor<A2, Alignment>& a2) noexcept;`]
[[variablelist [[Returns][`a1.base() == a2.base()`]]]]]
[[`template<class A1, class A2, std::size_t Alignment> bool operator!=(const
aligned_allocator_adaptor<A1, Alignment>& a1, const
aligned_allocator_adaptor<A2, Alignment>& a2) noexcept;`]
[[variablelist [[Returns][`!(a1 == a2)`]]]]]]
[endsect]
[section aligned_delete]
[variablelist
[[`class aligned_delete;`]
[[variablelist [[Header][`#include <boost/align/aligned_delete.hpp>`]]]]]]
[heading Member operators]
[variablelist
[[`template<class T> void operator()(T* ptr) noexcept(noexcept(ptr->~T()));`]
[[variablelist
[[Effects]
[Calls `~T()` on `ptr` to destroy the object and then calls `aligned_free()` on
`ptr` to free the allocated memory.]]
[[Note][If `T` is an incomplete type, the program is ill-formed.]]]]]]
[endsect]
[endsect]
[section Traits]
[section alignment_of]
[variablelist
[[`template<class T> struct alignment_of;`]
[[variablelist
[[Header][`#include <boost/align/alignment_of.hpp>`]]
[[Value]
[The alignment requirement of the type `T` as an integral constant of type
`std::size_t`. When `T` is a reference array type, the value shall be the
alignment of the referenced type. When `T` is an array type, the value shall be
the alignment of the element type.]]
[[Requires]
[`T` shall be a complete object type, or an array thereof, or a reference to
one of those types.]]]]]]
[endsect]
[endsect]
[section Macros]
[section BOOST_ALIGN_ASSUME_ALIGNED]
[variablelist
[[`BOOST_ALIGN_ASSUME_ALIGNED(ptr, alignment)`]
[[variablelist
[[Header][`#include <boost/align/assume_aligned.hpp>`]]
[[Requires]
[[itemized_list [`alignment` shall be a power of two]
[`ptr` shall be mutable]]]]
[[Effects]
[`ptr` may be modified in an implementation specific way to inform the compiler
of its alignment.]]]]]]
[endsect]
[endsect]
[endsect]
[section Vocabulary]
[heading \[basic.align\]]
Object types have /alignment requirements/ which place restrictions on the
addresses at which an object of that type may be allocated. An /alignment/ is
an implementation-defined integer value representing the number of bytes
between successive addresses at which a given object can be allocated. An
object type imposes an alignment requirement on every object of that type;
stricter alignment can be requested using the alignment specifier.
A /fundamental alignment/ is represented by an alignment less than or equal to
the greatest alignment supported by the implementation in all contexts, which
is equal to `alignof(std::max_align_t)`. The alignment required for a type
might be different when it is used as the type of a complete object and when
it is used as the type of a subobject.
\[['Example:]
[ordered_list
[`struct B { long double d; };`]
[`struct D : virtual B { char c; };`]]
When `D` is the type of a complete object, it will have a subobject of type
`B`, so it must be aligned appropriately for a `long double`. If `D` appears
as a subobject of another object that also has `B` as a virtual base class,
the `B` subobject might be part of a different subobject, reducing the
alignment requirements on the `D` subobject. \u2014['end example]\] The result
of the `alignof` operator reflects the alignment requirement of the type in
the complete-object case.
An /extended alignment/ is represented by an alignment greater than
`alignof(std::max_align_t)`. It is implementation-defined whether any extended
alignments are supported and the contexts in which they are supported. A type
having an extended alignment requirement is an /over-aligned type/. \[['Note:]
Every over-aligned type is or contains a class type to which extended
alignment applies (possibly through a non-static data member). \u2014['end
note]\]
Alignments are represented as values of the type `std::size_t`. Valid
alignments include only those values returned by an `alignof` expression for
the fundamental types plus an additional implementation-defined set of values,
which may be empty. Every alignment value shall be a non-negative integral
power of two.
Alignments have an order from /weaker/ to /stronger/ or /stricter/ alignments.
Stricter alignments have larger alignment values. An address that satisfies an
alignment requirement also satisfies any weaker valid alignment requirement.
The alignment requirement of a complete type can be queried using an `alignof`
expression. Furthermore, the types `char`, `signed char`, and `unsigned char`
shall have the weakest alignment requirement. \[['Note:] This enables the
character types to be used as the underlying type for an aligned memory area.
\u2014['end note]\]
Comparing alignments is meaningful and provides the obvious results:
* Two alignments are equal when their numeric values are equal.
* Two alignments are different when their numeric values are not equal.
* When an alignment is larger than another it represents a stricter
alignment.
\[['Note:] The runtime pointer alignment function can be used to obtain an
aligned pointer within a buffer; the aligned-storage templates in the library
can be used to obtain aligned storage. \u2014['end note]\]
If a request for a specific extended alignment in a specific context is not
supported by an implementation, the program is ill-formed. Additionally, a
request for runtime allocation of dynamic storage for which the requested
alignment cannot be honored shall be treated as an allocation failure.
[endsect]
[section Compatibility]
This library has been tested with the following C++ implementations:
[variablelist
[[Compilers][gcc, clang, msvc, intel]]
[[Libraries][libstdc++, libc++, dinkumware]]
[[Systems][linux, windows, osx]]
[[Platforms][x64, x86, arm]]
[[Standards][c++98, c++03, c++11, c++14, c++17]]]
[endsect]
[section Acknowledgments]
Thank you to everyone who reviewed the design, code, examples, tests, or
documentation, including:
* Peter Dimov
* Andrey Semashev
* Bjorn Reese
* Steven Watanabe
* Antony Polukhin
* Lars Viklund
* Michael Spencer
* Paul A. Bristow
Thank you to Ahmed Charles for serving as the review manager for the formal
review of the library.
[endsect]
[section History]
[variablelist
[[Boost 1.61]
[Functions for aligning up, down, and testing alignment of integral values.]]
[[Boost 1.59]
[Joel Falcou and Charly Chevalier contributed the alignment hint macro.]]
[[Boost 1.56]
[Glen Fernandes implemented and contributed the Align library to Boost.]]]
[endsect]

View File

@@ -0,0 +1,22 @@
/*
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)
*/
#ifndef BOOST_ALIGN_HPP
#define BOOST_ALIGN_HPP
#include <boost/align/align.hpp>
#include <boost/align/align_down.hpp>
#include <boost/align/align_up.hpp>
#include <boost/align/aligned_alloc.hpp>
#include <boost/align/aligned_allocator.hpp>
#include <boost/align/aligned_allocator_adaptor.hpp>
#include <boost/align/aligned_delete.hpp>
#include <boost/align/alignment_of.hpp>
#include <boost/align/assume_aligned.hpp>
#include <boost/align/is_aligned.hpp>
#endif

View File

@@ -0,0 +1,19 @@
/*
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)
*/
#ifndef BOOST_ALIGN_ALIGN_HPP
#define BOOST_ALIGN_ALIGN_HPP
#include <boost/config.hpp>
#if !defined(BOOST_NO_CXX11_STD_ALIGN) && !defined(BOOST_LIBSTDCXX_VERSION)
#include <boost/align/detail/align_cxx11.hpp>
#else
#include <boost/align/detail/align.hpp>
#endif
#endif

View File

@@ -0,0 +1,27 @@
/*
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)
*/
#ifndef BOOST_ALIGN_ALIGN_DOWN_HPP
#define BOOST_ALIGN_ALIGN_DOWN_HPP
#include <boost/align/detail/align_down.hpp>
#include <boost/align/detail/not_pointer.hpp>
namespace boost {
namespace alignment {
template<class T>
BOOST_CONSTEXPR inline typename detail::not_pointer<T, T>::type
align_down(T value, std::size_t alignment) BOOST_NOEXCEPT
{
return T(value & ~T(alignment - 1));
}
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,27 @@
/*
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)
*/
#ifndef BOOST_ALIGN_ALIGN_UP_HPP
#define BOOST_ALIGN_ALIGN_UP_HPP
#include <boost/align/detail/align_up.hpp>
#include <boost/align/detail/not_pointer.hpp>
namespace boost {
namespace alignment {
template<class T>
BOOST_CONSTEXPR inline typename detail::not_pointer<T, T>::type
align_up(T value, std::size_t alignment) BOOST_NOEXCEPT
{
return T((value + (T(alignment) - 1)) & ~T(alignment - 1));
}
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,47 @@
/*
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)
*/
#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(BOOST_ALIGN_USE_ALIGN)
#include <boost/align/detail/aligned_alloc.hpp>
#elif defined(BOOST_ALIGN_USE_NEW)
#include <boost/align/detail/aligned_alloc_new.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>
#elif defined(__MINGW32__)
#include <boost/align/detail/aligned_alloc_mingw.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

View File

@@ -0,0 +1,140 @@
/*
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)
*/
#ifndef BOOST_ALIGN_ALIGNED_ALLOCATOR_HPP
#define BOOST_ALIGN_ALIGNED_ALLOCATOR_HPP
#include <boost/align/detail/add_reference.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/detail/throw_exception.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 <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 typename detail::add_lvalue_reference<T>::type reference;
typedef typename detail::add_lvalue_reference<const
T>::type const_reference;
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef detail::true_type propagate_on_container_move_assignment;
typedef detail::true_type is_always_equal;
template<class U>
struct rebind {
typedef aligned_allocator<U, Alignment> other;
};
#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS)
aligned_allocator() = default;
#else
aligned_allocator() BOOST_NOEXCEPT { }
#endif
template<class U>
aligned_allocator(const aligned_allocator<U, Alignment>&)
BOOST_NOEXCEPT { }
pointer allocate(size_type size, const_void_pointer = 0) {
enum {
m = detail::max_size<Alignment,
alignment_of<value_type>::value>::value
};
if (size == 0) {
return 0;
}
void* p = boost::alignment::aligned_alloc(m, sizeof(T) * size);
if (!p) {
detail::throw_exception(std::bad_alloc());
}
return static_cast<T*>(p);
}
void deallocate(pointer ptr, size_type) {
boost::alignment::aligned_free(ptr);
}
BOOST_CONSTEXPR size_type max_size() const BOOST_NOEXCEPT {
return detail::max_objects<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) {
::new((void*)ptr) U(std::forward<Args>(args)...);
}
#else
template<class U, class V>
void construct(U* ptr, V&& value) {
::new((void*)ptr) U(std::forward<V>(value));
}
#endif
#else
template<class U, class V>
void construct(U* ptr, const V& value) {
::new((void*)ptr) U(value);
}
template<class U, class V>
void construct(U* ptr, V& value) {
::new((void*)ptr) U(value);
}
#endif
template<class U>
void construct(U* ptr) {
::new((void*)ptr) U();
}
template<class U>
void destroy(U* ptr) {
(void)ptr;
ptr->~U();
}
};
template<class T, class U, std::size_t Alignment>
inline bool
operator==(const aligned_allocator<T, Alignment>&,
const aligned_allocator<U, Alignment>&) BOOST_NOEXCEPT
{
return true;
}
template<class T, class U, std::size_t Alignment>
inline bool
operator!=(const aligned_allocator<T, Alignment>&,
const aligned_allocator<U, Alignment>&) BOOST_NOEXCEPT
{
return false;
}
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,170 @@
/*
Copyright 2014-2016 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_ALIGN_ALIGNED_ALLOCATOR_ADAPTOR_HPP
#define BOOST_ALIGN_ALIGNED_ALLOCATOR_ADAPTOR_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/core/pointer_traits.hpp>
#include <boost/static_assert.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> char_alloc;
typedef typename traits::template rebind_traits<char> char_traits;
typedef typename char_traits::pointer char_ptr;
#else
typedef typename Allocator::template rebind<char>::other char_alloc;
typedef typename char_alloc::pointer char_ptr;
#endif
public:
typedef typename Allocator::value_type value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef void* void_pointer;
typedef const void* const_void_pointer;
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
private:
template<class U>
struct min_align {
enum {
value = detail::max_size<Alignment,
detail::max_align<U, char_ptr>::value>::value
};
};
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
};
aligned_allocator_adaptor()
: Allocator() { }
#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) {
enum {
m = min_align<value_type>::value
};
std::size_t s = size * sizeof(value_type);
std::size_t n = s + m - 1;
char_alloc a(base());
char_ptr p = a.allocate(sizeof p + n);
void* r = boost::to_address(p) + sizeof p;
(void)boost::alignment::align(m, 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) {
enum {
m = min_align<value_type>::value
};
std::size_t s = size * sizeof(value_type);
std::size_t n = s + m - 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 p = char_traits::allocate(a, sizeof p + n, h);
#else
char_ptr p = a.allocate(sizeof p + n, h);
#endif
void* r = boost::to_address(p) + sizeof p;
(void)boost::alignment::align(m, 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) {
enum {
m = min_align<value_type>::value
};
char_ptr* p = reinterpret_cast<char_ptr*>(ptr) - 1;
char_ptr r = *p;
p->~char_ptr();
char_alloc a(base());
a.deallocate(r, sizeof r + size * sizeof(value_type) + m - 1);
}
};
template<class A, class B, std::size_t Alignment>
inline bool
operator==(const aligned_allocator_adaptor<A, Alignment>& a,
const aligned_allocator_adaptor<B, Alignment>& b) BOOST_NOEXCEPT
{
return a.base() == b.base();
}
template<class A, class B, std::size_t Alignment>
inline bool
operator!=(const aligned_allocator_adaptor<A, Alignment>& a,
const aligned_allocator_adaptor<B, Alignment>& b) BOOST_NOEXCEPT
{
return !(a == b);
}
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,22 @@
/*
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)
*/
#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;
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,22 @@
/*
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)
*/
#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;
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,31 @@
/*
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)
*/
#ifndef BOOST_ALIGN_ALIGNED_DELETE_HPP
#define BOOST_ALIGN_ALIGNED_DELETE_HPP
#include <boost/align/aligned_alloc.hpp>
#include <boost/align/aligned_delete_forward.hpp>
namespace boost {
namespace alignment {
struct aligned_delete {
template<class T>
void operator()(T* ptr) const
BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT_EXPR(ptr->~T())) {
if (ptr) {
ptr->~T();
boost::alignment::aligned_free(ptr);
}
}
};
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,19 @@
/*
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)
*/
#ifndef BOOST_ALIGN_ALIGNED_DELETE_FORWARD_HPP
#define BOOST_ALIGN_ALIGNED_DELETE_FORWARD_HPP
namespace boost {
namespace alignment {
struct aligned_delete;
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,54 @@
/*
Copyright 2014-2016 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_ALIGN_ALIGNMENT_OF_HPP
#define BOOST_ALIGN_ALIGNMENT_OF_HPP
#include <boost/align/detail/element_type.hpp>
#include <boost/align/alignment_of_forward.hpp>
#if defined(_MSC_VER) && defined(__clang__)
#include <boost/align/detail/alignment_of_cxx11.hpp>
#elif defined(BOOST_MSVC)
#include <boost/align/detail/alignment_of_msvc.hpp>
#elif defined(__GNUC__) && defined(__unix__) && !defined(__LP64__)
#include <boost/align/detail/alignment_of.hpp>
#elif defined(BOOST_CLANG) && !defined(__x86_64__)
#include <boost/align/detail/alignment_of.hpp>
#elif !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
#include <boost/align/detail/alignment_of_cxx11.hpp>
#elif defined(__ghs__) && (__GHS_VERSION_NUMBER >= 600)
#include <boost/align/detail/alignment_of_gcc.hpp>
#elif defined(BOOST_CODEGEARC)
#include <boost/align/detail/alignment_of_codegear.hpp>
#elif defined(BOOST_CLANG)
#include <boost/align/detail/alignment_of_clang.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::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 */
#endif

View File

@@ -0,0 +1,20 @@
/*
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)
*/
#ifndef BOOST_ALIGN_ALIGNMENT_OF_FORWARD_HPP
#define BOOST_ALIGN_ALIGNMENT_OF_FORWARD_HPP
namespace boost {
namespace alignment {
template<class T>
struct alignment_of;
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,28 @@
/*
Copyright 2015 NumScale SAS
Copyright 2015 LRI UMR 8623 CNRS/University Paris Sud XI
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)
*/
#ifndef BOOST_ALIGN_ASSUME_ALIGNED_HPP
#define BOOST_ALIGN_ASSUME_ALIGNED_HPP
#include <boost/config.hpp>
#if defined(BOOST_MSVC)
#include <boost/align/detail/assume_aligned_msvc.hpp>
#elif defined(BOOST_CLANG) && defined(__has_builtin)
#include <boost/align/detail/assume_aligned_clang.hpp>
#elif BOOST_GCC_VERSION >= 40700
#include <boost/align/detail/assume_aligned_gcc.hpp>
#elif defined(__INTEL_COMPILER)
#include <boost/align/detail/assume_aligned_intel.hpp>
#else
#include <boost/align/detail/assume_aligned.hpp>
#endif
#endif

View File

@@ -0,0 +1,44 @@
/*
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)
*/
#ifndef BOOST_ALIGN_DETAIL_ADD_REFERENCE_HPP
#define BOOST_ALIGN_DETAIL_ADD_REFERENCE_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::add_lvalue_reference;
#else
template<class T>
struct add_lvalue_reference {
typedef T& type;
};
template<>
struct add_lvalue_reference<void> {
typedef void type;
};
template<>
struct add_lvalue_reference<const void> {
typedef const void type;
};
#endif
} /* detail */
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,38 @@
/*
Copyright 2014-2020 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_ALIGN_DETAIL_ALIGN_HPP
#define BOOST_ALIGN_DETAIL_ALIGN_HPP
#include <boost/align/detail/is_alignment.hpp>
#include <boost/assert.hpp>
namespace boost {
namespace alignment {
inline void*
align(std::size_t alignment, std::size_t size, void*& ptr,
std::size_t& space)
{
BOOST_ASSERT(boost::alignment::detail::is_alignment(alignment));
if (size <= space) {
char* p = reinterpret_cast<char*>(~(alignment - 1) &
(reinterpret_cast<std::size_t>(ptr) + alignment - 1));
std::size_t n = p - static_cast<char*>(ptr);
if (n <= space - size) {
ptr = p;
space -= n;
return p;
}
}
return 0;
}
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,21 @@
/*
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)
*/
#ifndef BOOST_ALIGN_DETAIL_ALIGN_CXX11_HPP
#define BOOST_ALIGN_DETAIL_ALIGN_CXX11_HPP
#include <memory>
namespace boost {
namespace alignment {
using std::align;
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,28 @@
/*
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)
*/
#ifndef BOOST_ALIGN_DETAIL_ALIGN_DOWN_HPP
#define BOOST_ALIGN_DETAIL_ALIGN_DOWN_HPP
#include <boost/align/detail/is_alignment.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*>(~(alignment - 1) &
reinterpret_cast<std::size_t>(ptr));
}
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,28 @@
/*
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)
*/
#ifndef BOOST_ALIGN_DETAIL_ALIGN_UP_HPP
#define BOOST_ALIGN_DETAIL_ALIGN_UP_HPP
#include <boost/align/detail/is_alignment.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*>(~(alignment - 1) &
(reinterpret_cast<std::size_t>(ptr) + alignment - 1));
}
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,52 @@
/*
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)
*/
#ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_HPP
#define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_HPP
#include <boost/align/detail/is_alignment.hpp>
#include <boost/align/align.hpp>
#include <boost/align/alignment_of.hpp>
#include <boost/assert.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));
enum {
N = alignment_of<void*>::value
};
if (alignment < N) {
alignment = N;
}
std::size_t n = size + alignment - N;
void* p = std::malloc(sizeof(void*) + n);
if (p) {
void* r = static_cast<char*>(p) + sizeof(void*);
(void)boost::alignment::align(alignment, size, r, n);
*(static_cast<void**>(r) - 1) = p;
p = r;
}
return p;
}
inline void
aligned_free(void* ptr) BOOST_NOEXCEPT
{
if (ptr) {
std::free(*(static_cast<void**>(ptr) - 1));
}
}
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,34 @@
/*
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)
*/
#ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_ANDROID_HPP
#define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_ANDROID_HPP
#include <boost/align/detail/is_alignment.hpp>
#include <boost/assert.hpp>
#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);
}
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,44 @@
/*
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)
*/
#ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_MACOS_HPP
#define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_MACOS_HPP
#include <boost/align/detail/is_alignment.hpp>
#include <boost/assert.hpp>
#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 == 0) {
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);
}
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,34 @@
/*
Copyright 2020 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_MINGW_HPP
#define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_MINGW_HPP
#include <boost/align/detail/is_alignment.hpp>
#include <boost/assert.hpp>
#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 ::__mingw_aligned_malloc(size, alignment);
}
inline void
aligned_free(void* ptr) BOOST_NOEXCEPT
{
::__mingw_aligned_free(ptr);
}
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,34 @@
/*
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)
*/
#ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_MSVC_HPP
#define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_MSVC_HPP
#include <boost/align/detail/is_alignment.hpp>
#include <boost/assert.hpp>
#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);
}
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,52 @@
/*
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)
*/
#ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_NEW_HPP
#define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_NEW_HPP
#include <boost/align/detail/is_alignment.hpp>
#include <boost/align/align.hpp>
#include <boost/align/alignment_of.hpp>
#include <boost/assert.hpp>
#include <new>
namespace boost {
namespace alignment {
inline void*
aligned_alloc(std::size_t alignment, std::size_t size) BOOST_NOEXCEPT
{
BOOST_ASSERT(detail::is_alignment(alignment));
enum {
N = alignment_of<void*>::value
};
if (alignment < N) {
alignment = N;
}
std::size_t n = size + alignment - N;
void* p = ::operator new(sizeof(void*) + n, std::nothrow);
if (p) {
void* r = static_cast<char*>(p) + sizeof(void*);
(void)boost::alignment::align(alignment, size, r, n);
*(static_cast<void**>(r) - 1) = p;
p = r;
}
return p;
}
inline void
aligned_free(void* ptr) BOOST_NOEXCEPT
{
if (ptr) {
::operator delete(*(static_cast<void**>(ptr) - 1));
}
}
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,41 @@
/*
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)
*/
#ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_POSIX_HPP
#define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_POSIX_HPP
#include <boost/align/detail/is_alignment.hpp>
#include <boost/assert.hpp>
#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);
}
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,34 @@
/*
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)
*/
#ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_SUNOS_HPP
#define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_SUNOS_HPP
#include <boost/align/detail/is_alignment.hpp>
#include <boost/assert.hpp>
#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);
}
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,31 @@
/*
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)
*/
#ifndef BOOST_ALIGN_DETAIL_ALIGNMENT_OF_HPP
#define BOOST_ALIGN_DETAIL_ALIGNMENT_OF_HPP
#include <boost/align/detail/min_size.hpp>
namespace boost {
namespace alignment {
namespace detail {
template<class T>
struct offset_value {
char value;
T object;
};
template<class T>
struct alignment_of
: min_size<sizeof(T), sizeof(offset_value<T>) - sizeof(T)> { };
} /* detail */
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,26 @@
/*
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)
*/
#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)> { };
} /* detail */
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,26 @@
/*
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)
*/
#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)> { };
} /* detail */
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,23 @@
/*
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)
*/
#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;
} /* detail */
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,26 @@
/*
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)
*/
#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)> { };
} /* detail */
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,32 @@
/*
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)
*/
#ifndef BOOST_ALIGN_DETAIL_ALIGNMENT_OF_MSVC_HPP
#define BOOST_ALIGN_DETAIL_ALIGNMENT_OF_MSVC_HPP
#include <boost/align/detail/min_size.hpp>
namespace boost {
namespace alignment {
namespace detail {
template<class T>
struct offset_value {
T first;
char value;
T second;
};
template<class T>
struct alignment_of
: min_size<sizeof(T), sizeof(offset_value<T>) - (sizeof(T) << 1)> { };
} /* detail */
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,16 @@
/*
Copyright 2015 NumScale SAS
Copyright 2015 LRI UMR 8623 CNRS/University Paris Sud XI
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)
*/
#ifndef BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_HPP
#define BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_HPP
#define BOOST_ALIGN_ASSUME_ALIGNED(ptr, alignment)
#endif

View File

@@ -0,0 +1,18 @@
/*
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)
*/
#ifndef BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_CLANG_HPP
#define BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_CLANG_HPP
#if __has_builtin(__builtin_assume_aligned)
#define BOOST_ALIGN_ASSUME_ALIGNED(p, n) \
(p) = static_cast<__typeof__(p)>(__builtin_assume_aligned((p), (n)))
#else
#define BOOST_ALIGN_ASSUME_ALIGNED(p, n)
#endif
#endif

View File

@@ -0,0 +1,17 @@
/*
Copyright 2015 NumScale SAS
Copyright 2015 LRI UMR 8623 CNRS/University Paris Sud XI
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)
*/
#ifndef BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_GCC_HPP
#define BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_GCC_HPP
#define BOOST_ALIGN_ASSUME_ALIGNED(p, n) \
(p) = static_cast<__typeof__(p)>(__builtin_assume_aligned((p), (n)))
#endif

View File

@@ -0,0 +1,17 @@
/*
Copyright 2015 NumScale SAS
Copyright 2015 LRI UMR 8623 CNRS/University Paris Sud XI
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)
*/
#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))
#endif

View File

@@ -0,0 +1,19 @@
/*
Copyright 2015 NumScale SAS
Copyright 2015 LRI UMR 8623 CNRS/University Paris Sud XI
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)
*/
#ifndef BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_MSVC_HPP
#define BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_MSVC_HPP
#include <cstddef>
#define BOOST_ALIGN_ASSUME_ALIGNED(ptr, alignment) \
__assume((reinterpret_cast<std::size_t>(ptr) & ((alignment) - 1)) == 0)
#endif

View File

@@ -0,0 +1,91 @@
/*
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)
*/
#ifndef BOOST_ALIGN_DETAIL_ELEMENT_TYPE_HPP
#define BOOST_ALIGN_DETAIL_ELEMENT_TYPE_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_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;
};
#endif
template<class T>
struct element_type {
typedef typename remove_cv<typename remove_all_extents<typename
remove_reference<T>::type>::type>::type type;
};
} /* detail */
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,53 @@
/*
Copyright 2014-2016 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.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;
using std::true_type;
using std::false_type;
#else
template<class T, T Value>
struct integral_constant {
typedef T value_type;
typedef integral_constant type;
BOOST_CONSTEXPR operator value_type() const BOOST_NOEXCEPT {
return Value;
}
BOOST_CONSTEXPR value_type operator()() const BOOST_NOEXCEPT {
return Value;
}
BOOST_STATIC_CONSTEXPR T value = Value;
};
template<class T, T Value>
BOOST_CONSTEXPR_OR_CONST T integral_constant<T, Value>::value;
typedef integral_constant<bool, true> true_type;
typedef integral_constant<bool, false> false_type;
#endif
} /* detail */
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,34 @@
/*
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)
*/
#ifndef BOOST_ALIGN_DETAIL_IS_ALIGNED_HPP
#define BOOST_ALIGN_DETAIL_IS_ALIGNED_HPP
#include <boost/align/detail/is_alignment.hpp>
#include <boost/assert.hpp>
namespace boost {
namespace alignment {
inline bool
is_aligned(const volatile void* ptr, std::size_t alignment) BOOST_NOEXCEPT
{
BOOST_ASSERT(detail::is_alignment(alignment));
return (reinterpret_cast<std::size_t>(ptr) & (alignment - 1)) == 0;
}
inline bool
is_aligned(std::size_t alignment, const volatile void* ptr) BOOST_NOEXCEPT
{
BOOST_ASSERT(detail::is_alignment(alignment));
return (reinterpret_cast<std::size_t>(ptr) & (alignment - 1)) == 0;
}
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,28 @@
/*
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)
*/
#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);
}
} /* detail */
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,26 @@
/*
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)
*/
#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)> { };
} /* detail */
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,26 @@
/*
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)
*/
#ifndef BOOST_ALIGN_DETAIL_MAX_ALIGN_HPP
#define BOOST_ALIGN_DETAIL_MAX_ALIGN_HPP
#include <boost/align/detail/max_size.hpp>
#include <boost/align/alignment_of.hpp>
namespace boost {
namespace alignment {
namespace detail {
template<class A, class B>
struct max_align
: max_size<alignment_of<A>::value, alignment_of<B>::value> { };
} /* detail */
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,27 @@
/*
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)
*/
#ifndef BOOST_ALIGN_DETAIL_MAX_OBJECTS_HPP
#define BOOST_ALIGN_DETAIL_MAX_OBJECTS_HPP
#include <boost/align/detail/integral_constant.hpp>
#include <cstddef>
namespace boost {
namespace alignment {
namespace detail {
template<class T>
struct max_objects
: integral_constant<std::size_t,
~static_cast<std::size_t>(0) / sizeof(T)> { };
} /* detail */
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,26 @@
/*
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)
*/
#ifndef BOOST_ALIGN_DETAIL_MAX_SIZE_HPP
#define BOOST_ALIGN_DETAIL_MAX_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 max_size
: integral_constant<std::size_t, (A > B) ? A : B> { };
} /* detail */
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,26 @@
/*
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)
*/
#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> { };
} /* detail */
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,27 @@
/*
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)
*/
#ifndef BOOST_ALIGN_DETAIL_NOT_POINTER_HPP
#define BOOST_ALIGN_DETAIL_NOT_POINTER_HPP
namespace boost {
namespace alignment {
namespace detail {
template<class T, class U>
struct not_pointer {
typedef U type;
};
template<class T, class U>
struct not_pointer<T*, U> { };
} /* detail */
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,44 @@
/*
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)
*/
#ifndef BOOST_ALIGN_DETAIL_THROW_EXCEPTION_HPP
#define BOOST_ALIGN_DETAIL_THROW_EXCEPTION_HPP
#include <boost/config.hpp>
#if defined(BOOST_NO_EXCEPTIONS)
#include <exception>
#endif
namespace boost {
#if defined(BOOST_NO_EXCEPTIONS)
BOOST_NORETURN void throw_exception(const std::exception&);
#endif
namespace alignment {
namespace detail {
#if !defined(BOOST_NO_EXCEPTIONS)
template<class E>
BOOST_NORETURN inline void
throw_exception(const E& error)
{
throw error;
}
#else
BOOST_NORETURN inline void
throw_exception(const std::exception& error)
{
boost::throw_exception(error);
}
#endif
} /* detail */
} /* alignment */
} /* boost */
#endif

View File

@@ -0,0 +1,28 @@
/*
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)
*/
#ifndef BOOST_ALIGN_IS_ALIGNED_HPP
#define BOOST_ALIGN_IS_ALIGNED_HPP
#include <boost/align/detail/is_aligned.hpp>
#include <boost/align/detail/not_pointer.hpp>
namespace boost {
namespace alignment {
template<class T>
BOOST_CONSTEXPR inline typename detail::not_pointer<T, bool>::type
is_aligned(T value, std::size_t alignment) BOOST_NOEXCEPT
{
return (value & (T(alignment) - 1)) == 0;
}
} /* alignment */
} /* boost */
#endif

View File

@@ -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>

View File

@@ -0,0 +1,15 @@
{
"key": "align",
"name": "Align",
"description": "Memory alignment functions, allocators, traits.",
"authors": [
"Glen Fernandes"
],
"maintainers": [
"Glen Fernandes <glenjofe -at- gmail.com>"
],
"category": [
"Memory"
],
"cxxstd": "03"
}

View File

@@ -0,0 +1,25 @@
# 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_overflow_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 ;

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -0,0 +1,25 @@
/*
Copyright 2020 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/core/lightweight_test.hpp>
int main()
{
static const std::size_t n = -1;
{
void* p = reinterpret_cast<void*>(5);
std::size_t s = 3072;
BOOST_TEST(!boost::alignment::align(1024, n, p, s));
}
{
void* p = reinterpret_cast<void*>(1);
std::size_t s = -1;
BOOST_TEST(!boost::alignment::align(2, n, p, s));
}
return boost::report_errors();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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;
}

View File

@@ -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();
}

View File

@@ -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;
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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;
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -0,0 +1,7 @@
-- Downloading https://github.com/boostorg/align/archive/boost-1.79.0.tar.gz -> boostorg-align-boost-1.79.0.tar.gz...
-- Extracting source D:/a/1/s/externals/vcpkg/downloads/boostorg-align-boost-1.79.0.tar.gz
-- Using source at D:/a/1/s/externals/vcpkg/buildtrees/boost-align/src/ost-1.79.0-5ab20321db.clean
-- Copying headers
-- Copying headers done
-- Installing: D:/a/1/s/externals/vcpkg/packages/boost-align_x64-windows/share/boost-align/usage
-- Installing: D:/a/1/s/externals/vcpkg/packages/boost-align_x64-windows/share/boost-align/copyright

View File

@@ -0,0 +1,16 @@
boost-assert a50eed453b8be6c8932fb3d5f8feaf194a2ebeaed7982db4e36e3ba17f3ec107
boost-config 797535e8975ed7cf5bbe11d9f7fe26caa5da8fe819888564758d82a21109fade
boost-core 498aea0b6b68bcfe1ec683e76c2f0d32477dfe9ba958f518980ff806b6faba90
boost-static-assert 795e87a155fce50821163bc84e802f28dce54e4af6a3a86045f9ecec76ad4c95
boost-vcpkg-helpers c81c7b003df356a1a120a7c0c2f5a2ac95f3c33b006a2a5b4c02dcf0c9f3deaa
cmake 3.23.2
features core
portfile.cmake b48c941c88187f818ca82432594eb6dacbe6748906036bbbe0444ee90b8de0a1
ports.cmake 366c60b768113102408b32ac1d7c7b48ef7d30a477af2a220ecc222d9ffa3166
post_build_checks 2
powershell 7.2.5
triplet x64-windows
triplet_abi 4556164a2cd3dd6f4742101eabb46def7e71b6e5856faa88e5d005aac12a803c-c0600b35e024ce0485ed253ef5419f3686f7257cfb58cb6a24febcb600fc4b4c-27ebd443f77a6c449168adfa6ce8def60cf46e88
vcpkg.json eba8b76620a4098492bca6f803b401255d9e1e176c9055aee295b448411ff786
vcpkg_from_git 0aab20e34e84d52ba4763f009e539bfa8f418c41c918c8cf700156f1a8551a10
vcpkg_from_github b743742296a114ea1b18ae99672e02f142c4eb2bef7f57d36c038bedbfb0502f