is_aligned.hpp 835 B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. Copyright 2014 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_IS_ALIGNED_HPP
  8. #define BOOST_ALIGN_DETAIL_IS_ALIGNED_HPP
  9. #include <boost/align/detail/is_alignment.hpp>
  10. #include <boost/assert.hpp>
  11. namespace boost {
  12. namespace alignment {
  13. inline bool
  14. is_aligned(const volatile void* ptr, std::size_t alignment) BOOST_NOEXCEPT
  15. {
  16. BOOST_ASSERT(detail::is_alignment(alignment));
  17. return (reinterpret_cast<std::size_t>(ptr) & (alignment - 1)) == 0;
  18. }
  19. inline bool
  20. is_aligned(std::size_t alignment, const volatile void* ptr) BOOST_NOEXCEPT
  21. {
  22. BOOST_ASSERT(detail::is_alignment(alignment));
  23. return (reinterpret_cast<std::size_t>(ptr) & (alignment - 1)) == 0;
  24. }
  25. } /* alignment */
  26. } /* boost */
  27. #endif