align_down.hpp 633 B

12345678910111213141516171819202122232425262728
  1. /*
  2. Copyright 2015 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. #ifndef BOOST_ALIGN_DETAIL_ALIGN_DOWN_HPP
  8. #define BOOST_ALIGN_DETAIL_ALIGN_DOWN_HPP
  9. #include <boost/align/detail/is_alignment.hpp>
  10. #include <boost/assert.hpp>
  11. namespace boost {
  12. namespace alignment {
  13. inline void*
  14. align_down(void* ptr, std::size_t alignment) BOOST_NOEXCEPT
  15. {
  16. BOOST_ASSERT(detail::is_alignment(alignment));
  17. return reinterpret_cast<void*>(~(alignment - 1) &
  18. reinterpret_cast<std::size_t>(ptr));
  19. }
  20. } /* alignment */
  21. } /* boost */
  22. #endif