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* align(std::size_t alignment,std::size_t size,void * & ptr,std::size_t & space)18align(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 char* p = reinterpret_cast<char*>(~(alignment - 1) & 23 (reinterpret_cast<std::size_t>(ptr) + alignment - 1)); 24 std::size_t n = p - static_cast<char*>(ptr); 25 if (size + n <= space) { 26 ptr = p; 27 space -= n; 28 return p; 29 } 30 return 0; 31 } 32 33 } /* alignment */ 34 } /* boost */ 35 36 #endif 37