|
2 | 2 | #define OSRM_UTIL_BIT_RANGE_HPP
|
3 | 3 |
|
4 | 4 | #include "util/msb.hpp"
|
5 |
| - |
| 5 | +#include <bit> |
6 | 6 | #include <boost/iterator/iterator_facade.hpp>
|
7 | 7 | #include <boost/range/iterator_range.hpp>
|
8 | 8 |
|
9 | 9 | namespace osrm::util
|
10 | 10 | {
|
11 | 11 |
|
12 |
| -namespace detail |
13 |
| -{ |
14 |
| -template <typename T> std::size_t countOnes(T value) |
15 |
| -{ |
16 |
| - static_assert(std::is_unsigned<T>::value, "Only unsigned types allowed"); |
17 |
| - std::size_t number_of_ones = 0; |
18 |
| - while (value > 0) |
19 |
| - { |
20 |
| - auto index = msb(value); |
21 |
| - value = value & ~(T{1} << index); |
22 |
| - number_of_ones++; |
23 |
| - } |
24 |
| - return number_of_ones; |
25 |
| -} |
26 |
| - |
27 |
| -#if (defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)) |
28 |
| -inline std::size_t countOnes(std::uint8_t value) |
29 |
| -{ |
30 |
| - return __builtin_popcount(std::uint32_t{value}); |
31 |
| -} |
32 |
| -inline std::size_t countOnes(std::uint16_t value) |
33 |
| -{ |
34 |
| - return __builtin_popcount(std::uint32_t{value}); |
35 |
| -} |
36 |
| -inline std::size_t countOnes(unsigned int value) { return __builtin_popcount(value); } |
37 |
| -inline std::size_t countOnes(unsigned long value) { return __builtin_popcountl(value); } |
38 |
| -inline std::size_t countOnes(unsigned long long value) { return __builtin_popcountll(value); } |
39 |
| -#endif |
40 |
| -} // namespace detail |
41 |
| - |
42 | 12 | // Investigate if we can replace this with
|
43 | 13 | // http://www.boost.org/doc/libs/1_64_0/libs/dynamic_bitset/dynamic_bitset.html
|
44 | 14 | template <typename DataT>
|
@@ -70,7 +40,7 @@ class BitIterator : public boost::iterator_facade<BitIterator<DataT>,
|
70 | 40 |
|
71 | 41 | difference_type distance_to(const BitIterator &other) const
|
72 | 42 | {
|
73 |
| - return detail::countOnes(m_value) - detail::countOnes(other.m_value); |
| 43 | + return std::popcount(m_value) - std::popcount(other.m_value); |
74 | 44 | }
|
75 | 45 |
|
76 | 46 | bool equal(const BitIterator &other) const { return m_value == other.m_value; }
|
|
0 commit comments