align.qbk 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. [/
  2. Copyright 2014-2017 Glen Joseph Fernandes
  3. (glenjofe@gmail.com)
  4. Distributed under the Boost Software License, Version 1.0.
  5. (http://www.boost.org/LICENSE_1_0.txt)
  6. ]
  7. [library Boost.Align
  8. [quickbook 1.6]
  9. [id align]
  10. [copyright 2014-2017 Glen Joseph Fernandes]
  11. [authors [Fernandes, Glen]]
  12. [dirname align]
  13. [license Distributed under the Boost Software License, Version 1.0.]]
  14. [section Introduction]
  15. The Boost Align C++ library provides functions, classes, templates, traits,
  16. and macros, for the control, inspection, and diagnostic of memory alignment.
  17. [endsect]
  18. [section Rationale]
  19. [heading Dynamic allocation]
  20. C++11 added the ability to specify increased alignment (over-alignment) for
  21. class types. Unfortunately, `::operator new` allocation functions, `new`
  22. expressions and the Default Allocator, `std::allocator`, do not support
  23. dynamic memory allocation of over-aligned data. This library provides
  24. allocation functions and allocators that respect the alignment requirements of
  25. a type and so are suitable for allocating memory for over-aligned types.
  26. [variablelist
  27. [[`aligned_alloc(alignment, size)`]
  28. [Replaces `::operator new(size, std::nothrow)`]]
  29. [[`aligned_free(pointer)`]
  30. [Replaces `::operator delete(pointer, std::nothrow)`]]
  31. [[`aligned_allocator<T>`][Replaces `std::allocator<T>`]]
  32. [[`aligned_allocator_adaptor<Allocator>`][Replaces use of Allocator]]
  33. [[`aligned_delete`][Replaces `std::default_delete<T>`]]]
  34. [heading Pointer alignment]
  35. C++11 provided `std::align` in the standard library to align a pointer value.
  36. Unfortunately some C++ standard library implementations do not support it yet
  37. (libstdc++ as far as gcc 4.8.0) and other standard library implementations
  38. implement it incorrectly (dinkumware in msvc11.0). This library provides it
  39. for those implementations and also for C++03 compilers where it is equally
  40. useful.
  41. [heading Querying alignment]
  42. C++11 provided the `std::alignment_of` trait in the standard library to query
  43. the alignment requirement of a type. Unfortunately some C++ standard library
  44. vendors do not implement it in an entirely standard conforming manner, such as
  45. for array types (libc++ as far as clang 3.4). Other vendor implementations
  46. report incorrect values for certain types, such as pointer to members (msvc
  47. 14.0). This library provides it for those implementations and also for C++03
  48. compilers where it is equally useful.
  49. [heading Hinting alignment]
  50. Allocating aligned memory is sometimes not enough to ensure that optimal code
  51. is generated. Developers use specific compiler intrinsics to notify the
  52. compiler of a given alignment property of a memory block. This library
  53. provides a macro, `BOOST_ALIGN_ASSUME_ALIGNED`, to abstract that functionality
  54. for compilers with the appropriate intrinsics.
  55. [heading Checking alignment]
  56. This library provides a function, `is_aligned` to test the alignment of a
  57. pointer value. It is generally useful in assertions to validate that memory is
  58. correctly aligned.
  59. [endsect]
  60. [section Examples]
  61. [heading Aligned allocation]
  62. To dynamically allocate storage with desired alignment, you can use the
  63. `aligned_alloc` function:
  64. [ordered_list
  65. [`void* storage = boost::alignment::aligned_alloc(alignment, size);`]]
  66. To deallocate storage allocated with the `aligned_alloc` function, use
  67. the `aligned_free` function:
  68. [ordered_list [`boost::alignment::aligned_free(storage);`]]
  69. [heading Aligned allocator]
  70. For C++ allocator aware code, you can use the `aligned_allocator` class
  71. template for an allocator that respects over-alignment:
  72. [ordered_list
  73. [`std::vector<int128_t,
  74. boost::alignment::aligned_allocator<int128_t> > vector;`]]
  75. This template allows specifying minimum alignment for all dynamic allocations:
  76. [ordered_list
  77. [`std::vector<double,
  78. boost::alignment::aligned_allocator<double, 64> > vector;`]]
  79. [heading Aligned allocator adaptor]
  80. To turn an allocator into an allocator that respects over-alignment, you can
  81. use the `aligned_allocator_adaptor` class template:
  82. [ordered_list
  83. [`boost::alignment::aligned_allocator_adaptor<First> second(first);`]]
  84. This template allows specifying minimum alignment for all dynamic
  85. allocations:
  86. [ordered_list
  87. [`boost::alignment::aligned_allocator_adaptor<First, 64> second(first);`]]
  88. [heading Aligned deleter]
  89. For a deleter that can be paired with `aligned_alloc`, you can use the
  90. `aligned_delete` class:
  91. [ordered_list
  92. [`std::unique_ptr<double, boost::alignment::aligned_delete> pointer;`]]
  93. [heading Pointer alignment]
  94. To advance a pointer to the next address with the desired alignment:
  95. [ordered_list
  96. [`void* pointer = storage;`]
  97. [`std::size_t space = size;`]
  98. [`void* result = boost::alignment::align(64, sizeof(double), pointer,
  99. space);`]]
  100. [heading Querying alignment]
  101. To obtain the alignment of a given type at compie time, you can use:
  102. [ordered_list [`boost::alignment::alignment_of<int128_t>::value`]]
  103. If your compiler supports C++14 variable templates, you can also use:
  104. [ordered_list [`boost::alignment::alignment_of_v<int128_t>`]]
  105. [heading Hinting alignment]
  106. To inform the compiler about the alignment of a pointer, you can use:
  107. [ordered_list [`BOOST_ALIGN_ASSUME_ALIGNED(pointer, 64)`]]
  108. [heading Checking alignment]
  109. To check alignment of a pointer you can use the `is_aligned` function:
  110. [ordered_list [`assert(boost::alignment::is_aligned(pointer, 64));`]]
  111. [endsect]
  112. [section Reference]
  113. [section Functions]
  114. [section align]
  115. [variablelist
  116. [[`void* align(std::size_t alignment, std::size_t size, void*& ptr,
  117. std::size_t& space);`]
  118. [[variablelist
  119. [[Header][`#include <boost/align/align.hpp>`]]
  120. [[Effects]
  121. [If it is possible to fit `size` bytes of storage aligned by `alignment` into
  122. the buffer pointed to by `ptr` with length `space`, the function updates `ptr`
  123. to point to the first possible address of such storage and decreases `space` by
  124. the number of bytes used for alignment. Otherwise, the function does nothing.]]
  125. [[Requires]
  126. [[itemized_list
  127. [`alignment` shall be a power of two]
  128. [`ptr` shall point to contiguous storage of at least `space` bytes]]]]
  129. [[Returns]
  130. [A null pointer if the requested aligned buffer would not fit into the
  131. available space, otherwise the adjusted value of `ptr`.]]
  132. [[Note]
  133. [The function updates its `ptr` and `space` arguments so that it can be called
  134. repeatedly with possibly different `alignment` and `size`arguments for the same
  135. buffer.]]]]]]
  136. [endsect]
  137. [section align_up]
  138. [variablelist
  139. [[`template<class T> constexpr T align_up(T value, std::size_t alignment)
  140. noexcept;`]
  141. [[variablelist
  142. [[Header][`#include <boost/align/align_up.hpp>`]]
  143. [[Constraints][`T` is not a pointer type]]
  144. [[Requires][`alignment` shall be a power of two]]
  145. [[Returns][A value at or after `value` that is a multiple of `alignment`.]]]]]]
  146. [endsect]
  147. [section align_down]
  148. [variablelist
  149. [[`template<class T> constexpr T align_down(T value, std::size_t alignment)
  150. noexcept;`]
  151. [[variablelist
  152. [[Header][`#include <boost/align/align_down.hpp>`]]
  153. [[Constraints][`T` is not a pointer type]]
  154. [[Requires][`alignment` shall be a power of two]]
  155. [[Returns]
  156. [A value at or before `value` that is a multiple of `alignment`.]]]]]]
  157. [endsect]
  158. [section aligned_alloc]
  159. [variablelist
  160. [[`void* aligned_alloc(std::size_t alignment, std::size_t size);`]
  161. [[variablelist
  162. [[Header][`#include <boost/align/aligned_alloc.hpp>`]]
  163. [[Effects]
  164. [Allocates space for an object whose alignment is specified by `alignment`,
  165. whose size is specified by `size`, and whose value is indeterminate.]]
  166. [[Requires][`alignment` shall be a power of two.]]
  167. [[Returns][A null pointer or a pointer to the allocated space.]]
  168. [[Note]
  169. [On certain platforms, the space allocated may be slightly larger than
  170. `size` bytes, to allow for alignment.]]]]]]
  171. [endsect]
  172. [section aligned_free]
  173. [variablelist
  174. [[`void aligned_free(void* ptr);`]
  175. [[variablelist
  176. [[Header][`#include <boost/align/aligned_alloc.hpp>`]]
  177. [[Effects]
  178. [Causes the space pointed to by `ptr` to be deallocated, that is, made
  179. available for further allocation. If `ptr` is a null pointer, no action occurs.
  180. Otherwise, if the argument does not match a pointer earlier returned by the
  181. `aligned_alloc()` function, or if the space has been deallocated by a call to
  182. `aligned_free()`, the behavior is undefined.]]
  183. [[Requires]
  184. [`ptr` is a null pointer or a pointer earlier returned by the `aligned_alloc()`
  185. function that has not been deallocated by a call to `aligned_free()`.]]
  186. [[Returns][The `aligned_free()` function returns no value.]]]]]]
  187. [endsect]
  188. [section is_aligned]
  189. [variablelist
  190. [[`bool is_aligned(const volatile void* ptr, std::size_t alignment) noexcept;`]
  191. [[variablelist
  192. [[Header][`#include <boost/align/is_aligned.hpp>`]]
  193. [[Requires][`alignment` shall be a power of two.]]
  194. [[Returns]
  195. [`true` if `ptr` is aligned on the boundary specified by `alignment`, otherwise
  196. `false`.]]]]]
  197. [[`template<class T> constexpr bool is_aligned(T value, std::size_t alignment)
  198. noexcept;`]
  199. [[variablelist
  200. [[Header][`#include <boost/align/is_aligned.hpp>`]]
  201. [[Constraints][`T` is not a pointer type]]
  202. [[Requires][`alignment` shall be a power of two.]]
  203. [[Returns]
  204. [`true` if the value of `value` is aligned on the boundary specified by
  205. `alignment`, otherwise `false`.]]]]]]
  206. [endsect]
  207. [endsect]
  208. [section Classes]
  209. [section aligned_allocator]
  210. [variablelist
  211. [[`template<class T, std::size_t Alignment = 1> class aligned_allocator;`]
  212. [[variablelist
  213. [[Header][`#include <boost/align/aligned_allocator.hpp>`]]
  214. [[Note]
  215. [Using the aligned allocator with a minimum Alignment value is generally only
  216. useful with containers that are not node-based such as `vector`. With
  217. node-based containers, such as `list`, the node object would have the minimum
  218. alignment instead of the value type object.]]]]]]
  219. [heading Member types]
  220. [ordered_list
  221. [`typedef T value_type;`]
  222. [`typedef T* pointer;`]
  223. [`typedef const T* const_pointer;`]
  224. [`typedef void* void_pointer;`]
  225. [`typedef const void* const_void_pointer;`]
  226. [`typedef std::add_lvalue_reference_t<T> reference;`]
  227. [`typedef std::add_lvalue_reference_t<const T> const_reference;`]
  228. [`typedef std::size_t size_type;`]
  229. [`typedef std::ptrdiff_t difference_type;`]
  230. [`typedef std::true_type propagate_on_container_move_assignment;`]
  231. [`typedef std::true_type is_always_equal;`]
  232. [`template<class U> struct rebind { typedef aligned_allocator<U, Alignment>
  233. other; };`]]
  234. [heading Constructors]
  235. [variablelist
  236. [[`aligned_allocator() = default;`]
  237. [[variablelist [[Effects][Constructs the allocator.]]]]]
  238. [[`template<class U> aligned_allocator(const aligned_allocator<U, Alignment>&)
  239. noexcept;`]
  240. [[variablelist [[Effects][Constructs the allocator.]]]]]]
  241. [heading Member functions]
  242. Except for the destructor, member functions of the aligned allocator shall not
  243. introduce data races as a result of concurrent calls to those member functions
  244. from different threads. Calls to these functions that allocate or deallocate a
  245. particular unit of storage shall occur in a single total order, and each such
  246. deallocation call shall happen before the next allocation (if any) in this
  247. order.
  248. [variablelist
  249. [[`pointer allocate(size_type size, const_void_pointer = 0);`]
  250. [[variablelist
  251. [[Returns]
  252. [A pointer to the initial element of an array of storage of size
  253. `n * sizeof(T)`, aligned on the maximum of the minimum alignment specified and
  254. the alignment of objects of type `T`.]]
  255. [[Remark]
  256. [The storage is obtained by calling `aligned_alloc(std::size_t,
  257. std::size_t)`.]]
  258. [[Throws][`std::bad_alloc` if the storage cannot be obtained.]]]]]
  259. [[`void deallocate(pointer ptr, size_type);`]
  260. [[variablelist
  261. [[Requires]
  262. [`ptr` shall be a pointer value obtained from `allocate()`.]]
  263. [[Effects][Deallocates the storage referenced by `ptr`.]]
  264. [[Remark][Uses `aligned_free(void*)`.]]]]]
  265. [[`size_type max_size() const noexcept;`]
  266. [[variablelist
  267. [[Returns]
  268. [The largest value `N` for which the call `allocate(N)` might succeed.]]]]]
  269. [[`template<class U, class... Args> void construct(U* ptr, Args&&... args);`]
  270. [[variablelist
  271. [[Effects][`::new((void*)ptr) U(std::forward<Args>(args)...)`.]]]]]
  272. [[`template<class U> void destroy(U* ptr);`]
  273. [[variablelist [[Effects][`ptr->~U()`.]]]]]]
  274. [heading Global operators]
  275. [variablelist
  276. [[`template<class T1, class T2, std::size_t Alignment> bool operator==(const
  277. aligned_allocator<T1, Alignment>&, const aligned_allocator<T2, Alignment>&)
  278. noexcept;`]
  279. [[variablelist [[Returns][`true`]]]]]
  280. [[`template<class T1, class T2, std::size_t Alignment> bool operator!=(const
  281. aligned_allocator<T1, Alignment>&, const aligned_allocator<T2, Alignment>&)
  282. noexcept;`]
  283. [[variablelist [[Returns][`false`]]]]]]
  284. [endsect]
  285. [section aligned_allocator_adaptor]
  286. [variablelist
  287. [[`template<class Allocator, std::size_t Alignment = 1> class
  288. aligned_allocator_adaptor;`]
  289. [[variablelist
  290. [[Header][`#include <boost/align/aligned_allocator_adaptor.hpp>`]]
  291. [[Note]
  292. [This adaptor can be used with a C++11 Allocator whose pointer type is a smart
  293. pointer but the adaptor can choose to expose only raw pointer types.]]]]]]
  294. [heading Member types]
  295. [ordered_list
  296. [`typedef typename Allocator::value_type value_type;`]
  297. [`typedef value_type* pointer;`]
  298. [`typedef const value_type* const_pointer;`]
  299. [`typedef void* void_pointer;`]
  300. [`typedef const void* const_void_pointer;`]
  301. [`typedef std::size_t size_type;`]
  302. [`typedef std::ptrdiff_t difference_type;`]
  303. [`template<class U> struct rebind { typedef aligned_allocator_adaptor<typename
  304. std::allocator_traits<Allocator>::template rebind_alloc<U>, Alignment>
  305. other; };`]]
  306. [heading Constructors]
  307. [variablelist
  308. [[`aligned_allocator_adaptor() = default;`]
  309. [[variablelist [[Effects][Value-initializes the `Allocator` base class.]]]]]
  310. [[`template<class A> aligned_allocator_adaptor(A&& alloc) noexcept;`]
  311. [[variablelist [[Requires][`Allocator` shall be constructible from `A`.]]
  312. [[Effects]
  313. [Initializes the `Allocator` base class with `std::forward<A>(alloc)`.]]]]]
  314. [[`template<class U> aligned_allocator_adaptor(const
  315. aligned_allocator_adaptor<U, Alignment>& other) noexcept;`]
  316. [[variablelist
  317. [[Requires][`Allocator` shall be constructible from `A`.]]
  318. [[Effects][Initializes the `Allocator` base class with `other.base()`.]]]]]]
  319. [heading Member functions]
  320. [variablelist
  321. [[`Allocator& base() noexcept;`]
  322. [[variablelist [[Returns][`static_cast<Allocator&>(*this)`]]]]]
  323. [[`const Allocator& base() const noexcept;`]
  324. [[variablelist [[Returns][`static_cast<const Allocator&>(*this)`]]]]]
  325. [[`pointer allocate(size_type size);`]
  326. [[variablelist
  327. [[Returns]
  328. [A pointer to the initial element of an array of storage of size
  329. `n * sizeof(value_type)`, aligned on the maximum of the minimum alignment
  330. specified and the alignment of objects of type `value_type`.]]
  331. [[Remark]
  332. [The storage is obtained by calling `A2::allocate()` on an object `a2`, where
  333. `a2` of type `A2` is a rebound copy of `base()` where its `value_type` is
  334. implementation defined.]]
  335. [[Throws]
  336. [Throws an exception thrown from `A2::allocate()` if the storage cannot be
  337. obtained.]]]]]
  338. [[`pointer allocate(size_type size, const_void_pointer hint);`]
  339. [[variablelist
  340. [[Requires]
  341. [`hint` is a value obtained by calling `allocate()` on any equivalent allocator
  342. object, or else a null pointer.]]
  343. [[Returns]
  344. [A pointer to the initial element of an array of storage of size
  345. `n * sizeof(value_type)`, aligned on the maximum of the minimum alignment
  346. specified and the alignment of objects of type `value_type`.]]
  347. [[Remark]
  348. [The storage is obtained by calling `A2::allocate()` on an object `a2`, where
  349. `a2` of type `A2` is a rebound copy of `base()` where its `value_type` is an
  350. implementation defined.]]
  351. [[Throws]
  352. [Throws an exception thrown from `A2::allocate()` if the storage cannot be
  353. obtained.]]]]]
  354. [[`void deallocate(pointer ptr, size_type size);`]
  355. [[variablelist
  356. [[Requires]
  357. [[itemized_list
  358. [`ptr` shall be a pointer value obtained from `allocate()`]
  359. [`size` shall equal the value passed as the first argument to the invocation of
  360. `allocate()` which returned `ptr`.]]]]
  361. [[Effects][Deallocates the storage referenced by `ptr`.]]
  362. [[Note]
  363. [Uses `A2::deallocate()` on an object `a2`, where `a2` of type `A2` is a
  364. rebound copy of `base()` where its `value_type` is implementation
  365. defined.]]]]]]
  366. [heading Global operators]
  367. [variablelist
  368. [[`template<class A1, class A2, std::size_t Alignment> bool operator==(const
  369. aligned_allocator_adaptor<A1, Alignment>& a1, const
  370. aligned_allocator_adaptor<A2, Alignment>& a2) noexcept;`]
  371. [[variablelist [[Returns][`a1.base() == a2.base()`]]]]]
  372. [[`template<class A1, class A2, std::size_t Alignment> bool operator!=(const
  373. aligned_allocator_adaptor<A1, Alignment>& a1, const
  374. aligned_allocator_adaptor<A2, Alignment>& a2) noexcept;`]
  375. [[variablelist [[Returns][`!(a1 == a2)`]]]]]]
  376. [endsect]
  377. [section aligned_delete]
  378. [variablelist
  379. [[`class aligned_delete;`]
  380. [[variablelist [[Header][`#include <boost/align/aligned_delete.hpp>`]]]]]]
  381. [heading Member operators]
  382. [variablelist
  383. [[`template<class T> void operator()(T* ptr) noexcept(noexcept(ptr->~T()));`]
  384. [[variablelist
  385. [[Effects]
  386. [Calls `~T()` on `ptr` to destroy the object and then calls `aligned_free()` on
  387. `ptr` to free the allocated memory.]]
  388. [[Note][If `T` is an incomplete type, the program is ill-formed.]]]]]]
  389. [endsect]
  390. [endsect]
  391. [section Traits]
  392. [section alignment_of]
  393. [variablelist
  394. [[`template<class T> struct alignment_of;`]
  395. [[variablelist
  396. [[Header][`#include <boost/align/alignment_of.hpp>`]]
  397. [[Value]
  398. [The alignment requirement of the type `T` as an integral constant of type
  399. `std::size_t`. When `T` is a reference array type, the value shall be the
  400. alignment of the referenced type. When `T` is an array type, the value shall be
  401. the alignment of the element type.]]
  402. [[Requires]
  403. [`T` shall be a complete object type, or an array thereof, or a reference to
  404. one of those types.]]]]]]
  405. [endsect]
  406. [endsect]
  407. [section Macros]
  408. [section BOOST_ALIGN_ASSUME_ALIGNED]
  409. [variablelist
  410. [[`BOOST_ALIGN_ASSUME_ALIGNED(ptr, alignment)`]
  411. [[variablelist
  412. [[Header][`#include <boost/align/assume_aligned.hpp>`]]
  413. [[Requires]
  414. [[itemized_list [`alignment` shall be a power of two]
  415. [`ptr` shall be mutable]]]]
  416. [[Effects]
  417. [`ptr` may be modified in an implementation specific way to inform the compiler
  418. of its alignment.]]]]]]
  419. [endsect]
  420. [endsect]
  421. [endsect]
  422. [section Vocabulary]
  423. [heading \[basic.align\]]
  424. Object types have /alignment requirements/ which place restrictions on the
  425. addresses at which an object of that type may be allocated. An /alignment/ is
  426. an implementation-defined integer value representing the number of bytes
  427. between successive addresses at which a given object can be allocated. An
  428. object type imposes an alignment requirement on every object of that type;
  429. stricter alignment can be requested using the alignment specifier.
  430. A /fundamental alignment/ is represented by an alignment less than or equal to
  431. the greatest alignment supported by the implementation in all contexts, which
  432. is equal to `alignof(std::max_align_t)`. The alignment required for a type
  433. might be different when it is used as the type of a complete object and when
  434. it is used as the type of a subobject.
  435. \[['Example:]
  436. [ordered_list
  437. [`struct B { long double d; };`]
  438. [`struct D : virtual B { char c; };`]]
  439. When `D` is the type of a complete object, it will have a subobject of type
  440. `B`, so it must be aligned appropriately for a `long double`. If `D` appears
  441. as a subobject of another object that also has `B` as a virtual base class,
  442. the `B` subobject might be part of a different subobject, reducing the
  443. alignment requirements on the `D` subobject. \u2014['end example]\] The result
  444. of the `alignof` operator reflects the alignment requirement of the type in
  445. the complete-object case.
  446. An /extended alignment/ is represented by an alignment greater than
  447. `alignof(std::max_align_t)`. It is implementation-defined whether any extended
  448. alignments are supported and the contexts in which they are supported. A type
  449. having an extended alignment requirement is an /over-aligned type/. \[['Note:]
  450. Every over-aligned type is or contains a class type to which extended
  451. alignment applies (possibly through a non-static data member). \u2014['end
  452. note]\]
  453. Alignments are represented as values of the type `std::size_t`. Valid
  454. alignments include only those values returned by an `alignof` expression for
  455. the fundamental types plus an additional implementation-defined set of values,
  456. which may be empty. Every alignment value shall be a non-negative integral
  457. power of two.
  458. Alignments have an order from /weaker/ to /stronger/ or /stricter/ alignments.
  459. Stricter alignments have larger alignment values. An address that satisfies an
  460. alignment requirement also satisfies any weaker valid alignment requirement.
  461. The alignment requirement of a complete type can be queried using an `alignof`
  462. expression. Furthermore, the types `char`, `signed char`, and `unsigned char`
  463. shall have the weakest alignment requirement. \[['Note:] This enables the
  464. character types to be used as the underlying type for an aligned memory area.
  465. \u2014['end note]\]
  466. Comparing alignments is meaningful and provides the obvious results:
  467. * Two alignments are equal when their numeric values are equal.
  468. * Two alignments are different when their numeric values are not equal.
  469. * When an alignment is larger than another it represents a stricter
  470. alignment.
  471. \[['Note:] The runtime pointer alignment function can be used to obtain an
  472. aligned pointer within a buffer; the aligned-storage templates in the library
  473. can be used to obtain aligned storage. \u2014['end note]\]
  474. If a request for a specific extended alignment in a specific context is not
  475. supported by an implementation, the program is ill-formed. Additionally, a
  476. request for runtime allocation of dynamic storage for which the requested
  477. alignment cannot be honored shall be treated as an allocation failure.
  478. [endsect]
  479. [section Compatibility]
  480. This library has been tested with the following C++ implementations:
  481. [variablelist
  482. [[Compilers][gcc, clang, msvc, intel]]
  483. [[Libraries][libstdc++, libc++, dinkumware]]
  484. [[Systems][linux, windows, osx]]
  485. [[Platforms][x64, x86, arm]]
  486. [[Standards][c++98, c++03, c++11, c++14, c++17]]]
  487. [endsect]
  488. [section Acknowledgments]
  489. Thank you to everyone who reviewed the design, code, examples, tests, or
  490. documentation, including:
  491. * Peter Dimov
  492. * Andrey Semashev
  493. * Bjorn Reese
  494. * Steven Watanabe
  495. * Antony Polukhin
  496. * Lars Viklund
  497. * Michael Spencer
  498. * Paul A. Bristow
  499. Thank you to Ahmed Charles for serving as the review manager for the formal
  500. review of the library.
  501. [endsect]
  502. [section History]
  503. [variablelist
  504. [[Boost 1.61]
  505. [Functions for aligning up, down, and testing alignment of integral values.]]
  506. [[Boost 1.59]
  507. [Joel Falcou and Charly Chevalier contributed the alignment hint macro.]]
  508. [[Boost 1.56]
  509. [Glen Fernandes implemented and contributed the Align library to Boost.]]]
  510. [endsect]