constexpr_bit_width.hpp 689 B

1234567891011121314151617181920212223242526272829
  1. /* Copyright 2025 Joaquin M Lopez Munoz.
  2. * Distributed under the Boost Software License, Version 1.0.
  3. * (See accompanying file LICENSE_1_0.txt or copy at
  4. * http://www.boost.org/LICENSE_1_0.txt)
  5. *
  6. * See https://www.boost.org/libs/bloom for library home page.
  7. */
  8. #ifndef BOOST_BLOOM_DETAIL_CONSTEXPR_BIT_WIDTH_HPP
  9. #define BOOST_BLOOM_DETAIL_CONSTEXPR_BIT_WIDTH_HPP
  10. #include <cstddef>
  11. namespace boost{
  12. namespace bloom{
  13. namespace detail{
  14. /* boost::core::bit_width is not always C++11 constexpr */
  15. constexpr std::size_t constexpr_bit_width(std::size_t x)
  16. {
  17. return x?1+constexpr_bit_width(x>>1):0;
  18. }
  19. } /* namespace detail */
  20. } /* namespace bloom */
  21. } /* namespace boost */
  22. #endif