]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/align/detail/align.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / align / detail / align.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_ALIGN_HPP
9 #define BOOST_ALIGN_DETAIL_ALIGN_HPP
10
11 #include <boost/align/detail/is_alignment.hpp>
12 #include <boost/assert.hpp>
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(detail::is_alignment(alignment));
22 if (size <= space) {
23 char* p = reinterpret_cast<char*>(~(alignment - 1) &
24 (reinterpret_cast<std::size_t>(ptr) + alignment - 1));
25 std::size_t n = space - (p - static_cast<char*>(ptr));
26 if (size <= n) {
27 ptr = p;
28 space = n;
29 return p;
30 }
31 }
32 return 0;
33 }
34
35 } /* alignment */
36 } /* boost */
37
38 #endif