├── .appveyor.yml ├── .github └── workflows │ └── ci.yml ├── .travis.yml ├── CMakeLists.txt ├── README.md ├── doc ├── Jamfile └── align.qbk ├── include └── boost │ ├── align.hpp │ └── align │ ├── align.hpp │ ├── align_down.hpp │ ├── align_up.hpp │ ├── aligned_alloc.hpp │ ├── aligned_allocator.hpp │ ├── aligned_allocator_adaptor.hpp │ ├── aligned_allocator_adaptor_forward.hpp │ ├── aligned_allocator_forward.hpp │ ├── aligned_delete.hpp │ ├── aligned_delete_forward.hpp │ ├── alignment_of.hpp │ ├── alignment_of_forward.hpp │ ├── assume_aligned.hpp │ ├── detail │ ├── add_reference.hpp │ ├── align.hpp │ ├── align_cxx11.hpp │ ├── align_down.hpp │ ├── align_up.hpp │ ├── aligned_alloc.hpp │ ├── aligned_alloc_android.hpp │ ├── aligned_alloc_macos.hpp │ ├── aligned_alloc_mingw.hpp │ ├── aligned_alloc_msvc.hpp │ ├── aligned_alloc_new.hpp │ ├── aligned_alloc_posix.hpp │ ├── aligned_alloc_sunos.hpp │ ├── alignment_of.hpp │ ├── alignment_of_clang.hpp │ ├── alignment_of_codegear.hpp │ ├── alignment_of_cxx11.hpp │ ├── alignment_of_gcc.hpp │ ├── alignment_of_msvc.hpp │ ├── assume_aligned.hpp │ ├── assume_aligned_clang.hpp │ ├── assume_aligned_gcc.hpp │ ├── assume_aligned_intel.hpp │ ├── assume_aligned_msvc.hpp │ ├── element_type.hpp │ ├── integral_constant.hpp │ ├── is_aligned.hpp │ ├── is_alignment.hpp │ ├── is_alignment_constant.hpp │ ├── max_align.hpp │ ├── max_objects.hpp │ ├── max_size.hpp │ ├── min_size.hpp │ ├── not_pointer.hpp │ └── throw_exception.hpp │ └── is_aligned.hpp ├── index.html ├── meta └── libraries.json └── test ├── Jamfile ├── align_down_integral_test.cpp ├── align_down_test.cpp ├── align_overflow_test.cpp ├── align_test.cpp ├── align_up_integral_test.cpp ├── align_up_test.cpp ├── aligned_alloc_test.cpp ├── aligned_allocator_adaptor_incomplete_test.cpp ├── aligned_allocator_adaptor_test.cpp ├── aligned_allocator_incomplete_test.cpp ├── aligned_allocator_test.cpp ├── aligned_delete_test.cpp ├── alignment_of_test.cpp ├── assume_aligned_test.cpp ├── is_aligned_integral_test.cpp └── is_aligned_test.cpp /.appveyor.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Glen Joseph Fernandes 2 | # (glenjofe@gmail.com) 3 | # 4 | # Distributed under the Boost Software License, Version 1.0. 5 | # (http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | version: 1.0.{build}-{branch} 8 | 9 | shallow_clone: true 10 | 11 | branches: 12 | only: 13 | - master 14 | - develop 15 | 16 | environment: 17 | matrix: 18 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 19 | TOOLSET: msvc-9.0 20 | TARGET: 32 21 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 22 | TOOLSET: msvc-10.0 23 | TARGET: 32 24 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 25 | TOOLSET: msvc-11.0 26 | TARGET: 32 27 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 28 | TOOLSET: msvc-12.0 29 | TARGET: 32,64 30 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 31 | TOOLSET: msvc-14.0 32 | TARGET: 32,64 33 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 34 | TOOLSET: msvc-14.1 35 | TARGET: 32,64 36 | STANDARD: 14,17 37 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 38 | TOOLSET: msvc-14.2 39 | TARGET: 32,64 40 | STANDARD: 14,17 41 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 42 | TOOLSET: clang-win 43 | TARGET: 32,64 44 | STANDARD: 14,17 45 | 46 | install: 47 | - cd .. 48 | - git clone -b %APPVEYOR_REPO_BRANCH% https://github.com/boostorg/boost 49 | - cd boost 50 | - git submodule init libs/assert 51 | - git submodule init libs/config 52 | - git submodule init libs/core 53 | - git submodule init libs/static_assert 54 | - git submodule init libs/headers 55 | - git submodule init tools/build 56 | - git submodule init tools/boost_install 57 | - git submodule update 58 | - xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\align 59 | - cmd /c bootstrap 60 | - b2 headers 61 | 62 | build: off 63 | 64 | test_script: 65 | - if not "%STANDARD%" == "" set STANDARD=cxxstd=%STANDARD% 66 | - b2 libs/align/test toolset=%TOOLSET% address-model=%TARGET% %STANDARD% 67 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: 7 | - master 8 | - develop 9 | 10 | jobs: 11 | posix: 12 | strategy: 13 | fail-fast: false 14 | matrix: 15 | include: 16 | - toolset: gcc-4.8 17 | standard: "03,11" 18 | os: ubuntu-18.04 19 | install: g++-4.8 20 | - toolset: gcc-5 21 | standard: "03,11,14,1z" 22 | os: ubuntu-18.04 23 | install: g++-5 24 | - toolset: gcc-6 25 | standard: "03,11,14,1z" 26 | os: ubuntu-18.04 27 | install: g++-6 28 | - toolset: gcc-7 29 | standard: "03,11,14,17" 30 | os: ubuntu-18.04 31 | - toolset: gcc-8 32 | standard: "03,11,14,17,2a" 33 | os: ubuntu-18.04 34 | install: g++-8 35 | - toolset: gcc-9 36 | standard: "03,11,14,17,2a" 37 | os: ubuntu-18.04 38 | - toolset: gcc-10 39 | standard: "03,11,14,17,2a" 40 | os: ubuntu-20.04 41 | install: g++-10 42 | - toolset: gcc-11 43 | standard: "03,11,14,17,2a" 44 | os: ubuntu-20.04 45 | install: g++-11 46 | - toolset: clang 47 | compiler: clang++-3.9 48 | standard: "03,11,14" 49 | os: ubuntu-18.04 50 | install: clang-3.9 51 | - toolset: clang 52 | compiler: clang++-4.0 53 | standard: "03,11,14" 54 | os: ubuntu-18.04 55 | install: clang-4.0 56 | - toolset: clang 57 | compiler: clang++-5.0 58 | standard: "03,11,14,1z" 59 | os: ubuntu-18.04 60 | install: clang-5.0 61 | - toolset: clang 62 | compiler: clang++-6.0 63 | standard: "03,11,14,17" 64 | os: ubuntu-18.04 65 | install: clang-6.0 66 | - toolset: clang 67 | compiler: clang++-7 68 | standard: "03,11,14,17" 69 | os: ubuntu-18.04 70 | install: clang-7 71 | - toolset: clang 72 | compiler: clang++-8 73 | standard: "03,11,14,17" 74 | os: ubuntu-20.04 75 | install: clang-8 76 | - toolset: clang 77 | compiler: clang++-9 78 | standard: "03,11,14,17,2a" 79 | os: ubuntu-20.04 80 | install: clang-9 81 | - toolset: clang 82 | compiler: clang++-10 83 | standard: "03,11,14,17,2a" 84 | os: ubuntu-20.04 85 | install: clang-10 86 | - toolset: clang 87 | compiler: clang++-11 88 | cxxstd: "03,11,14,17,2a" 89 | os: ubuntu-20.04 90 | install: clang-11 91 | - toolset: clang 92 | compiler: clang++-12 93 | cxxstd: "03,11,14,17,2a" 94 | os: ubuntu-20.04 95 | install: clang-12 96 | - toolset: clang 97 | standard: "03,11,14,17,2a" 98 | os: macos-10.15 99 | 100 | runs-on: ${{matrix.os}} 101 | 102 | steps: 103 | - uses: actions/checkout@v2 104 | 105 | - name: Install packages 106 | if: matrix.install 107 | run: sudo apt install ${{matrix.install}} 108 | 109 | - name: Setup Boost 110 | run: | 111 | cd .. 112 | git clone --depth 1 https://github.com/boostorg/boost 113 | cd boost 114 | cp -r $GITHUB_WORKSPACE/* libs/align 115 | git submodule init libs/assert 116 | git submodule init libs/config 117 | git submodule init libs/core 118 | git submodule init libs/static_assert 119 | git submodule init libs/headers 120 | git submodule init tools/build 121 | git submodule init tools/boost_install 122 | git submodule update 123 | ./bootstrap.sh 124 | ./b2 -d0 headers 125 | 126 | - name: Create user-config.jam 127 | if: matrix.compiler 128 | run: | 129 | echo "using ${{matrix.toolset}} : : ${{matrix.compiler}} ;" > ~/user-config.jam 130 | 131 | - name: Run tests 132 | run: | 133 | cd ../boost 134 | ./b2 -j3 libs/align/test toolset=${{matrix.toolset}} cxxstd=${{matrix.standard}} variant=debug,release 135 | 136 | windows: 137 | strategy: 138 | fail-fast: false 139 | matrix: 140 | include: 141 | - toolset: msvc-14.1 142 | standard: "14,17,latest" 143 | target: 32,64 144 | os: windows-2016 145 | - toolset: msvc-14.2 146 | standard: "14,17,latest" 147 | target: 32,64 148 | os: windows-2019 149 | - toolset: msvc-14.3 150 | cxxstd: "14,17,latest" 151 | addrmd: 32,64 152 | os: windows-2022 153 | - toolset: gcc 154 | standard: "03,11,14,17,2a" 155 | target: 64 156 | os: windows-2019 157 | 158 | runs-on: ${{matrix.os}} 159 | 160 | steps: 161 | - uses: actions/checkout@v2 162 | 163 | - name: Setup Boost 164 | shell: cmd 165 | run: | 166 | cd .. 167 | git clone --depth 1 https://github.com/boostorg/boost boost 168 | cd boost 169 | xcopy /s /e /q %GITHUB_WORKSPACE% libs\align\ 170 | git submodule init libs/assert 171 | git submodule init libs/config 172 | git submodule init libs/core 173 | git submodule init libs/static_assert 174 | git submodule init libs/headers 175 | git submodule init tools/build 176 | git submodule init tools/boost_install 177 | git submodule update 178 | cmd /c bootstrap 179 | b2 -d0 headers 180 | 181 | - name: Run tests 182 | shell: cmd 183 | run: | 184 | cd ../boost 185 | b2 -j3 libs/align/test toolset=${{matrix.toolset}} cxxstd=${{matrix.standard}} address-model=${{matrix.target}} variant=debug,release 186 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Glen Joseph Fernandes 2 | # (glenjofe@gmail.com) 3 | # 4 | # Distributed under the Boost Software License, Version 1.0. 5 | # (http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | language: cpp 8 | 9 | sudo: false 10 | 11 | dist: xenial 12 | 13 | branches: 14 | only: 15 | - master 16 | - develop 17 | 18 | env: 19 | matrix: 20 | - EMPTY=true 21 | 22 | matrix: 23 | 24 | exclude: 25 | - env: EMPTY=true 26 | 27 | include: 28 | - os: linux 29 | compiler: g++ 30 | env: TOOLSET=gcc COMPILER=g++ STANDARD=03,11 31 | 32 | - os: linux 33 | compiler: g++-4.4 34 | env: TOOLSET=gcc COMPILER=g++-4.4 STANDARD=98,0x 35 | addons: 36 | apt: 37 | packages: 38 | - g++-4.4 39 | sources: 40 | - ubuntu-toolchain-r-test 41 | 42 | - os: linux 43 | compiler: g++-4.6 44 | env: TOOLSET=gcc COMPILER=g++-4.6 STANDARD=03,0x 45 | addons: 46 | apt: 47 | packages: 48 | - g++-4.6 49 | sources: 50 | - ubuntu-toolchain-r-test 51 | 52 | - os: linux 53 | compiler: g++-4.7 54 | env: TOOLSET=gcc COMPILER=g++-4.7 STANDARD=03,11 55 | addons: 56 | apt: 57 | packages: 58 | - g++-4.7 59 | sources: 60 | - ubuntu-toolchain-r-test 61 | 62 | - os: linux 63 | compiler: g++-4.8 64 | env: TOOLSET=gcc COMPILER=g++-4.8 STANDARD=03,11 65 | addons: 66 | apt: 67 | packages: 68 | - g++-4.8 69 | sources: 70 | - ubuntu-toolchain-r-test 71 | 72 | - os: linux 73 | compiler: g++-4.9 74 | env: TOOLSET=gcc COMPILER=g++-4.9 STANDARD=03,11 75 | addons: 76 | apt: 77 | packages: 78 | - g++-4.9 79 | sources: 80 | - ubuntu-toolchain-r-test 81 | 82 | - os: linux 83 | compiler: g++-5 84 | env: TOOLSET=gcc COMPILER=g++-5 STANDARD=03,11,14,1z 85 | addons: 86 | apt: 87 | packages: 88 | - g++-5 89 | sources: 90 | - ubuntu-toolchain-r-test 91 | 92 | - os: linux 93 | compiler: g++-6 94 | env: TOOLSET=gcc COMPILER=g++-6 STANDARD=03,11,14,1z 95 | addons: 96 | apt: 97 | packages: 98 | - g++-6 99 | sources: 100 | - ubuntu-toolchain-r-test 101 | 102 | - os: linux 103 | compiler: g++-7 104 | env: TOOLSET=gcc COMPILER=g++-7 STANDARD=03,11,14,17 105 | addons: 106 | apt: 107 | packages: 108 | - g++-7 109 | sources: 110 | - ubuntu-toolchain-r-test 111 | 112 | - os: linux 113 | compiler: g++-8 114 | env: TOOLSET=gcc COMPILER=g++-8 STANDARD=03,11,14,17,2a 115 | addons: 116 | apt: 117 | packages: 118 | - g++-8 119 | sources: 120 | - ubuntu-toolchain-r-test 121 | 122 | - os: linux 123 | compiler: g++-9 124 | env: TOOLSET=gcc COMPILER=g++-9 STANDARD=03,11,14,17,2a 125 | addons: 126 | apt: 127 | packages: 128 | - g++-9 129 | sources: 130 | - ubuntu-toolchain-r-test 131 | 132 | - os: linux 133 | compiler: clang++ 134 | env: TOOLSET=clang COMPILER=clang++ STANDARD=03,11 135 | 136 | - os: linux 137 | dist: trusty 138 | compiler: /usr/bin/clang++ 139 | env: TOOLSET=clang COMPILER=/usr/bin/clang++ STANDARD=03,11 140 | addons: 141 | apt: 142 | packages: 143 | - clang-3.3 144 | 145 | - os: linux 146 | dist: trusty 147 | compiler: /usr/bin/clang++ 148 | env: TOOLSET=clang COMPILER=/usr/bin/clang++ STANDARD=03,11 149 | addons: 150 | apt: 151 | packages: 152 | - clang-3.4 153 | 154 | - os: linux 155 | dist: trusty 156 | compiler: clang++-3.5 157 | env: TOOLSET=clang COMPILER=clang++-3.5 STANDARD=03,11,14,1z 158 | addons: 159 | apt: 160 | packages: 161 | - clang-3.5 162 | - libstdc++-4.9-dev 163 | sources: 164 | - ubuntu-toolchain-r-test 165 | - llvm-toolchain-precise-3.5 166 | 167 | - os: linux 168 | compiler: clang++-3.6 169 | env: TOOLSET=clang COMPILER=clang++-3.6 STANDARD=03,11,14,1z 170 | addons: 171 | apt: 172 | packages: 173 | - clang-3.6 174 | sources: 175 | - ubuntu-toolchain-r-test 176 | 177 | - os: linux 178 | compiler: clang++-3.7 179 | env: TOOLSET=clang COMPILER=clang++-3.7 STANDARD=03,11,14,1z 180 | addons: 181 | apt: 182 | packages: 183 | - clang-3.7 184 | sources: 185 | - ubuntu-toolchain-r-test 186 | 187 | - os: linux 188 | compiler: clang++-3.8 189 | env: TOOLSET=clang COMPILER=clang++-3.8 STANDARD=03,11,14,1z 190 | addons: 191 | apt: 192 | packages: 193 | - clang-3.8 194 | - libstdc++-4.9-dev 195 | sources: 196 | - ubuntu-toolchain-r-test 197 | 198 | - os: linux 199 | compiler: clang++-3.9 200 | env: TOOLSET=clang COMPILER=clang++-3.9 STANDARD=03,11,14,1z 201 | addons: 202 | apt: 203 | packages: 204 | - clang-3.9 205 | - libstdc++-4.9-dev 206 | sources: 207 | - ubuntu-toolchain-r-test 208 | 209 | - os: linux 210 | compiler: clang++-4.0 211 | env: TOOLSET=clang COMPILER=clang++-4.0 STANDARD=03,11,14,1z 212 | addons: 213 | apt: 214 | packages: 215 | - clang-4.0 216 | sources: 217 | - ubuntu-toolchain-r-test 218 | 219 | - os: linux 220 | compiler: clang++-5.0 221 | env: TOOLSET=clang COMPILER=clang++-5.0 STANDARD=03,11,14,1z 222 | addons: 223 | apt: 224 | packages: 225 | - clang-5.0 226 | sources: 227 | - ubuntu-toolchain-r-test 228 | 229 | - os: linux 230 | compiler: clang++-6.0 231 | env: TOOLSET=clang COMPILER=clang++-6.0 STANDARD=03,11,14,17,2a 232 | addons: 233 | apt: 234 | packages: 235 | - clang-6.0 236 | sources: 237 | - ubuntu-toolchain-r-test 238 | 239 | - os: linux 240 | compiler: clang++-7 241 | env: TOOLSET=clang COMPILER=clang++-7 STANDARD=03,11,14,17,2a 242 | addons: 243 | apt: 244 | packages: 245 | - clang-7 246 | sources: 247 | - ubuntu-toolchain-r-test 248 | - llvm-toolchain-xenial-7 249 | 250 | - os: linux 251 | compiler: clang++-8 252 | env: TOOLSET=clang COMPILER=clang++-8 STANDARD=03,11,14,17,2a 253 | addons: 254 | apt: 255 | packages: 256 | - clang-8 257 | sources: 258 | - ubuntu-toolchain-r-test 259 | - llvm-toolchain-xenial-8 260 | 261 | - os: linux 262 | dist: trusty 263 | compiler: clang++-libc++ 264 | env: TOOLSET=clang COMPILER=clang++-libc++ STANDARD=03,11,14,1z 265 | addons: 266 | apt: 267 | packages: 268 | - libc++-dev 269 | 270 | - os: osx 271 | compiler: clang++ 272 | env: TOOLSET=clang COMPILER=clang++ STANDARD=03,11,14,1z 273 | 274 | install: 275 | - cd .. 276 | - git clone -b $TRAVIS_BRANCH https://github.com/boostorg/boost 277 | - cd boost 278 | - git submodule init libs/assert 279 | - git submodule init libs/config 280 | - git submodule init libs/core 281 | - git submodule init libs/static_assert 282 | - git submodule init libs/headers 283 | - git submodule init tools/build 284 | - git submodule init tools/boost_install 285 | - git submodule update 286 | - cp -R $TRAVIS_BUILD_DIR/* libs/align 287 | - ./bootstrap.sh 288 | - ./b2 headers 289 | 290 | script: 291 | - |- 292 | echo "using $TOOLSET : : $COMPILER ;" > ~/user-config.jam 293 | - ./b2 libs/align/test toolset=$TOOLSET cxxstd=$STANDARD 294 | 295 | notifications: 296 | email: 297 | on_success: always 298 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Glen Joseph Fernandes 2 | # (glenjofe@gmail.com) 3 | # 4 | # Distributed under the Boost Software License, Version 1.0. 5 | # (http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | cmake_minimum_required(VERSION 3.5...3.20) 8 | 9 | project(boost_align VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX) 10 | 11 | add_library(boost_align INTERFACE) 12 | 13 | add_library(Boost::align ALIAS boost_align) 14 | 15 | target_include_directories(boost_align INTERFACE include) 16 | 17 | target_link_libraries(boost_align INTERFACE 18 | Boost::assert 19 | Boost::config 20 | Boost::core 21 | Boost::static_assert 22 | ) 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Boost.Align 2 | 3 | The Boost Align C++ library provides functions, classes, templates, traits, 4 | and macros, for the control, inspection, and diagnostic of memory alignment. 5 | 6 | ### License 7 | 8 | Distributed under the 9 | [Boost Software License, Version 1.0](http://www.boost.org/LICENSE_1_0.txt). 10 | -------------------------------------------------------------------------------- /doc/Jamfile: -------------------------------------------------------------------------------- 1 | # Copyright 2014 Glen Joseph Fernandes 2 | # (glenjofe@gmail.com) 3 | # 4 | # Distributed under the Boost Software License, Version 1.0. 5 | # (http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | import quickbook ; 8 | 9 | xml align : align.qbk ; 10 | 11 | boostbook standalone : align : boost.root=../../../.. ; 12 | 13 | alias boostdoc : align : : : ; 14 | 15 | explicit boostdoc ; 16 | 17 | alias boostrelease ; 18 | 19 | explicit boostrelease ; 20 | -------------------------------------------------------------------------------- /doc/align.qbk: -------------------------------------------------------------------------------- 1 | [/ 2 | Copyright 2014-2017 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | ] 8 | 9 | [library Boost.Align 10 | [quickbook 1.6] 11 | [id align] 12 | [copyright 2014-2017 Glen Joseph Fernandes] 13 | [authors [Fernandes, Glen]] 14 | [dirname align] 15 | [license Distributed under the Boost Software License, Version 1.0.]] 16 | 17 | [section Introduction] 18 | 19 | The Boost Align C++ library provides functions, classes, templates, traits, 20 | and macros, for the control, inspection, and diagnostic of memory alignment. 21 | 22 | [endsect] 23 | 24 | [section Rationale] 25 | 26 | [heading Dynamic allocation] 27 | 28 | C++11 added the ability to specify increased alignment (over-alignment) for 29 | class types. Unfortunately, `::operator new` allocation functions, `new` 30 | expressions and the Default Allocator, `std::allocator`, do not support 31 | dynamic memory allocation of over-aligned data. This library provides 32 | allocation functions and allocators that respect the alignment requirements of 33 | a type and so are suitable for allocating memory for over-aligned types. 34 | 35 | [variablelist 36 | [[`aligned_alloc(alignment, size)`] 37 | [Replaces `::operator new(size, std::nothrow)`]] 38 | [[`aligned_free(pointer)`] 39 | [Replaces `::operator delete(pointer, std::nothrow)`]] 40 | [[`aligned_allocator`][Replaces `std::allocator`]] 41 | [[`aligned_allocator_adaptor`][Replaces use of Allocator]] 42 | [[`aligned_delete`][Replaces `std::default_delete`]]] 43 | 44 | [heading Pointer alignment] 45 | 46 | C++11 provided `std::align` in the standard library to align a pointer value. 47 | Unfortunately some C++ standard library implementations do not support it yet 48 | (libstdc++ as far as gcc 4.8.0) and other standard library implementations 49 | implement it incorrectly (dinkumware in msvc11.0). This library provides it 50 | for those implementations and also for C++03 compilers where it is equally 51 | useful. 52 | 53 | [heading Querying alignment] 54 | 55 | C++11 provided the `std::alignment_of` trait in the standard library to query 56 | the alignment requirement of a type. Unfortunately some C++ standard library 57 | vendors do not implement it in an entirely standard conforming manner, such as 58 | for array types (libc++ as far as clang 3.4). Other vendor implementations 59 | report incorrect values for certain types, such as pointer to members (msvc 60 | 14.0). This library provides it for those implementations and also for C++03 61 | compilers where it is equally useful. 62 | 63 | [heading Hinting alignment] 64 | 65 | Allocating aligned memory is sometimes not enough to ensure that optimal code 66 | is generated. Developers use specific compiler intrinsics to notify the 67 | compiler of a given alignment property of a memory block. This library 68 | provides a macro, `BOOST_ALIGN_ASSUME_ALIGNED`, to abstract that functionality 69 | for compilers with the appropriate intrinsics. 70 | 71 | [heading Checking alignment] 72 | 73 | This library provides a function, `is_aligned` to test the alignment of a 74 | pointer value. It is generally useful in assertions to validate that memory is 75 | correctly aligned. 76 | 77 | [endsect] 78 | 79 | [section Examples] 80 | 81 | [heading Aligned allocation] 82 | 83 | To dynamically allocate storage with desired alignment, you can use the 84 | `aligned_alloc` function: 85 | 86 | [ordered_list 87 | [`void* storage = boost::alignment::aligned_alloc(alignment, size);`]] 88 | 89 | To deallocate storage allocated with the `aligned_alloc` function, use 90 | the `aligned_free` function: 91 | 92 | [ordered_list [`boost::alignment::aligned_free(storage);`]] 93 | 94 | [heading Aligned allocator] 95 | 96 | For C++ allocator aware code, you can use the `aligned_allocator` class 97 | template for an allocator that respects over-alignment: 98 | 99 | [ordered_list 100 | [`std::vector > vector;`]] 102 | 103 | This template allows specifying minimum alignment for all dynamic allocations: 104 | 105 | [ordered_list 106 | [`std::vector > vector;`]] 108 | 109 | [heading Aligned allocator adaptor] 110 | 111 | To turn an allocator into an allocator that respects over-alignment, you can 112 | use the `aligned_allocator_adaptor` class template: 113 | 114 | [ordered_list 115 | [`boost::alignment::aligned_allocator_adaptor second(first);`]] 116 | 117 | This template allows specifying minimum alignment for all dynamic 118 | allocations: 119 | 120 | [ordered_list 121 | [`boost::alignment::aligned_allocator_adaptor second(first);`]] 122 | 123 | [heading Aligned deleter] 124 | 125 | For a deleter that can be paired with `aligned_alloc`, you can use the 126 | `aligned_delete` class: 127 | 128 | [ordered_list 129 | [`std::unique_ptr pointer;`]] 130 | 131 | [heading Pointer alignment] 132 | 133 | To advance a pointer to the next address with the desired alignment: 134 | 135 | [ordered_list 136 | [`void* pointer = storage;`] 137 | [`std::size_t space = size;`] 138 | [`void* result = boost::alignment::align(64, sizeof(double), pointer, 139 | space);`]] 140 | 141 | [heading Querying alignment] 142 | 143 | To obtain the alignment of a given type at compie time, you can use: 144 | 145 | [ordered_list [`boost::alignment::alignment_of::value`]] 146 | 147 | If your compiler supports C++14 variable templates, you can also use: 148 | 149 | [ordered_list [`boost::alignment::alignment_of_v`]] 150 | 151 | [heading Hinting alignment] 152 | 153 | To inform the compiler about the alignment of a pointer, you can use: 154 | 155 | [ordered_list [`BOOST_ALIGN_ASSUME_ALIGNED(pointer, 64)`]] 156 | 157 | [heading Checking alignment] 158 | 159 | To check alignment of a pointer you can use the `is_aligned` function: 160 | 161 | [ordered_list [`assert(boost::alignment::is_aligned(pointer, 64));`]] 162 | 163 | [endsect] 164 | 165 | [section Reference] 166 | 167 | [section Functions] 168 | 169 | [section align] 170 | 171 | [variablelist 172 | [[`void* align(std::size_t alignment, std::size_t size, void*& ptr, 173 | std::size_t& space);`] 174 | [[variablelist 175 | [[Header][`#include `]] 176 | [[Effects] 177 | [If it is possible to fit `size` bytes of storage aligned by `alignment` into 178 | the buffer pointed to by `ptr` with length `space`, the function updates `ptr` 179 | to point to the first possible address of such storage and decreases `space` by 180 | the number of bytes used for alignment. Otherwise, the function does nothing.]] 181 | [[Requires] 182 | [[itemized_list 183 | [`alignment` shall be a power of two] 184 | [`ptr` shall point to contiguous storage of at least `space` bytes]]]] 185 | [[Returns] 186 | [A null pointer if the requested aligned buffer would not fit into the 187 | available space, otherwise the adjusted value of `ptr`.]] 188 | [[Note] 189 | [The function updates its `ptr` and `space` arguments so that it can be called 190 | repeatedly with possibly different `alignment` and `size`arguments for the same 191 | buffer.]]]]]] 192 | 193 | [endsect] 194 | 195 | [section align_up] 196 | 197 | [variablelist 198 | [[`template constexpr T align_up(T value, std::size_t alignment) 199 | noexcept;`] 200 | [[variablelist 201 | [[Header][`#include `]] 202 | [[Constraints][`T` is not a pointer type]] 203 | [[Requires][`alignment` shall be a power of two]] 204 | [[Returns][A value at or after `value` that is a multiple of `alignment`.]]]]]] 205 | 206 | [endsect] 207 | 208 | [section align_down] 209 | 210 | [variablelist 211 | [[`template constexpr T align_down(T value, std::size_t alignment) 212 | noexcept;`] 213 | [[variablelist 214 | [[Header][`#include `]] 215 | [[Constraints][`T` is not a pointer type]] 216 | [[Requires][`alignment` shall be a power of two]] 217 | [[Returns] 218 | [A value at or before `value` that is a multiple of `alignment`.]]]]]] 219 | 220 | [endsect] 221 | 222 | [section aligned_alloc] 223 | 224 | [variablelist 225 | [[`void* aligned_alloc(std::size_t alignment, std::size_t size);`] 226 | [[variablelist 227 | [[Header][`#include `]] 228 | [[Effects] 229 | [Allocates space for an object whose alignment is specified by `alignment`, 230 | whose size is specified by `size`, and whose value is indeterminate.]] 231 | [[Requires][`alignment` shall be a power of two.]] 232 | [[Returns][A null pointer or a pointer to the allocated space.]] 233 | [[Note] 234 | [On certain platforms, the space allocated may be slightly larger than 235 | `size` bytes, to allow for alignment.]]]]]] 236 | 237 | [endsect] 238 | 239 | [section aligned_free] 240 | 241 | [variablelist 242 | [[`void aligned_free(void* ptr);`] 243 | [[variablelist 244 | [[Header][`#include `]] 245 | [[Effects] 246 | [Causes the space pointed to by `ptr` to be deallocated, that is, made 247 | available for further allocation. If `ptr` is a null pointer, no action occurs. 248 | Otherwise, if the argument does not match a pointer earlier returned by the 249 | `aligned_alloc()` function, or if the space has been deallocated by a call to 250 | `aligned_free()`, the behavior is undefined.]] 251 | [[Requires] 252 | [`ptr` is a null pointer or a pointer earlier returned by the `aligned_alloc()` 253 | function that has not been deallocated by a call to `aligned_free()`.]] 254 | [[Returns][The `aligned_free()` function returns no value.]]]]]] 255 | 256 | [endsect] 257 | 258 | [section is_aligned] 259 | 260 | [variablelist 261 | [[`bool is_aligned(const volatile void* ptr, std::size_t alignment) noexcept;`] 262 | [[variablelist 263 | [[Header][`#include `]] 264 | [[Requires][`alignment` shall be a power of two.]] 265 | [[Returns] 266 | [`true` if `ptr` is aligned on the boundary specified by `alignment`, otherwise 267 | `false`.]]]]] 268 | [[`template constexpr bool is_aligned(T value, std::size_t alignment) 269 | noexcept;`] 270 | [[variablelist 271 | [[Header][`#include `]] 272 | [[Constraints][`T` is not a pointer type]] 273 | [[Requires][`alignment` shall be a power of two.]] 274 | [[Returns] 275 | [`true` if the value of `value` is aligned on the boundary specified by 276 | `alignment`, otherwise `false`.]]]]]] 277 | 278 | [endsect] 279 | 280 | [endsect] 281 | 282 | [section Classes] 283 | 284 | [section aligned_allocator] 285 | 286 | [variablelist 287 | [[`template class aligned_allocator;`] 288 | [[variablelist 289 | [[Header][`#include `]] 290 | [[Note] 291 | [Using the aligned allocator with a minimum Alignment value is generally only 292 | useful with containers that are not node-based such as `vector`. With 293 | node-based containers, such as `list`, the node object would have the minimum 294 | alignment instead of the value type object.]]]]]] 295 | 296 | [heading Member types] 297 | 298 | [ordered_list 299 | [`typedef T value_type;`] 300 | [`typedef T* pointer;`] 301 | [`typedef const T* const_pointer;`] 302 | [`typedef void* void_pointer;`] 303 | [`typedef const void* const_void_pointer;`] 304 | [`typedef std::add_lvalue_reference_t reference;`] 305 | [`typedef std::add_lvalue_reference_t const_reference;`] 306 | [`typedef std::size_t size_type;`] 307 | [`typedef std::ptrdiff_t difference_type;`] 308 | [`typedef std::true_type propagate_on_container_move_assignment;`] 309 | [`typedef std::true_type is_always_equal;`] 310 | [`template struct rebind { typedef aligned_allocator 311 | other; };`]] 312 | 313 | [heading Constructors] 314 | 315 | [variablelist 316 | [[`aligned_allocator() = default;`] 317 | [[variablelist [[Effects][Constructs the allocator.]]]]] 318 | [[`template aligned_allocator(const aligned_allocator&) 319 | noexcept;`] 320 | [[variablelist [[Effects][Constructs the allocator.]]]]]] 321 | 322 | [heading Member functions] 323 | 324 | Except for the destructor, member functions of the aligned allocator shall not 325 | introduce data races as a result of concurrent calls to those member functions 326 | from different threads. Calls to these functions that allocate or deallocate a 327 | particular unit of storage shall occur in a single total order, and each such 328 | deallocation call shall happen before the next allocation (if any) in this 329 | order. 330 | 331 | [variablelist 332 | [[`pointer allocate(size_type size, const_void_pointer = 0);`] 333 | [[variablelist 334 | [[Returns] 335 | [A pointer to the initial element of an array of storage of size 336 | `n * sizeof(T)`, aligned on the maximum of the minimum alignment specified and 337 | the alignment of objects of type `T`.]] 338 | [[Remark] 339 | [The storage is obtained by calling `aligned_alloc(std::size_t, 340 | std::size_t)`.]] 341 | [[Throws][`std::bad_alloc` if the storage cannot be obtained.]]]]] 342 | [[`void deallocate(pointer ptr, size_type);`] 343 | [[variablelist 344 | [[Requires] 345 | [`ptr` shall be a pointer value obtained from `allocate()`.]] 346 | [[Effects][Deallocates the storage referenced by `ptr`.]] 347 | [[Remark][Uses `aligned_free(void*)`.]]]]] 348 | [[`size_type max_size() const noexcept;`] 349 | [[variablelist 350 | [[Returns] 351 | [The largest value `N` for which the call `allocate(N)` might succeed.]]]]] 352 | [[`template void construct(U* ptr, Args&&... args);`] 353 | [[variablelist 354 | [[Effects][`::new((void*)ptr) U(std::forward(args)...)`.]]]]] 355 | [[`template void destroy(U* ptr);`] 356 | [[variablelist [[Effects][`ptr->~U()`.]]]]]] 357 | 358 | [heading Global operators] 359 | 360 | [variablelist 361 | [[`template bool operator==(const 362 | aligned_allocator&, const aligned_allocator&) 363 | noexcept;`] 364 | [[variablelist [[Returns][`true`]]]]] 365 | [[`template bool operator!=(const 366 | aligned_allocator&, const aligned_allocator&) 367 | noexcept;`] 368 | [[variablelist [[Returns][`false`]]]]]] 369 | 370 | [endsect] 371 | 372 | [section aligned_allocator_adaptor] 373 | 374 | [variablelist 375 | [[`template class 376 | aligned_allocator_adaptor;`] 377 | [[variablelist 378 | [[Header][`#include `]] 379 | [[Note] 380 | [This adaptor can be used with a C++11 Allocator whose pointer type is a smart 381 | pointer but the adaptor can choose to expose only raw pointer types.]]]]]] 382 | 383 | [heading Member types] 384 | 385 | [ordered_list 386 | [`typedef typename Allocator::value_type value_type;`] 387 | [`typedef value_type* pointer;`] 388 | [`typedef const value_type* const_pointer;`] 389 | [`typedef void* void_pointer;`] 390 | [`typedef const void* const_void_pointer;`] 391 | [`typedef std::size_t size_type;`] 392 | [`typedef std::ptrdiff_t difference_type;`] 393 | [`template struct rebind { typedef aligned_allocator_adaptor::template rebind_alloc, Alignment> 395 | other; };`]] 396 | 397 | [heading Constructors] 398 | 399 | [variablelist 400 | [[`aligned_allocator_adaptor() = default;`] 401 | [[variablelist [[Effects][Value-initializes the `Allocator` base class.]]]]] 402 | [[`template aligned_allocator_adaptor(A&& alloc) noexcept;`] 403 | [[variablelist [[Requires][`Allocator` shall be constructible from `A`.]] 404 | [[Effects] 405 | [Initializes the `Allocator` base class with `std::forward(alloc)`.]]]]] 406 | [[`template aligned_allocator_adaptor(const 407 | aligned_allocator_adaptor& other) noexcept;`] 408 | [[variablelist 409 | [[Requires][`Allocator` shall be constructible from `A`.]] 410 | [[Effects][Initializes the `Allocator` base class with `other.base()`.]]]]]] 411 | 412 | [heading Member functions] 413 | 414 | [variablelist 415 | [[`Allocator& base() noexcept;`] 416 | [[variablelist [[Returns][`static_cast(*this)`]]]]] 417 | [[`const Allocator& base() const noexcept;`] 418 | [[variablelist [[Returns][`static_cast(*this)`]]]]] 419 | [[`pointer allocate(size_type size);`] 420 | [[variablelist 421 | [[Returns] 422 | [A pointer to the initial element of an array of storage of size 423 | `n * sizeof(value_type)`, aligned on the maximum of the minimum alignment 424 | specified and the alignment of objects of type `value_type`.]] 425 | [[Remark] 426 | [The storage is obtained by calling `A2::allocate()` on an object `a2`, where 427 | `a2` of type `A2` is a rebound copy of `base()` where its `value_type` is 428 | implementation defined.]] 429 | [[Throws] 430 | [Throws an exception thrown from `A2::allocate()` if the storage cannot be 431 | obtained.]]]]] 432 | [[`pointer allocate(size_type size, const_void_pointer hint);`] 433 | [[variablelist 434 | [[Requires] 435 | [`hint` is a value obtained by calling `allocate()` on any equivalent allocator 436 | object, or else a null pointer.]] 437 | [[Returns] 438 | [A pointer to the initial element of an array of storage of size 439 | `n * sizeof(value_type)`, aligned on the maximum of the minimum alignment 440 | specified and the alignment of objects of type `value_type`.]] 441 | [[Remark] 442 | [The storage is obtained by calling `A2::allocate()` on an object `a2`, where 443 | `a2` of type `A2` is a rebound copy of `base()` where its `value_type` is an 444 | implementation defined.]] 445 | [[Throws] 446 | [Throws an exception thrown from `A2::allocate()` if the storage cannot be 447 | obtained.]]]]] 448 | [[`void deallocate(pointer ptr, size_type size);`] 449 | [[variablelist 450 | [[Requires] 451 | [[itemized_list 452 | [`ptr` shall be a pointer value obtained from `allocate()`] 453 | [`size` shall equal the value passed as the first argument to the invocation of 454 | `allocate()` which returned `ptr`.]]]] 455 | [[Effects][Deallocates the storage referenced by `ptr`.]] 456 | [[Note] 457 | [Uses `A2::deallocate()` on an object `a2`, where `a2` of type `A2` is a 458 | rebound copy of `base()` where its `value_type` is implementation 459 | defined.]]]]]] 460 | 461 | [heading Global operators] 462 | 463 | [variablelist 464 | [[`template bool operator==(const 465 | aligned_allocator_adaptor& a1, const 466 | aligned_allocator_adaptor& a2) noexcept;`] 467 | [[variablelist [[Returns][`a1.base() == a2.base()`]]]]] 468 | [[`template bool operator!=(const 469 | aligned_allocator_adaptor& a1, const 470 | aligned_allocator_adaptor& a2) noexcept;`] 471 | [[variablelist [[Returns][`!(a1 == a2)`]]]]]] 472 | 473 | [endsect] 474 | 475 | [section aligned_delete] 476 | 477 | [variablelist 478 | [[`class aligned_delete;`] 479 | [[variablelist [[Header][`#include `]]]]]] 480 | 481 | [heading Member operators] 482 | 483 | [variablelist 484 | [[`template void operator()(T* ptr) noexcept(noexcept(ptr->~T()));`] 485 | [[variablelist 486 | [[Effects] 487 | [Calls `~T()` on `ptr` to destroy the object and then calls `aligned_free()` on 488 | `ptr` to free the allocated memory.]] 489 | [[Note][If `T` is an incomplete type, the program is ill-formed.]]]]]] 490 | 491 | [endsect] 492 | 493 | [endsect] 494 | 495 | [section Traits] 496 | 497 | [section alignment_of] 498 | 499 | [variablelist 500 | [[`template struct alignment_of;`] 501 | [[variablelist 502 | [[Header][`#include `]] 503 | [[Value] 504 | [The alignment requirement of the type `T` as an integral constant of type 505 | `std::size_t`. When `T` is a reference array type, the value shall be the 506 | alignment of the referenced type. When `T` is an array type, the value shall be 507 | the alignment of the element type.]] 508 | [[Requires] 509 | [`T` shall be a complete object type, or an array thereof, or a reference to 510 | one of those types.]]]]]] 511 | 512 | [endsect] 513 | 514 | [endsect] 515 | 516 | [section Macros] 517 | 518 | [section BOOST_ALIGN_ASSUME_ALIGNED] 519 | 520 | [variablelist 521 | [[`BOOST_ALIGN_ASSUME_ALIGNED(ptr, alignment)`] 522 | [[variablelist 523 | [[Header][`#include `]] 524 | [[Requires] 525 | [[itemized_list [`alignment` shall be a power of two] 526 | [`ptr` shall be mutable]]]] 527 | [[Effects] 528 | [`ptr` may be modified in an implementation specific way to inform the compiler 529 | of its alignment.]]]]]] 530 | 531 | [endsect] 532 | 533 | [endsect] 534 | 535 | [endsect] 536 | 537 | [section Vocabulary] 538 | 539 | [heading \[basic.align\]] 540 | 541 | Object types have /alignment requirements/ which place restrictions on the 542 | addresses at which an object of that type may be allocated. An /alignment/ is 543 | an implementation-defined integer value representing the number of bytes 544 | between successive addresses at which a given object can be allocated. An 545 | object type imposes an alignment requirement on every object of that type; 546 | stricter alignment can be requested using the alignment specifier. 547 | 548 | A /fundamental alignment/ is represented by an alignment less than or equal to 549 | the greatest alignment supported by the implementation in all contexts, which 550 | is equal to `alignof(std::max_align_t)`. The alignment required for a type 551 | might be different when it is used as the type of a complete object and when 552 | it is used as the type of a subobject. 553 | \[['Example:] 554 | [ordered_list 555 | [`struct B { long double d; };`] 556 | [`struct D : virtual B { char c; };`]] 557 | When `D` is the type of a complete object, it will have a subobject of type 558 | `B`, so it must be aligned appropriately for a `long double`. If `D` appears 559 | as a subobject of another object that also has `B` as a virtual base class, 560 | the `B` subobject might be part of a different subobject, reducing the 561 | alignment requirements on the `D` subobject. \u2014['end example]\] The result 562 | of the `alignof` operator reflects the alignment requirement of the type in 563 | the complete-object case. 564 | 565 | An /extended alignment/ is represented by an alignment greater than 566 | `alignof(std::max_align_t)`. It is implementation-defined whether any extended 567 | alignments are supported and the contexts in which they are supported. A type 568 | having an extended alignment requirement is an /over-aligned type/. \[['Note:] 569 | Every over-aligned type is or contains a class type to which extended 570 | alignment applies (possibly through a non-static data member). \u2014['end 571 | note]\] 572 | 573 | Alignments are represented as values of the type `std::size_t`. Valid 574 | alignments include only those values returned by an `alignof` expression for 575 | the fundamental types plus an additional implementation-defined set of values, 576 | which may be empty. Every alignment value shall be a non-negative integral 577 | power of two. 578 | 579 | Alignments have an order from /weaker/ to /stronger/ or /stricter/ alignments. 580 | Stricter alignments have larger alignment values. An address that satisfies an 581 | alignment requirement also satisfies any weaker valid alignment requirement. 582 | 583 | The alignment requirement of a complete type can be queried using an `alignof` 584 | expression. Furthermore, the types `char`, `signed char`, and `unsigned char` 585 | shall have the weakest alignment requirement. \[['Note:] This enables the 586 | character types to be used as the underlying type for an aligned memory area. 587 | \u2014['end note]\] 588 | 589 | Comparing alignments is meaningful and provides the obvious results: 590 | 591 | * Two alignments are equal when their numeric values are equal. 592 | * Two alignments are different when their numeric values are not equal. 593 | * When an alignment is larger than another it represents a stricter 594 | alignment. 595 | 596 | \[['Note:] The runtime pointer alignment function can be used to obtain an 597 | aligned pointer within a buffer; the aligned-storage templates in the library 598 | can be used to obtain aligned storage. \u2014['end note]\] 599 | 600 | If a request for a specific extended alignment in a specific context is not 601 | supported by an implementation, the program is ill-formed. Additionally, a 602 | request for runtime allocation of dynamic storage for which the requested 603 | alignment cannot be honored shall be treated as an allocation failure. 604 | 605 | [endsect] 606 | 607 | [section Compatibility] 608 | 609 | This library has been tested with the following C++ implementations: 610 | 611 | [variablelist 612 | [[Compilers][gcc, clang, msvc, intel]] 613 | [[Libraries][libstdc++, libc++, dinkumware]] 614 | [[Systems][linux, windows, osx]] 615 | [[Platforms][x64, x86, arm]] 616 | [[Standards][c++98, c++03, c++11, c++14, c++17]]] 617 | 618 | [endsect] 619 | 620 | [section Acknowledgments] 621 | 622 | Thank you to everyone who reviewed the design, code, examples, tests, or 623 | documentation, including: 624 | 625 | * Peter Dimov 626 | * Andrey Semashev 627 | * Bjorn Reese 628 | * Steven Watanabe 629 | * Antony Polukhin 630 | * Lars Viklund 631 | * Michael Spencer 632 | * Paul A. Bristow 633 | 634 | Thank you to Ahmed Charles for serving as the review manager for the formal 635 | review of the library. 636 | 637 | [endsect] 638 | 639 | [section History] 640 | 641 | [variablelist 642 | [[Boost 1.61] 643 | [Functions for aligning up, down, and testing alignment of integral values.]] 644 | [[Boost 1.59] 645 | [Joel Falcou and Charly Chevalier contributed the alignment hint macro.]] 646 | [[Boost 1.56] 647 | [Glen Fernandes implemented and contributed the Align library to Boost.]]] 648 | 649 | [endsect] 650 | -------------------------------------------------------------------------------- /include/boost/align.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014-2015 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_HPP 9 | #define BOOST_ALIGN_HPP 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /include/boost/align/align.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014-2015 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_ALIGN_HPP 9 | #define BOOST_ALIGN_ALIGN_HPP 10 | 11 | #include 12 | 13 | #if !defined(BOOST_NO_CXX11_STD_ALIGN) && !defined(BOOST_LIBSTDCXX_VERSION) 14 | #include 15 | #else 16 | #include 17 | #endif 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /include/boost/align/align_down.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_ALIGN_DOWN_HPP 9 | #define BOOST_ALIGN_ALIGN_DOWN_HPP 10 | 11 | #include 12 | #include 13 | 14 | namespace boost { 15 | namespace alignment { 16 | 17 | template 18 | BOOST_CONSTEXPR inline typename detail::not_pointer::type 19 | align_down(T value, std::size_t alignment) BOOST_NOEXCEPT 20 | { 21 | return T(value & ~T(alignment - 1)); 22 | } 23 | 24 | } /* alignment */ 25 | } /* boost */ 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /include/boost/align/align_up.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_ALIGN_UP_HPP 9 | #define BOOST_ALIGN_ALIGN_UP_HPP 10 | 11 | #include 12 | #include 13 | 14 | namespace boost { 15 | namespace alignment { 16 | 17 | template 18 | BOOST_CONSTEXPR inline typename detail::not_pointer::type 19 | align_up(T value, std::size_t alignment) BOOST_NOEXCEPT 20 | { 21 | return T((value + (T(alignment) - 1)) & ~T(alignment - 1)); 22 | } 23 | 24 | } /* alignment */ 25 | } /* boost */ 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /include/boost/align/aligned_alloc.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014-2015 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_ALIGNED_ALLOC_HPP 9 | #define BOOST_ALIGN_ALIGNED_ALLOC_HPP 10 | 11 | #include 12 | 13 | #if defined(BOOST_HAS_UNISTD_H) 14 | #include 15 | #endif 16 | 17 | #if defined(__APPLE__) || defined(__APPLE_CC__) || defined(macintosh) 18 | #include 19 | #endif 20 | 21 | #if defined(BOOST_ALIGN_USE_ALIGN) 22 | #include 23 | #elif defined(BOOST_ALIGN_USE_NEW) 24 | #include 25 | #elif defined(_MSC_VER) && !defined(UNDER_CE) 26 | #include 27 | #elif defined(__MINGW32__) && (__MSVCRT_VERSION__ >= 0x0700) 28 | #include 29 | #elif defined(__MINGW32__) 30 | #include 31 | #elif MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 32 | #include 33 | #elif MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 34 | #include 35 | #elif defined(__ANDROID__) 36 | #include 37 | #elif defined(__SunOS_5_11) || defined(__SunOS_5_12) 38 | #include 39 | #elif defined(sun) || defined(__sun) 40 | #include 41 | #elif defined(_POSIX_VERSION) 42 | #include 43 | #else 44 | #include 45 | #endif 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /include/boost/align/aligned_allocator.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014-2015 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_ALIGNED_ALLOCATOR_HPP 9 | #define BOOST_ALIGN_ALIGNED_ALLOCATOR_HPP 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 23 | #include 24 | #endif 25 | 26 | namespace boost { 27 | namespace alignment { 28 | 29 | template 30 | class aligned_allocator { 31 | BOOST_STATIC_ASSERT(detail::is_alignment_constant::value); 32 | 33 | public: 34 | typedef T value_type; 35 | typedef T* pointer; 36 | typedef const T* const_pointer; 37 | typedef void* void_pointer; 38 | typedef const void* const_void_pointer; 39 | typedef typename detail::add_lvalue_reference::type reference; 40 | typedef typename detail::add_lvalue_reference::type const_reference; 42 | typedef std::size_t size_type; 43 | typedef std::ptrdiff_t difference_type; 44 | typedef detail::true_type propagate_on_container_move_assignment; 45 | typedef detail::true_type is_always_equal; 46 | 47 | template 48 | struct rebind { 49 | typedef aligned_allocator other; 50 | }; 51 | 52 | #if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) 53 | aligned_allocator() = default; 54 | #else 55 | aligned_allocator() BOOST_NOEXCEPT { } 56 | #endif 57 | 58 | template 59 | aligned_allocator(const aligned_allocator&) 60 | BOOST_NOEXCEPT { } 61 | 62 | pointer allocate(size_type size, const_void_pointer = 0) { 63 | enum { 64 | m = detail::max_size::value>::value 66 | }; 67 | if (size == 0) { 68 | return 0; 69 | } 70 | void* p = boost::alignment::aligned_alloc(m, sizeof(T) * size); 71 | if (!p) { 72 | detail::throw_exception(std::bad_alloc()); 73 | } 74 | return static_cast(p); 75 | } 76 | 77 | void deallocate(pointer ptr, size_type) { 78 | boost::alignment::aligned_free(ptr); 79 | } 80 | 81 | BOOST_CONSTEXPR size_type max_size() const BOOST_NOEXCEPT { 82 | return detail::max_objects::value; 83 | } 84 | 85 | #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 86 | #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) 87 | template 88 | void construct(U* ptr, Args&&... args) { 89 | ::new((void*)ptr) U(std::forward(args)...); 90 | } 91 | #else 92 | template 93 | void construct(U* ptr, V&& value) { 94 | ::new((void*)ptr) U(std::forward(value)); 95 | } 96 | #endif 97 | #else 98 | template 99 | void construct(U* ptr, const V& value) { 100 | ::new((void*)ptr) U(value); 101 | } 102 | 103 | template 104 | void construct(U* ptr, V& value) { 105 | ::new((void*)ptr) U(value); 106 | } 107 | #endif 108 | 109 | template 110 | void construct(U* ptr) { 111 | ::new((void*)ptr) U(); 112 | } 113 | 114 | template 115 | void destroy(U* ptr) { 116 | (void)ptr; 117 | ptr->~U(); 118 | } 119 | }; 120 | 121 | template 122 | inline bool 123 | operator==(const aligned_allocator&, 124 | const aligned_allocator&) BOOST_NOEXCEPT 125 | { 126 | return true; 127 | } 128 | 129 | template 130 | inline bool 131 | operator!=(const aligned_allocator&, 132 | const aligned_allocator&) BOOST_NOEXCEPT 133 | { 134 | return false; 135 | } 136 | 137 | } /* alignment */ 138 | } /* boost */ 139 | 140 | #endif 141 | -------------------------------------------------------------------------------- /include/boost/align/aligned_allocator_adaptor.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014-2016 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_ALIGNED_ALLOCATOR_ADAPTOR_HPP 9 | #define BOOST_ALIGN_ALIGNED_ALLOCATOR_ADAPTOR_HPP 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #if !defined(BOOST_NO_CXX11_ALLOCATOR) 22 | #include 23 | #endif 24 | 25 | #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 26 | #include 27 | #endif 28 | 29 | namespace boost { 30 | namespace alignment { 31 | 32 | template 33 | class aligned_allocator_adaptor 34 | : public Allocator { 35 | BOOST_STATIC_ASSERT(detail::is_alignment_constant::value); 36 | 37 | #if !defined(BOOST_NO_CXX11_ALLOCATOR) 38 | typedef std::allocator_traits traits; 39 | typedef typename traits::template rebind_alloc char_alloc; 40 | typedef typename traits::template rebind_traits char_traits; 41 | typedef typename char_traits::pointer char_ptr; 42 | #else 43 | typedef typename Allocator::template rebind::other char_alloc; 44 | typedef typename char_alloc::pointer char_ptr; 45 | #endif 46 | 47 | public: 48 | typedef typename Allocator::value_type value_type; 49 | typedef value_type* pointer; 50 | typedef const value_type* const_pointer; 51 | typedef void* void_pointer; 52 | typedef const void* const_void_pointer; 53 | typedef std::size_t size_type; 54 | typedef std::ptrdiff_t difference_type; 55 | 56 | private: 57 | template 58 | struct min_align { 59 | enum { 60 | value = detail::max_size::value>::value 62 | }; 63 | }; 64 | 65 | public: 66 | template 67 | struct rebind { 68 | #if !defined(BOOST_NO_CXX11_ALLOCATOR) 69 | typedef aligned_allocator_adaptor, Alignment> other; 71 | #else 72 | typedef aligned_allocator_adaptor::other, Alignment> other; 74 | #endif 75 | }; 76 | 77 | aligned_allocator_adaptor() 78 | : Allocator() { } 79 | 80 | #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 81 | template 82 | explicit aligned_allocator_adaptor(A&& alloc) BOOST_NOEXCEPT 83 | : Allocator(std::forward(alloc)) { } 84 | #else 85 | template 86 | explicit aligned_allocator_adaptor(const A& alloc) BOOST_NOEXCEPT 87 | : Allocator(alloc) { } 88 | #endif 89 | 90 | template 91 | aligned_allocator_adaptor(const aligned_allocator_adaptor& other) BOOST_NOEXCEPT 93 | : Allocator(other.base()) { } 94 | 95 | Allocator& base() BOOST_NOEXCEPT { 96 | return static_cast(*this); 97 | } 98 | 99 | const Allocator& base() const BOOST_NOEXCEPT { 100 | return static_cast(*this); 101 | } 102 | 103 | pointer allocate(size_type size) { 104 | enum { 105 | m = min_align::value 106 | }; 107 | std::size_t s = size * sizeof(value_type); 108 | std::size_t n = s + m - 1; 109 | char_alloc a(base()); 110 | char_ptr p = a.allocate(sizeof p + n); 111 | void* r = boost::to_address(p) + sizeof p; 112 | (void)boost::alignment::align(m, s, r, n); 113 | ::new(static_cast(static_cast(r) - 1)) char_ptr(p); 114 | return static_cast(r); 115 | } 116 | 117 | pointer allocate(size_type size, const_void_pointer hint) { 118 | enum { 119 | m = min_align::value 120 | }; 121 | std::size_t s = size * sizeof(value_type); 122 | std::size_t n = s + m - 1; 123 | char_ptr h = char_ptr(); 124 | if (hint) { 125 | h = *(static_cast(hint) - 1); 126 | } 127 | char_alloc a(base()); 128 | #if !defined(BOOST_NO_CXX11_ALLOCATOR) 129 | char_ptr p = char_traits::allocate(a, sizeof p + n, h); 130 | #else 131 | char_ptr p = a.allocate(sizeof p + n, h); 132 | #endif 133 | void* r = boost::to_address(p) + sizeof p; 134 | (void)boost::alignment::align(m, s, r, n); 135 | ::new(static_cast(static_cast(r) - 1)) char_ptr(p); 136 | return static_cast(r); 137 | } 138 | 139 | void deallocate(pointer ptr, size_type size) { 140 | enum { 141 | m = min_align::value 142 | }; 143 | char_ptr* p = reinterpret_cast(ptr) - 1; 144 | char_ptr r = *p; 145 | p->~char_ptr(); 146 | char_alloc a(base()); 147 | a.deallocate(r, sizeof r + size * sizeof(value_type) + m - 1); 148 | } 149 | }; 150 | 151 | template 152 | inline bool 153 | operator==(const aligned_allocator_adaptor& a, 154 | const aligned_allocator_adaptor& b) BOOST_NOEXCEPT 155 | { 156 | return a.base() == b.base(); 157 | } 158 | 159 | template 160 | inline bool 161 | operator!=(const aligned_allocator_adaptor& a, 162 | const aligned_allocator_adaptor& b) BOOST_NOEXCEPT 163 | { 164 | return !(a == b); 165 | } 166 | 167 | } /* alignment */ 168 | } /* boost */ 169 | 170 | #endif 171 | -------------------------------------------------------------------------------- /include/boost/align/aligned_allocator_adaptor_forward.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_ALIGNED_ALLOCATOR_ADAPTOR_FORWARD_HPP 9 | #define BOOST_ALIGN_ALIGNED_ALLOCATOR_ADAPTOR_FORWARD_HPP 10 | 11 | #include 12 | 13 | namespace boost { 14 | namespace alignment { 15 | 16 | template 17 | class aligned_allocator_adaptor; 18 | 19 | } /* alignment */ 20 | } /* boost */ 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /include/boost/align/aligned_allocator_forward.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_ALIGNED_ALLOCATOR_FORWARD_HPP 9 | #define BOOST_ALIGN_ALIGNED_ALLOCATOR_FORWARD_HPP 10 | 11 | #include 12 | 13 | namespace boost { 14 | namespace alignment { 15 | 16 | template 17 | class aligned_allocator; 18 | 19 | } /* alignment */ 20 | } /* boost */ 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /include/boost/align/aligned_delete.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014-2015 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_ALIGNED_DELETE_HPP 9 | #define BOOST_ALIGN_ALIGNED_DELETE_HPP 10 | 11 | #include 12 | #include 13 | 14 | namespace boost { 15 | namespace alignment { 16 | 17 | struct aligned_delete { 18 | template 19 | void operator()(T* ptr) const 20 | BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT_EXPR(ptr->~T())) { 21 | if (ptr) { 22 | ptr->~T(); 23 | boost::alignment::aligned_free(ptr); 24 | } 25 | } 26 | }; 27 | 28 | } /* alignment */ 29 | } /* boost */ 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /include/boost/align/aligned_delete_forward.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014-2015 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_ALIGNED_DELETE_FORWARD_HPP 9 | #define BOOST_ALIGN_ALIGNED_DELETE_FORWARD_HPP 10 | 11 | namespace boost { 12 | namespace alignment { 13 | 14 | struct aligned_delete; 15 | 16 | } /* alignment */ 17 | } /* boost */ 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /include/boost/align/alignment_of.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014-2016 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_ALIGNMENT_OF_HPP 9 | #define BOOST_ALIGN_ALIGNMENT_OF_HPP 10 | 11 | #include 12 | #include 13 | 14 | #if defined(_MSC_VER) && defined(__clang__) 15 | #include 16 | #elif defined(BOOST_MSVC) 17 | #include 18 | #elif defined(__GNUC__) && defined(__unix__) && !defined(__LP64__) 19 | #include 20 | #elif defined(BOOST_CLANG) && !defined(__x86_64__) 21 | #include 22 | #elif !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) 23 | #include 24 | #elif defined(__ghs__) && (__GHS_VERSION_NUMBER >= 600) 25 | #include 26 | #elif defined(BOOST_CODEGEARC) 27 | #include 28 | #elif defined(BOOST_CLANG) 29 | #include 30 | #elif __GNUC__ > 4 31 | #include 32 | #elif (__GNUC__ == 4) && (__GNUC_MINOR__ >= 3) 33 | #include 34 | #else 35 | #include 36 | #endif 37 | 38 | namespace boost { 39 | namespace alignment { 40 | 41 | template 42 | struct alignment_of 43 | : detail::alignment_of::type>::type { }; 45 | 46 | #if !defined(BOOST_NO_CXX14_VARIABLE_TEMPLATES) 47 | template 48 | constexpr std::size_t alignment_of_v = alignment_of::value; 49 | #endif 50 | 51 | } /* alignment */ 52 | } /* boost */ 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /include/boost/align/alignment_of_forward.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_ALIGNMENT_OF_FORWARD_HPP 9 | #define BOOST_ALIGN_ALIGNMENT_OF_FORWARD_HPP 10 | 11 | namespace boost { 12 | namespace alignment { 13 | 14 | template 15 | struct alignment_of; 16 | 17 | } /* alignment */ 18 | } /* boost */ 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /include/boost/align/assume_aligned.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 NumScale SAS 3 | Copyright 2015 LRI UMR 8623 CNRS/University Paris Sud XI 4 | 5 | Copyright 2015 Glen Joseph Fernandes 6 | (glenjofe@gmail.com) 7 | 8 | Distributed under the Boost Software License, Version 1.0. 9 | (http://www.boost.org/LICENSE_1_0.txt) 10 | */ 11 | #ifndef BOOST_ALIGN_ASSUME_ALIGNED_HPP 12 | #define BOOST_ALIGN_ASSUME_ALIGNED_HPP 13 | 14 | #include 15 | 16 | #if defined(BOOST_MSVC) 17 | #include 18 | #elif defined(BOOST_CLANG) && defined(__has_builtin) 19 | #include 20 | #elif BOOST_GCC_VERSION >= 40700 21 | #include 22 | #elif defined(__INTEL_COMPILER) 23 | #include 24 | #else 25 | #include 26 | #endif 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /include/boost/align/detail/add_reference.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_ADD_REFERENCE_HPP 9 | #define BOOST_ALIGN_DETAIL_ADD_REFERENCE_HPP 10 | 11 | #include 12 | 13 | #if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) 14 | #include 15 | #endif 16 | 17 | namespace boost { 18 | namespace alignment { 19 | namespace detail { 20 | 21 | #if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) 22 | using std::add_lvalue_reference; 23 | #else 24 | template 25 | struct add_lvalue_reference { 26 | typedef T& type; 27 | }; 28 | 29 | template<> 30 | struct add_lvalue_reference { 31 | typedef void type; 32 | }; 33 | 34 | template<> 35 | struct add_lvalue_reference { 36 | typedef const void type; 37 | }; 38 | #endif 39 | 40 | } /* detail */ 41 | } /* alignment */ 42 | } /* boost */ 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /include/boost/align/detail/align.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014-2020 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_ALIGN_HPP 9 | #define BOOST_ALIGN_DETAIL_ALIGN_HPP 10 | 11 | #include 12 | #include 13 | 14 | namespace boost { 15 | namespace alignment { 16 | 17 | inline void* 18 | align(std::size_t alignment, std::size_t size, void*& ptr, 19 | std::size_t& space) 20 | { 21 | BOOST_ASSERT(boost::alignment::detail::is_alignment(alignment)); 22 | if (size <= space) { 23 | char* p = reinterpret_cast(~(alignment - 1) & 24 | (reinterpret_cast(ptr) + alignment - 1)); 25 | std::size_t n = p - static_cast(ptr); 26 | if (n <= space - size) { 27 | ptr = p; 28 | space -= n; 29 | return p; 30 | } 31 | } 32 | return 0; 33 | } 34 | 35 | } /* alignment */ 36 | } /* boost */ 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /include/boost/align/detail/align_cxx11.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_ALIGN_CXX11_HPP 9 | #define BOOST_ALIGN_DETAIL_ALIGN_CXX11_HPP 10 | 11 | #include 12 | 13 | namespace boost { 14 | namespace alignment { 15 | 16 | using std::align; 17 | 18 | } /* alignment */ 19 | } /* boost */ 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /include/boost/align/detail/align_down.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_ALIGN_DOWN_HPP 9 | #define BOOST_ALIGN_DETAIL_ALIGN_DOWN_HPP 10 | 11 | #include 12 | #include 13 | 14 | namespace boost { 15 | namespace alignment { 16 | 17 | inline void* 18 | align_down(void* ptr, std::size_t alignment) BOOST_NOEXCEPT 19 | { 20 | BOOST_ASSERT(detail::is_alignment(alignment)); 21 | return reinterpret_cast(~(alignment - 1) & 22 | reinterpret_cast(ptr)); 23 | } 24 | 25 | } /* alignment */ 26 | } /* boost */ 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /include/boost/align/detail/align_up.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_ALIGN_UP_HPP 9 | #define BOOST_ALIGN_DETAIL_ALIGN_UP_HPP 10 | 11 | #include 12 | #include 13 | 14 | namespace boost { 15 | namespace alignment { 16 | 17 | inline void* 18 | align_up(void* ptr, std::size_t alignment) BOOST_NOEXCEPT 19 | { 20 | BOOST_ASSERT(detail::is_alignment(alignment)); 21 | return reinterpret_cast(~(alignment - 1) & 22 | (reinterpret_cast(ptr) + alignment - 1)); 23 | } 24 | 25 | } /* alignment */ 26 | } /* boost */ 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /include/boost/align/detail/aligned_alloc.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014-2015 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_HPP 9 | #define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_HPP 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace boost { 18 | namespace alignment { 19 | 20 | inline void* 21 | aligned_alloc(std::size_t alignment, std::size_t size) BOOST_NOEXCEPT 22 | { 23 | BOOST_ASSERT(detail::is_alignment(alignment)); 24 | enum { 25 | N = alignment_of::value 26 | }; 27 | if (alignment < N) { 28 | alignment = N; 29 | } 30 | std::size_t n = size + alignment - N; 31 | void* p = std::malloc(sizeof(void*) + n); 32 | if (p) { 33 | void* r = static_cast(p) + sizeof(void*); 34 | (void)boost::alignment::align(alignment, size, r, n); 35 | *(static_cast(r) - 1) = p; 36 | p = r; 37 | } 38 | return p; 39 | } 40 | 41 | inline void 42 | aligned_free(void* ptr) BOOST_NOEXCEPT 43 | { 44 | if (ptr) { 45 | std::free(*(static_cast(ptr) - 1)); 46 | } 47 | } 48 | 49 | } /* alignment */ 50 | } /* boost */ 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /include/boost/align/detail/aligned_alloc_android.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_ANDROID_HPP 9 | #define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_ANDROID_HPP 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace boost { 16 | namespace alignment { 17 | 18 | inline void* 19 | aligned_alloc(std::size_t alignment, std::size_t size) BOOST_NOEXCEPT 20 | { 21 | BOOST_ASSERT(detail::is_alignment(alignment)); 22 | return ::memalign(alignment, size); 23 | } 24 | 25 | inline void 26 | aligned_free(void* ptr) BOOST_NOEXCEPT 27 | { 28 | ::free(ptr); 29 | } 30 | 31 | } /* alignment */ 32 | } /* boost */ 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /include/boost/align/detail/aligned_alloc_macos.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_MACOS_HPP 9 | #define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_MACOS_HPP 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace boost { 16 | namespace alignment { 17 | 18 | inline void* 19 | aligned_alloc(std::size_t alignment, std::size_t size) BOOST_NOEXCEPT 20 | { 21 | BOOST_ASSERT(detail::is_alignment(alignment)); 22 | if (size == 0) { 23 | return 0; 24 | } 25 | if (alignment < sizeof(void*)) { 26 | alignment = sizeof(void*); 27 | } 28 | void* p; 29 | if (::posix_memalign(&p, alignment, size) != 0) { 30 | p = 0; 31 | } 32 | return p; 33 | } 34 | 35 | inline void 36 | aligned_free(void* ptr) BOOST_NOEXCEPT 37 | { 38 | ::free(ptr); 39 | } 40 | 41 | } /* alignment */ 42 | } /* boost */ 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /include/boost/align/detail/aligned_alloc_mingw.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_MINGW_HPP 9 | #define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_MINGW_HPP 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace boost { 16 | namespace alignment { 17 | 18 | inline void* 19 | aligned_alloc(std::size_t alignment, std::size_t size) BOOST_NOEXCEPT 20 | { 21 | BOOST_ASSERT(detail::is_alignment(alignment)); 22 | return ::__mingw_aligned_malloc(size, alignment); 23 | } 24 | 25 | inline void 26 | aligned_free(void* ptr) BOOST_NOEXCEPT 27 | { 28 | ::__mingw_aligned_free(ptr); 29 | } 30 | 31 | } /* alignment */ 32 | } /* boost */ 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /include/boost/align/detail/aligned_alloc_msvc.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_MSVC_HPP 9 | #define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_MSVC_HPP 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace boost { 16 | namespace alignment { 17 | 18 | inline void* 19 | aligned_alloc(std::size_t alignment, std::size_t size) BOOST_NOEXCEPT 20 | { 21 | BOOST_ASSERT(detail::is_alignment(alignment)); 22 | return ::_aligned_malloc(size, alignment); 23 | } 24 | 25 | inline void 26 | aligned_free(void* ptr) BOOST_NOEXCEPT 27 | { 28 | ::_aligned_free(ptr); 29 | } 30 | 31 | } /* alignment */ 32 | } /* boost */ 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /include/boost/align/detail/aligned_alloc_new.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014-2015 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_NEW_HPP 9 | #define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_NEW_HPP 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace boost { 18 | namespace alignment { 19 | 20 | inline void* 21 | aligned_alloc(std::size_t alignment, std::size_t size) BOOST_NOEXCEPT 22 | { 23 | BOOST_ASSERT(detail::is_alignment(alignment)); 24 | enum { 25 | N = alignment_of::value 26 | }; 27 | if (alignment < N) { 28 | alignment = N; 29 | } 30 | std::size_t n = size + alignment - N; 31 | void* p = ::operator new(sizeof(void*) + n, std::nothrow); 32 | if (p) { 33 | void* r = static_cast(p) + sizeof(void*); 34 | (void)boost::alignment::align(alignment, size, r, n); 35 | *(static_cast(r) - 1) = p; 36 | p = r; 37 | } 38 | return p; 39 | } 40 | 41 | inline void 42 | aligned_free(void* ptr) BOOST_NOEXCEPT 43 | { 44 | if (ptr) { 45 | ::operator delete(*(static_cast(ptr) - 1)); 46 | } 47 | } 48 | 49 | } /* alignment */ 50 | } /* boost */ 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /include/boost/align/detail/aligned_alloc_posix.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_POSIX_HPP 9 | #define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_POSIX_HPP 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace boost { 16 | namespace alignment { 17 | 18 | inline void* 19 | aligned_alloc(std::size_t alignment, std::size_t size) BOOST_NOEXCEPT 20 | { 21 | BOOST_ASSERT(detail::is_alignment(alignment)); 22 | if (alignment < sizeof(void*)) { 23 | alignment = sizeof(void*); 24 | } 25 | void* p; 26 | if (::posix_memalign(&p, alignment, size) != 0) { 27 | p = 0; 28 | } 29 | return p; 30 | } 31 | 32 | inline void 33 | aligned_free(void* ptr) BOOST_NOEXCEPT 34 | { 35 | ::free(ptr); 36 | } 37 | 38 | } /* alignment */ 39 | } /* boost */ 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /include/boost/align/detail/aligned_alloc_sunos.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_SUNOS_HPP 9 | #define BOOST_ALIGN_DETAIL_ALIGNED_ALLOC_SUNOS_HPP 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace boost { 16 | namespace alignment { 17 | 18 | inline void* 19 | aligned_alloc(std::size_t alignment, std::size_t size) BOOST_NOEXCEPT 20 | { 21 | BOOST_ASSERT(detail::is_alignment(alignment)); 22 | return ::memalign(alignment, size); 23 | } 24 | 25 | inline void 26 | aligned_free(void* ptr) BOOST_NOEXCEPT 27 | { 28 | ::free(ptr); 29 | } 30 | 31 | } /* alignment */ 32 | } /* boost */ 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /include/boost/align/detail/alignment_of.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014-2015 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_ALIGNMENT_OF_HPP 9 | #define BOOST_ALIGN_DETAIL_ALIGNMENT_OF_HPP 10 | 11 | #include 12 | 13 | namespace boost { 14 | namespace alignment { 15 | namespace detail { 16 | 17 | template 18 | struct offset_value { 19 | char value; 20 | T object; 21 | }; 22 | 23 | template 24 | struct alignment_of 25 | : min_size) - sizeof(T)> { }; 26 | 27 | } /* detail */ 28 | } /* alignment */ 29 | } /* boost */ 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /include/boost/align/detail/alignment_of_clang.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_ALIGNMENT_OF_CLANG_HPP 9 | #define BOOST_ALIGN_DETAIL_ALIGNMENT_OF_CLANG_HPP 10 | 11 | #include 12 | #include 13 | 14 | namespace boost { 15 | namespace alignment { 16 | namespace detail { 17 | 18 | template 19 | struct alignment_of 20 | : integral_constant { }; 21 | 22 | } /* detail */ 23 | } /* alignment */ 24 | } /* boost */ 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /include/boost/align/detail/alignment_of_codegear.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_ALIGNMENT_OF_CODEGEAR_HPP 9 | #define BOOST_ALIGN_DETAIL_ALIGNMENT_OF_CODEGEAR_HPP 10 | 11 | #include 12 | #include 13 | 14 | namespace boost { 15 | namespace alignment { 16 | namespace detail { 17 | 18 | template 19 | struct alignment_of 20 | : integral_constant { }; 21 | 22 | } /* detail */ 23 | } /* alignment */ 24 | } /* boost */ 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /include/boost/align/detail/alignment_of_cxx11.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_ALIGNMENT_OF_CXX11_HPP 9 | #define BOOST_ALIGN_DETAIL_ALIGNMENT_OF_CXX11_HPP 10 | 11 | #include 12 | 13 | namespace boost { 14 | namespace alignment { 15 | namespace detail { 16 | 17 | using std::alignment_of; 18 | 19 | } /* detail */ 20 | } /* alignment */ 21 | } /* boost */ 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /include/boost/align/detail/alignment_of_gcc.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_ALIGNMENT_OF_GCC_HPP 9 | #define BOOST_ALIGN_DETAIL_ALIGNMENT_OF_GCC_HPP 10 | 11 | #include 12 | #include 13 | 14 | namespace boost { 15 | namespace alignment { 16 | namespace detail { 17 | 18 | template 19 | struct alignment_of 20 | : integral_constant { }; 21 | 22 | } /* detail */ 23 | } /* alignment */ 24 | } /* boost */ 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /include/boost/align/detail/alignment_of_msvc.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014-2015 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_ALIGNMENT_OF_MSVC_HPP 9 | #define BOOST_ALIGN_DETAIL_ALIGNMENT_OF_MSVC_HPP 10 | 11 | #include 12 | 13 | namespace boost { 14 | namespace alignment { 15 | namespace detail { 16 | 17 | template 18 | struct offset_value { 19 | T first; 20 | char value; 21 | T second; 22 | }; 23 | 24 | template 25 | struct alignment_of 26 | : min_size) - (sizeof(T) << 1)> { }; 27 | 28 | } /* detail */ 29 | } /* alignment */ 30 | } /* boost */ 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /include/boost/align/detail/assume_aligned.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 NumScale SAS 3 | Copyright 2015 LRI UMR 8623 CNRS/University Paris Sud XI 4 | 5 | Copyright 2015 Glen Joseph Fernandes 6 | (glenjofe@gmail.com) 7 | 8 | Distributed under the Boost Software License, Version 1.0. 9 | (http://www.boost.org/LICENSE_1_0.txt) 10 | */ 11 | #ifndef BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_HPP 12 | #define BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_HPP 13 | 14 | #define BOOST_ALIGN_ASSUME_ALIGNED(ptr, alignment) 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /include/boost/align/detail/assume_aligned_clang.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_CLANG_HPP 9 | #define BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_CLANG_HPP 10 | 11 | #if __has_builtin(__builtin_assume_aligned) 12 | #define BOOST_ALIGN_ASSUME_ALIGNED(p, n) \ 13 | (p) = static_cast<__typeof__(p)>(__builtin_assume_aligned((p), (n))) 14 | #else 15 | #define BOOST_ALIGN_ASSUME_ALIGNED(p, n) 16 | #endif 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /include/boost/align/detail/assume_aligned_gcc.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 NumScale SAS 3 | Copyright 2015 LRI UMR 8623 CNRS/University Paris Sud XI 4 | 5 | Copyright 2015 Glen Joseph Fernandes 6 | (glenjofe@gmail.com) 7 | 8 | Distributed under the Boost Software License, Version 1.0. 9 | (http://www.boost.org/LICENSE_1_0.txt) 10 | */ 11 | #ifndef BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_GCC_HPP 12 | #define BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_GCC_HPP 13 | 14 | #define BOOST_ALIGN_ASSUME_ALIGNED(p, n) \ 15 | (p) = static_cast<__typeof__(p)>(__builtin_assume_aligned((p), (n))) 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /include/boost/align/detail/assume_aligned_intel.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 NumScale SAS 3 | Copyright 2015 LRI UMR 8623 CNRS/University Paris Sud XI 4 | 5 | Copyright 2015 Glen Joseph Fernandes 6 | (glenjofe@gmail.com) 7 | 8 | Distributed under the Boost Software License, Version 1.0. 9 | (http://www.boost.org/LICENSE_1_0.txt) 10 | */ 11 | #ifndef BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_INTEL_HPP 12 | #define BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_INTEL_HPP 13 | 14 | #define BOOST_ALIGN_ASSUME_ALIGNED(ptr, alignment) \ 15 | __assume_aligned((ptr), (alignment)) 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /include/boost/align/detail/assume_aligned_msvc.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 NumScale SAS 3 | Copyright 2015 LRI UMR 8623 CNRS/University Paris Sud XI 4 | 5 | Copyright 2015 Glen Joseph Fernandes 6 | (glenjofe@gmail.com) 7 | 8 | Distributed under the Boost Software License, Version 1.0. 9 | (http://www.boost.org/LICENSE_1_0.txt) 10 | */ 11 | #ifndef BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_MSVC_HPP 12 | #define BOOST_ALIGN_DETAIL_ASSUME_ALIGNED_MSVC_HPP 13 | 14 | #include 15 | 16 | #define BOOST_ALIGN_ASSUME_ALIGNED(ptr, alignment) \ 17 | __assume((reinterpret_cast(ptr) & ((alignment) - 1)) == 0) 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /include/boost/align/detail/element_type.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_ELEMENT_TYPE_HPP 9 | #define BOOST_ALIGN_DETAIL_ELEMENT_TYPE_HPP 10 | 11 | #include 12 | 13 | #if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) 14 | #include 15 | #else 16 | #include 17 | #endif 18 | 19 | namespace boost { 20 | namespace alignment { 21 | namespace detail { 22 | 23 | #if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) 24 | using std::remove_reference; 25 | using std::remove_all_extents; 26 | using std::remove_cv; 27 | #else 28 | template 29 | struct remove_reference { 30 | typedef T type; 31 | }; 32 | 33 | template 34 | struct remove_reference { 35 | typedef T type; 36 | }; 37 | 38 | #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 39 | template 40 | struct remove_reference { 41 | typedef T type; 42 | }; 43 | #endif 44 | 45 | template 46 | struct remove_all_extents { 47 | typedef T type; 48 | }; 49 | 50 | template 51 | struct remove_all_extents { 52 | typedef typename remove_all_extents::type type; 53 | }; 54 | 55 | template 56 | struct remove_all_extents { 57 | typedef typename remove_all_extents::type type; 58 | }; 59 | 60 | template 61 | struct remove_cv { 62 | typedef T type; 63 | }; 64 | 65 | template 66 | struct remove_cv { 67 | typedef T type; 68 | }; 69 | 70 | template 71 | struct remove_cv { 72 | typedef T type; 73 | }; 74 | 75 | template 76 | struct remove_cv { 77 | typedef T type; 78 | }; 79 | #endif 80 | 81 | template 82 | struct element_type { 83 | typedef typename remove_cv::type>::type>::type type; 85 | }; 86 | 87 | } /* detail */ 88 | } /* alignment */ 89 | } /* boost */ 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /include/boost/align/detail/integral_constant.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014-2016 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_INTEGRAL_CONSTANT_HPP 9 | #define BOOST_ALIGN_DETAIL_INTEGRAL_CONSTANT_HPP 10 | 11 | #include 12 | 13 | #if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) 14 | #include 15 | #endif 16 | 17 | namespace boost { 18 | namespace alignment { 19 | namespace detail { 20 | 21 | #if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) 22 | using std::integral_constant; 23 | using std::true_type; 24 | using std::false_type; 25 | #else 26 | template 27 | struct integral_constant { 28 | typedef T value_type; 29 | typedef integral_constant type; 30 | 31 | BOOST_CONSTEXPR operator value_type() const BOOST_NOEXCEPT { 32 | return Value; 33 | } 34 | 35 | BOOST_CONSTEXPR value_type operator()() const BOOST_NOEXCEPT { 36 | return Value; 37 | } 38 | 39 | BOOST_STATIC_CONSTEXPR T value = Value; 40 | }; 41 | 42 | template 43 | BOOST_CONSTEXPR_OR_CONST T integral_constant::value; 44 | 45 | typedef integral_constant true_type; 46 | typedef integral_constant false_type; 47 | #endif 48 | 49 | } /* detail */ 50 | } /* alignment */ 51 | } /* boost */ 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /include/boost/align/detail/is_aligned.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_IS_ALIGNED_HPP 9 | #define BOOST_ALIGN_DETAIL_IS_ALIGNED_HPP 10 | 11 | #include 12 | #include 13 | 14 | namespace boost { 15 | namespace alignment { 16 | 17 | inline bool 18 | is_aligned(const volatile void* ptr, std::size_t alignment) BOOST_NOEXCEPT 19 | { 20 | BOOST_ASSERT(detail::is_alignment(alignment)); 21 | return (reinterpret_cast(ptr) & (alignment - 1)) == 0; 22 | } 23 | 24 | inline bool 25 | is_aligned(std::size_t alignment, const volatile void* ptr) BOOST_NOEXCEPT 26 | { 27 | BOOST_ASSERT(detail::is_alignment(alignment)); 28 | return (reinterpret_cast(ptr) & (alignment - 1)) == 0; 29 | } 30 | 31 | } /* alignment */ 32 | } /* boost */ 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /include/boost/align/detail/is_alignment.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_IS_ALIGNMENT_HPP 9 | #define BOOST_ALIGN_DETAIL_IS_ALIGNMENT_HPP 10 | 11 | #include 12 | #include 13 | 14 | namespace boost { 15 | namespace alignment { 16 | namespace detail { 17 | 18 | BOOST_CONSTEXPR inline bool 19 | is_alignment(std::size_t value) BOOST_NOEXCEPT 20 | { 21 | return (value > 0) && ((value & (value - 1)) == 0); 22 | } 23 | 24 | } /* detail */ 25 | } /* alignment */ 26 | } /* boost */ 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /include/boost/align/detail/is_alignment_constant.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_IS_ALIGNMENT_CONSTANT_HPP 9 | #define BOOST_ALIGN_DETAIL_IS_ALIGNMENT_CONSTANT_HPP 10 | 11 | #include 12 | #include 13 | 14 | namespace boost { 15 | namespace alignment { 16 | namespace detail { 17 | 18 | template 19 | struct is_alignment_constant 20 | : integral_constant 0) && ((N & (N - 1)) == 0)> { }; 21 | 22 | } /* detail */ 23 | } /* alignment */ 24 | } /* boost */ 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /include/boost/align/detail/max_align.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014-2015 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_MAX_ALIGN_HPP 9 | #define BOOST_ALIGN_DETAIL_MAX_ALIGN_HPP 10 | 11 | #include 12 | #include 13 | 14 | namespace boost { 15 | namespace alignment { 16 | namespace detail { 17 | 18 | template 19 | struct max_align 20 | : max_size::value, alignment_of::value> { }; 21 | 22 | } /* detail */ 23 | } /* alignment */ 24 | } /* boost */ 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /include/boost/align/detail/max_objects.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_MAX_OBJECTS_HPP 9 | #define BOOST_ALIGN_DETAIL_MAX_OBJECTS_HPP 10 | 11 | #include 12 | #include 13 | 14 | namespace boost { 15 | namespace alignment { 16 | namespace detail { 17 | 18 | template 19 | struct max_objects 20 | : integral_constant(0) / sizeof(T)> { }; 22 | 23 | } /* detail */ 24 | } /* alignment */ 25 | } /* boost */ 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /include/boost/align/detail/max_size.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014-2015 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_MAX_SIZE_HPP 9 | #define BOOST_ALIGN_DETAIL_MAX_SIZE_HPP 10 | 11 | #include 12 | #include 13 | 14 | namespace boost { 15 | namespace alignment { 16 | namespace detail { 17 | 18 | template 19 | struct max_size 20 | : integral_constant B) ? A : B> { }; 21 | 22 | } /* detail */ 23 | } /* alignment */ 24 | } /* boost */ 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /include/boost/align/detail/min_size.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_MIN_SIZE_HPP 9 | #define BOOST_ALIGN_DETAIL_MIN_SIZE_HPP 10 | 11 | #include 12 | #include 13 | 14 | namespace boost { 15 | namespace alignment { 16 | namespace detail { 17 | 18 | template 19 | struct min_size 20 | : integral_constant { }; 21 | 22 | } /* detail */ 23 | } /* alignment */ 24 | } /* boost */ 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /include/boost/align/detail/not_pointer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_NOT_POINTER_HPP 9 | #define BOOST_ALIGN_DETAIL_NOT_POINTER_HPP 10 | 11 | namespace boost { 12 | namespace alignment { 13 | namespace detail { 14 | 15 | template 16 | struct not_pointer { 17 | typedef U type; 18 | }; 19 | 20 | template 21 | struct not_pointer { }; 22 | 23 | } /* detail */ 24 | } /* alignment */ 25 | } /* boost */ 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /include/boost/align/detail/throw_exception.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #ifndef BOOST_ALIGN_DETAIL_THROW_EXCEPTION_HPP 9 | #define BOOST_ALIGN_DETAIL_THROW_EXCEPTION_HPP 10 | 11 | #include 12 | #if defined(BOOST_NO_EXCEPTIONS) 13 | #include 14 | #endif 15 | 16 | namespace boost { 17 | 18 | #if defined(BOOST_NO_EXCEPTIONS) 19 | BOOST_NORETURN void throw_exception(const std::exception&); 20 | #endif 21 | 22 | namespace alignment { 23 | namespace detail { 24 | 25 | #if !defined(BOOST_NO_EXCEPTIONS) 26 | template 27 | BOOST_NORETURN inline void 28 | throw_exception(const E& error) 29 | { 30 | throw error; 31 | } 32 | #else 33 | BOOST_NORETURN inline void 34 | throw_exception(const std::exception& error) 35 | { 36 | boost::throw_exception(error); 37 | } 38 | #endif 39 | 40 | } /* detail */ 41 | } /* alignment */ 42 | } /* boost */ 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /include/boost/align/is_aligned.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | */ 9 | #ifndef BOOST_ALIGN_IS_ALIGNED_HPP 10 | #define BOOST_ALIGN_IS_ALIGNED_HPP 11 | 12 | #include 13 | #include 14 | 15 | namespace boost { 16 | namespace alignment { 17 | 18 | template 19 | BOOST_CONSTEXPR inline typename detail::not_pointer::type 20 | is_aligned(T value, std::size_t alignment) BOOST_NOEXCEPT 21 | { 22 | return (value & (T(alignment) - 1)) == 0; 23 | } 24 | 25 | } /* alignment */ 26 | } /* boost */ 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | Boost.Align 14 | 15 | 16 | 19 |
20 | Copyright 2014-2015 Glen Fernandes 21 | 22 | 23 | -------------------------------------------------------------------------------- /meta/libraries.json: -------------------------------------------------------------------------------- 1 | { 2 | "key": "align", 3 | "name": "Align", 4 | "description": "Memory alignment functions, allocators, traits.", 5 | "authors": [ 6 | "Glen Fernandes" 7 | ], 8 | "maintainers": [ 9 | "Glen Fernandes " 10 | ], 11 | "category": [ 12 | "Memory" 13 | ], 14 | "cxxstd": "03" 15 | } 16 | -------------------------------------------------------------------------------- /test/Jamfile: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2015 Glen Joseph Fernandes 2 | # (glenjofe@gmail.com) 3 | # 4 | # Distributed under the Boost Software License, Version 1.0. 5 | # (http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | import testing ; 8 | 9 | run align_test.cpp ; 10 | run align_overflow_test.cpp ; 11 | run align_down_test.cpp ; 12 | run align_down_integral_test.cpp ; 13 | run align_up_test.cpp ; 14 | run align_up_integral_test.cpp ; 15 | run aligned_alloc_test.cpp ; 16 | run aligned_allocator_test.cpp ; 17 | run aligned_allocator_adaptor_test.cpp ; 18 | run aligned_delete_test.cpp ; 19 | run alignment_of_test.cpp ; 20 | run assume_aligned_test.cpp ; 21 | run is_aligned_test.cpp ; 22 | run is_aligned_integral_test.cpp ; 23 | 24 | compile aligned_allocator_incomplete_test.cpp ; 25 | compile aligned_allocator_adaptor_incomplete_test.cpp ; 26 | -------------------------------------------------------------------------------- /test/align_down_integral_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #include 9 | #include 10 | 11 | template 12 | struct A { }; 13 | 14 | template 15 | void test(A) 16 | { 17 | T v1 = N; 18 | BOOST_TEST(boost::alignment::align_down(v1, N) == v1); 19 | T v2 = N + 1; 20 | BOOST_TEST(boost::alignment::align_down(v2, N) == v1); 21 | } 22 | 23 | template 24 | void test(A<1>) 25 | { 26 | T v = 1; 27 | BOOST_TEST(boost::alignment::align_down(v, 1) == v); 28 | } 29 | 30 | template 31 | void test() 32 | { 33 | test(A<1>()); 34 | test(A<2>()); 35 | test(A<4>()); 36 | test(A<8>()); 37 | test(A<16>()); 38 | test(A<32>()); 39 | test(A<64>()); 40 | test(A<128>()); 41 | } 42 | 43 | int main() 44 | { 45 | test(); 46 | test(); 47 | test(); 48 | test(); 49 | test(); 50 | test(); 51 | #if !defined(BOOST_NO_LONG_LONG) 52 | test(); 53 | test(); 54 | #endif 55 | test(); 56 | test(); 57 | 58 | return boost::report_errors(); 59 | } 60 | -------------------------------------------------------------------------------- /test/align_down_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #include 9 | #include 10 | #include 11 | 12 | template 13 | void test() 14 | { 15 | char s[Alignment << 1]; 16 | char* b = s; 17 | while (!boost::alignment::is_aligned(b, Alignment)) { 18 | ++b; 19 | } 20 | { 21 | void* p = &b[Alignment]; 22 | BOOST_TEST(boost::alignment::align_down(p, Alignment) == p); 23 | } 24 | { 25 | void* p = &b[Alignment - 1]; 26 | void* q = b; 27 | BOOST_TEST(boost::alignment::align_down(p, Alignment) == q); 28 | } 29 | } 30 | 31 | int main() 32 | { 33 | test<1>(); 34 | test<2>(); 35 | test<4>(); 36 | test<8>(); 37 | test<16>(); 38 | test<32>(); 39 | test<64>(); 40 | test<128>(); 41 | 42 | return boost::report_errors(); 43 | } 44 | -------------------------------------------------------------------------------- /test/align_overflow_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #include 9 | #include 10 | 11 | int main() 12 | { 13 | static const std::size_t n = -1; 14 | { 15 | void* p = reinterpret_cast(5); 16 | std::size_t s = 3072; 17 | BOOST_TEST(!boost::alignment::align(1024, n, p, s)); 18 | } 19 | { 20 | void* p = reinterpret_cast(1); 21 | std::size_t s = -1; 22 | BOOST_TEST(!boost::alignment::align(2, n, p, s)); 23 | } 24 | return boost::report_errors(); 25 | } 26 | -------------------------------------------------------------------------------- /test/align_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014-2015 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #include 9 | #include 10 | #include 11 | 12 | template 13 | void test() 14 | { 15 | char s[Alignment << 1]; 16 | char* b = s; 17 | while (!boost::alignment::is_aligned(b, Alignment)) { 18 | ++b; 19 | } 20 | { 21 | std::size_t n = Alignment; 22 | void* p = b; 23 | void* q = boost::alignment::align(Alignment, 1, p, n); 24 | BOOST_TEST(q == p); 25 | BOOST_TEST(q == b); 26 | BOOST_TEST(boost::alignment::is_aligned(q, Alignment)); 27 | BOOST_TEST(n == Alignment); 28 | } 29 | { 30 | std::size_t n = 0; 31 | void* p = b; 32 | void* q = boost::alignment::align(Alignment, 1, p, n); 33 | BOOST_TEST(q == 0); 34 | BOOST_TEST(p == b); 35 | BOOST_TEST(n == 0); 36 | } 37 | { 38 | std::size_t n = Alignment - 1; 39 | void* p = &b[1]; 40 | void* q = boost::alignment::align(Alignment, 1, p, n); 41 | BOOST_TEST(q == 0); 42 | BOOST_TEST(p == &b[1]); 43 | BOOST_TEST(n == Alignment - 1); 44 | } 45 | { 46 | std::size_t n = Alignment; 47 | void* p = &b[1]; 48 | void* q = boost::alignment::align(Alignment, 1, p, n); 49 | BOOST_TEST(q == p); 50 | BOOST_TEST(p == &b[Alignment]); 51 | BOOST_TEST(boost::alignment::is_aligned(q, Alignment)); 52 | BOOST_TEST(n == 1); 53 | } 54 | } 55 | 56 | int main() 57 | { 58 | test<1>(); 59 | test<2>(); 60 | test<4>(); 61 | test<8>(); 62 | test<16>(); 63 | test<32>(); 64 | test<64>(); 65 | test<128>(); 66 | 67 | return boost::report_errors(); 68 | } 69 | -------------------------------------------------------------------------------- /test/align_up_integral_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #include 9 | #include 10 | 11 | template 12 | struct A { }; 13 | 14 | template 15 | void test(A) 16 | { 17 | T v1 = N; 18 | BOOST_TEST(boost::alignment::align_up(v1, N) == v1); 19 | T v2 = N - 1; 20 | BOOST_TEST(boost::alignment::align_up(v2, N) == v1); 21 | T v3 = N + N; 22 | BOOST_TEST(boost::alignment::align_up(v3, N) == v3); 23 | T v4 = N + 1; 24 | BOOST_TEST(boost::alignment::align_up(v4, N) == v3); 25 | } 26 | 27 | template 28 | void test(A<1>) 29 | { 30 | T v = 1; 31 | BOOST_TEST(boost::alignment::align_up(v, 1) == v); 32 | } 33 | 34 | template 35 | void test() 36 | { 37 | test(A<1>()); 38 | test(A<2>()); 39 | test(A<4>()); 40 | test(A<8>()); 41 | test(A<16>()); 42 | test(A<32>()); 43 | test(A<64>()); 44 | test(A<128>()); 45 | } 46 | 47 | int main() 48 | { 49 | test(); 50 | test(); 51 | test(); 52 | test(); 53 | test(); 54 | test(); 55 | #if !defined(BOOST_NO_LONG_LONG) 56 | test(); 57 | test(); 58 | #endif 59 | test(); 60 | test(); 61 | 62 | return boost::report_errors(); 63 | } 64 | -------------------------------------------------------------------------------- /test/align_up_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #include 9 | #include 10 | #include 11 | 12 | template 13 | void test() 14 | { 15 | char s[Alignment << 1]; 16 | char* b = s; 17 | while (!boost::alignment::is_aligned(b, Alignment)) { 18 | ++b; 19 | } 20 | { 21 | void* p = b; 22 | BOOST_TEST(boost::alignment::align_up(p, Alignment) == p); 23 | } 24 | { 25 | void* p = &b[Alignment]; 26 | void* q = &b[1]; 27 | BOOST_TEST(boost::alignment::align_up(q, Alignment) == p); 28 | } 29 | } 30 | 31 | int main() 32 | { 33 | test<1>(); 34 | test<2>(); 35 | test<4>(); 36 | test<8>(); 37 | test<16>(); 38 | test<32>(); 39 | test<64>(); 40 | test<128>(); 41 | 42 | return boost::report_errors(); 43 | } 44 | -------------------------------------------------------------------------------- /test/aligned_alloc_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | void test(std::size_t alignment) 14 | { 15 | { 16 | void* p = boost::alignment::aligned_alloc(alignment, alignment + 1); 17 | BOOST_TEST(p != 0); 18 | BOOST_TEST(boost::alignment::is_aligned(p, alignment)); 19 | std::memset(p, 0, alignment); 20 | boost::alignment::aligned_free(p); 21 | } 22 | { 23 | void* p = boost::alignment::aligned_alloc(alignment, 1); 24 | BOOST_TEST(p != 0); 25 | BOOST_TEST(boost::alignment::is_aligned(p, alignment)); 26 | std::memset(p, 0, 1); 27 | boost::alignment::aligned_free(p); 28 | } 29 | { 30 | void* p = boost::alignment::aligned_alloc(alignment, 0); 31 | boost::alignment::aligned_free(p); 32 | } 33 | } 34 | 35 | int main() 36 | { 37 | test(1); 38 | test(2); 39 | test(4); 40 | test(8); 41 | test(16); 42 | test(32); 43 | test(64); 44 | test(128); 45 | 46 | return boost::report_errors(); 47 | } 48 | -------------------------------------------------------------------------------- /test/aligned_allocator_adaptor_incomplete_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #include 9 | 10 | template 11 | class A { 12 | public: 13 | typedef T value_type; 14 | typedef T* pointer; 15 | typedef std::size_t size_type; 16 | typedef std::ptrdiff_t difference_type; 17 | 18 | template 19 | struct rebind { 20 | typedef A other; 21 | }; 22 | 23 | A(int state) 24 | : state_(state) { } 25 | 26 | template 27 | A(const A& other) 28 | : state_(other.state()) { } 29 | 30 | T* allocate(std::size_t size, const void* = 0) { 31 | return static_cast(::operator new(sizeof(T) * size)); 32 | } 33 | 34 | void deallocate(T* ptr, std::size_t) { 35 | ::operator delete(ptr); 36 | } 37 | 38 | int state() const { 39 | return state_; 40 | } 41 | 42 | private: 43 | int state_; 44 | }; 45 | 46 | template 47 | inline bool 48 | operator==(const A& a, const A& b) 49 | { 50 | return a.state() == b.state(); 51 | } 52 | 53 | template 54 | inline bool 55 | operator!=(const A& a, const A& b) 56 | { 57 | return !(a == b); 58 | } 59 | 60 | struct S; 61 | struct V { }; 62 | 63 | void value_test() 64 | { 65 | boost::alignment::aligned_allocator_adaptor > a(A(1)); 66 | (void)a; 67 | } 68 | 69 | void rebind_test() 70 | { 71 | boost::alignment::aligned_allocator_adaptor > a(A(1)); 72 | boost::alignment::aligned_allocator_adaptor >::rebind::other r(a); 73 | (void)r; 74 | } 75 | -------------------------------------------------------------------------------- /test/aligned_allocator_adaptor_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | template 15 | class A { 16 | public: 17 | typedef T value_type; 18 | typedef T* pointer; 19 | typedef std::size_t size_type; 20 | typedef std::ptrdiff_t difference_type; 21 | 22 | template 23 | struct rebind { 24 | typedef A other; 25 | }; 26 | 27 | A(int state) 28 | : state_(state) { } 29 | 30 | template 31 | A(const A& other) 32 | : state_(other.state()) { } 33 | 34 | T* allocate(std::size_t size, const void* = 0) { 35 | return static_cast(::operator new(sizeof(T) * size)); 36 | } 37 | 38 | void deallocate(T* ptr, std::size_t) { 39 | ::operator delete(ptr); 40 | } 41 | 42 | void construct(T* ptr, const T& value) { 43 | ::new(static_cast(ptr)) T(value); 44 | } 45 | 46 | void destroy(T* ptr) { 47 | ptr->~T(); 48 | } 49 | 50 | int state() const { 51 | return state_; 52 | } 53 | 54 | private: 55 | int state_; 56 | }; 57 | 58 | template 59 | inline bool 60 | operator==(const A& a, const A& b) 61 | { 62 | return a.state() == b.state(); 63 | } 64 | 65 | template 66 | inline bool 67 | operator!=(const A& a, const A& b) 68 | { 69 | return !(a == b); 70 | } 71 | 72 | template 73 | void test_allocate() 74 | { 75 | { 76 | boost::alignment::aligned_allocator_adaptor, Alignment> a(5); 77 | int* p = a.allocate(1); 78 | BOOST_TEST(p != 0); 79 | BOOST_TEST(boost::alignment::is_aligned(p, Alignment)); 80 | std::memset(p, 0, 1); 81 | a.deallocate(p, 1); 82 | } 83 | { 84 | boost::alignment::aligned_allocator_adaptor, Alignment> a(5); 85 | int* p = a.allocate(1); 86 | int* q = a.allocate(1, p); 87 | BOOST_TEST(q != 0); 88 | BOOST_TEST(boost::alignment::is_aligned(q, Alignment)); 89 | std::memset(q, 0, 1); 90 | a.deallocate(q, 1); 91 | a.deallocate(p, 1); 92 | } 93 | { 94 | boost::alignment::aligned_allocator_adaptor, Alignment> a(5); 95 | int* p = a.allocate(0); 96 | a.deallocate(p, 0); 97 | } 98 | } 99 | 100 | template 101 | void test_construct() 102 | { 103 | boost::alignment::aligned_allocator_adaptor, Alignment> a(5); 104 | int* p = a.allocate(1); 105 | a.construct(p, 1); 106 | BOOST_TEST(*p == 1); 107 | a.destroy(p); 108 | a.deallocate(p, 1); 109 | } 110 | 111 | template 112 | void test_constructor() 113 | { 114 | { 115 | boost::alignment::aligned_allocator_adaptor, Alignment> a(5); 116 | boost::alignment::aligned_allocator_adaptor, Alignment> b(a); 117 | BOOST_TEST(b == a); 118 | } 119 | { 120 | A a(5); 121 | boost::alignment::aligned_allocator_adaptor, Alignment> b(a); 122 | BOOST_TEST(b.base() == a); 123 | } 124 | } 125 | 126 | template 127 | void test_rebind() 128 | { 129 | boost::alignment::aligned_allocator_adaptor, Alignment> a(5); 130 | typename boost::alignment::aligned_allocator_adaptor, 131 | Alignment>::template rebind::other b(a); 132 | BOOST_TEST(b == a); 133 | } 134 | 135 | template 136 | void test() 137 | { 138 | test_allocate(); 139 | test_construct(); 140 | test_constructor(); 141 | test_rebind(); 142 | } 143 | 144 | int main() 145 | { 146 | test<1>(); 147 | test<2>(); 148 | test<4>(); 149 | test<8>(); 150 | test<16>(); 151 | test<32>(); 152 | test<64>(); 153 | test<128>(); 154 | 155 | return boost::report_errors(); 156 | } 157 | -------------------------------------------------------------------------------- /test/aligned_allocator_incomplete_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #include 9 | 10 | struct S; 11 | struct V { }; 12 | 13 | void value_test() 14 | { 15 | boost::alignment::aligned_allocator a; 16 | (void)a; 17 | } 18 | 19 | void rebind_test() 20 | { 21 | boost::alignment::aligned_allocator a; 22 | boost::alignment::aligned_allocator::rebind::other r(a); 23 | (void)r; 24 | } 25 | -------------------------------------------------------------------------------- /test/aligned_allocator_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | template 14 | void test_allocate() 15 | { 16 | { 17 | boost::alignment::aligned_allocator a; 18 | int* p = a.allocate(1); 19 | BOOST_TEST(p != 0); 20 | BOOST_TEST(boost::alignment::is_aligned(p, Alignment)); 21 | std::memset(p, 0, 1); 22 | a.deallocate(p, 1); 23 | } 24 | { 25 | boost::alignment::aligned_allocator a; 26 | int* p = a.allocate(0); 27 | a.deallocate(p, 0); 28 | } 29 | } 30 | 31 | template 32 | void test_construct() 33 | { 34 | boost::alignment::aligned_allocator a; 35 | int* p = a.allocate(1); 36 | a.construct(p, 1); 37 | BOOST_TEST(*p == 1); 38 | a.destroy(p); 39 | a.deallocate(p, 1); 40 | } 41 | 42 | template 43 | void test_constructor() 44 | { 45 | { 46 | boost::alignment::aligned_allocator a1; 47 | boost::alignment::aligned_allocator a2(a1); 48 | BOOST_TEST(a2 == a1); 49 | } 50 | { 51 | boost::alignment::aligned_allocator a1; 52 | boost::alignment::aligned_allocator a2(a1); 53 | BOOST_TEST(a2 == a1); 54 | } 55 | { 56 | boost::alignment::aligned_allocator a1; 57 | boost::alignment::aligned_allocator a2(a1); 58 | BOOST_TEST(a2 == a1); 59 | } 60 | } 61 | 62 | template 63 | void test_rebind() 64 | { 65 | { 66 | boost::alignment::aligned_allocator a1; 67 | typename boost::alignment::aligned_allocator::template rebind::other a2(a1); 69 | BOOST_TEST(a2 == a1); 70 | } 71 | { 72 | boost::alignment::aligned_allocator a1; 73 | typename boost::alignment::aligned_allocator::template rebind::other a2(a1); 75 | BOOST_TEST(a2 == a1); 76 | } 77 | { 78 | boost::alignment::aligned_allocator a1; 79 | typename boost::alignment::aligned_allocator::template rebind::other a2(a1); 81 | BOOST_TEST(a2 == a1); 82 | } 83 | } 84 | 85 | template 86 | void test() 87 | { 88 | test_allocate(); 89 | test_construct(); 90 | test_constructor(); 91 | test_rebind(); 92 | } 93 | 94 | int main() 95 | { 96 | test<1>(); 97 | test<2>(); 98 | test<4>(); 99 | test<8>(); 100 | test<16>(); 101 | test<32>(); 102 | test<64>(); 103 | test<128>(); 104 | 105 | return boost::report_errors(); 106 | } 107 | -------------------------------------------------------------------------------- /test/aligned_delete_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | class type { 15 | public: 16 | static unsigned count; 17 | 18 | type() { 19 | ++count; 20 | } 21 | 22 | ~type() { 23 | --count; 24 | } 25 | 26 | private: 27 | type(const type&); 28 | type& operator=(const type&); 29 | }; 30 | 31 | unsigned type::count = 0; 32 | 33 | int main() 34 | { 35 | { 36 | void* p = boost::alignment::aligned_alloc(1, 1); 37 | char* q = ::new(p) char; 38 | boost::alignment::aligned_delete()(q); 39 | } 40 | { 41 | enum { 42 | N = boost::alignment::alignment_of::value 43 | }; 44 | void* p = boost::alignment::aligned_alloc(N, sizeof(type)); 45 | type* q = ::new(p) type; 46 | BOOST_TEST(type::count == 1); 47 | boost::alignment::aligned_delete()(q); 48 | BOOST_TEST(type::count == 0); 49 | } 50 | return boost::report_errors(); 51 | } 52 | -------------------------------------------------------------------------------- /test/alignment_of_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | template 14 | struct remove_reference { 15 | typedef T type; 16 | }; 17 | 18 | template 19 | struct remove_reference { 20 | typedef T type; 21 | }; 22 | 23 | #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 24 | template 25 | struct remove_reference { 26 | typedef T type; 27 | }; 28 | #endif 29 | 30 | template 31 | struct remove_all_extents { 32 | typedef T type; 33 | }; 34 | 35 | template 36 | struct remove_all_extents { 37 | typedef typename remove_all_extents::type type; 38 | }; 39 | 40 | template 41 | struct remove_all_extents { 42 | typedef typename remove_all_extents::type type; 43 | }; 44 | 45 | template 46 | struct remove_cv { 47 | typedef T type; 48 | }; 49 | 50 | template 51 | struct remove_cv { 52 | typedef T type; 53 | }; 54 | 55 | template 56 | struct remove_cv { 57 | typedef T type; 58 | }; 59 | 60 | template 61 | struct remove_cv { 62 | typedef T type; 63 | }; 64 | 65 | template 66 | struct offset_value { 67 | char value; 68 | typename remove_cv::type>::type>::type object; 70 | }; 71 | 72 | template 73 | void test_type() 74 | { 75 | enum { 76 | N = boost::alignment::alignment_of::value 77 | }; 78 | BOOST_TEST(offsetof(offset_value, object) == N); 79 | } 80 | 81 | template 82 | void test_reference() 83 | { 84 | test_type(); 85 | test_type(); 86 | 87 | #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 88 | test_type(); 89 | #endif 90 | } 91 | 92 | template 93 | void test_array() 94 | { 95 | test_reference(); 96 | test_reference(); 97 | test_type(); 98 | } 99 | 100 | template 101 | void test_cv() 102 | { 103 | test_array(); 104 | test_array(); 105 | test_array(); 106 | test_array(); 107 | } 108 | 109 | template 110 | struct Struct { 111 | T t; 112 | }; 113 | 114 | template 115 | union Union { 116 | T t; 117 | }; 118 | 119 | template 120 | void test() 121 | { 122 | test_cv(); 123 | test_cv >(); 124 | test_cv >(); 125 | } 126 | 127 | void test_integral() 128 | { 129 | test(); 130 | test(); 131 | test(); 132 | test(); 133 | test(); 134 | 135 | #if !defined(BOOST_NO_CXX11_CHAR16_T) 136 | test(); 137 | #endif 138 | 139 | #if !defined(BOOST_NO_CXX11_CHAR32_T) 140 | test(); 141 | #endif 142 | 143 | test(); 144 | test(); 145 | test(); 146 | test(); 147 | test(); 148 | test(); 149 | 150 | #if !defined(BOOST_NO_LONG_LONG) 151 | test(); 152 | test(); 153 | #endif 154 | } 155 | 156 | void test_floating_point() 157 | { 158 | test(); 159 | test(); 160 | test(); 161 | } 162 | 163 | void test_nullptr_t() 164 | { 165 | #if !defined(BOOST_NO_CXX11_NULLPTR) && \ 166 | !defined(BOOST_NO_CXX11_DECLTYPE) 167 | test(); 168 | #endif 169 | } 170 | 171 | class X; 172 | 173 | void test_pointer() 174 | { 175 | test(); 176 | test(); 177 | test(); 178 | test(); 179 | test(); 180 | } 181 | 182 | void test_member_pointer() 183 | { 184 | test(); 185 | test(); 186 | } 187 | 188 | enum E { 189 | V = 1 190 | }; 191 | 192 | void test_enum() 193 | { 194 | test(); 195 | } 196 | 197 | struct S { }; 198 | class C { }; 199 | union U { }; 200 | 201 | void test_class() 202 | { 203 | test(); 204 | test(); 205 | test(); 206 | } 207 | 208 | int main() 209 | { 210 | test_integral(); 211 | test_floating_point(); 212 | test_nullptr_t(); 213 | test_pointer(); 214 | test_member_pointer(); 215 | test_enum(); 216 | test_class(); 217 | 218 | return boost::report_errors(); 219 | } 220 | -------------------------------------------------------------------------------- /test/assume_aligned_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #include 9 | 10 | void* test1(void* p) 11 | { 12 | BOOST_ALIGN_ASSUME_ALIGNED(p, 1); 13 | return p; 14 | } 15 | 16 | void* test2(void* p) 17 | { 18 | BOOST_ALIGN_ASSUME_ALIGNED(p, 2); 19 | return p; 20 | } 21 | 22 | void* test4(void* p) 23 | { 24 | BOOST_ALIGN_ASSUME_ALIGNED(p, 4); 25 | return p; 26 | } 27 | 28 | void* test8(void* p) 29 | { 30 | BOOST_ALIGN_ASSUME_ALIGNED(p, 8); 31 | return p; 32 | } 33 | 34 | void* test16(void* p) 35 | { 36 | BOOST_ALIGN_ASSUME_ALIGNED(p, 16); 37 | return p; 38 | } 39 | 40 | void* test32(void* p) 41 | { 42 | BOOST_ALIGN_ASSUME_ALIGNED(p, 32); 43 | return p; 44 | } 45 | 46 | void* test64(void* p) 47 | { 48 | BOOST_ALIGN_ASSUME_ALIGNED(p, 64); 49 | return p; 50 | } 51 | 52 | void* test128(void* p) 53 | { 54 | BOOST_ALIGN_ASSUME_ALIGNED(p, 128); 55 | return p; 56 | } 57 | 58 | int main() 59 | { 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /test/is_aligned_integral_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #include 9 | #include 10 | 11 | template 12 | struct A { }; 13 | 14 | template 15 | void test(A) 16 | { 17 | T v1 = N; 18 | BOOST_TEST(boost::alignment::is_aligned(v1, N)); 19 | T v2 = N - 1; 20 | BOOST_TEST(!boost::alignment::is_aligned(v2, N)); 21 | T v3 = N + 1; 22 | BOOST_TEST(!boost::alignment::is_aligned(v3, N)); 23 | T v4 = N + N; 24 | BOOST_TEST(boost::alignment::is_aligned(v4, N)); 25 | } 26 | 27 | template 28 | void test(A<1>) 29 | { 30 | T v = 1; 31 | BOOST_TEST(boost::alignment::is_aligned(v, 1)); 32 | } 33 | 34 | template 35 | void test() 36 | { 37 | test(A<1>()); 38 | test(A<2>()); 39 | test(A<4>()); 40 | test(A<8>()); 41 | test(A<16>()); 42 | test(A<32>()); 43 | test(A<64>()); 44 | test(A<128>()); 45 | } 46 | 47 | int main() 48 | { 49 | test(); 50 | test(); 51 | test(); 52 | test(); 53 | test(); 54 | test(); 55 | #if !defined(BOOST_NO_LONG_LONG) 56 | test(); 57 | test(); 58 | #endif 59 | test(); 60 | test(); 61 | 62 | return boost::report_errors(); 63 | } 64 | -------------------------------------------------------------------------------- /test/is_aligned_test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014-2015 Glen Joseph Fernandes 3 | (glenjofe@gmail.com) 4 | 5 | Distributed under the Boost Software License, Version 1.0. 6 | (http://www.boost.org/LICENSE_1_0.txt) 7 | */ 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | template 14 | struct A { }; 15 | 16 | template 17 | void test(char* p, A) 18 | { 19 | BOOST_TEST(boost::alignment::is_aligned(p, N)); 20 | BOOST_TEST(!boost::alignment::is_aligned(p + 1, N)); 21 | } 22 | 23 | void test(char* p, A<1>) 24 | { 25 | BOOST_TEST(boost::alignment::is_aligned(p, 1)); 26 | } 27 | 28 | template 29 | void test() 30 | { 31 | T o; 32 | test(reinterpret_cast(&o), 33 | A::value>()); 34 | } 35 | 36 | class X; 37 | 38 | int main() 39 | { 40 | test(); 41 | test(); 42 | test(); 43 | #if !defined(BOOST_NO_CXX11_CHAR16_T) 44 | test(); 45 | #endif 46 | #if !defined(BOOST_NO_CXX11_CHAR32_T) 47 | test(); 48 | #endif 49 | test(); 50 | test(); 51 | test(); 52 | #if !defined(BOOST_NO_LONG_LONG) && !defined(_MSC_VER) 53 | test(); 54 | #endif 55 | test(); 56 | #if !defined(BOOST_MSVC) 57 | test(); 58 | test(); 59 | #endif 60 | test(); 61 | test(); 62 | test(); 63 | test(); 64 | test(); 65 | #if !defined(_MSC_VER) || !defined(__clang__) 66 | #if !defined(BOOST_MSVC) 67 | test(); 68 | test(); 69 | #endif 70 | #endif 71 | 72 | return boost::report_errors(); 73 | } 74 | --------------------------------------------------------------------------------

17 | Redirecting you to Boost.Align 18 |