tetl
0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
countr_one.hpp
Go to the documentation of this file.
1
// SPDX-License-Identifier: BSL-1.0
2
// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
3
4
#
ifndef
TETL_BIT_COUNTR_ONE_HPP
5
#
define
TETL_BIT_COUNTR_ONE_HPP
6
7
#
include
<
etl
/
_bit
/
test_bit
.
hpp
>
8
#
include
<
etl
/
_concepts
/
builtin_unsigned_integer
.
hpp
>
9
#
include
<
etl
/
_limits
/
numeric_limits
.
hpp
>
10
11
namespace
etl
{
12
13
/// \brief Returns the number of consecutive 1 bits in the value of x, starting
14
/// from the least significant bit ("right").
15
///
16
/// \details This overload only participates in overload resolution if UInt is an
17
/// unsigned integer type (that is, unsigned char, unsigned short, unsigned int,
18
/// unsigned long, unsigned long long, or an extended unsigned integer type).
19
///
20
/// \returns The number of consecutive 1 bits in the value of x, starting from
21
/// the least significant bit.
22
///
23
/// \ingroup bit
24
template
<
etl
::builtin_unsigned_integer UInt>
25
[[nodiscard]]
constexpr
auto
countr_one
(UInt x)
noexcept
->
int
26
{
27
auto
totalBits =
etl
::
numeric_limits
<UInt>::digits;
28
auto
result = 0;
29
while
(result != totalBits) {
30
if
(
not
etl
::test_bit(x,
static_cast
<UInt>(result))) {
31
break
;
32
}
33
++result;
34
}
35
return
result;
36
}
37
38
}
// namespace etl
39
40
#
endif
// TETL_BIT_COUNTR_ONE_HPP
etl::countr_one
constexpr auto countr_one(UInt x) noexcept -> int
Returns the number of consecutive 1 bits in the value of x, starting from the least significant bit (...
Definition
countr_one.hpp:25
etl
Definition
adjacent_find.hpp:9
etl::numeric_limits
Definition
numeric_limits.hpp:18
include
etl
_bit
countr_one.hpp
Generated on Sun Sep 7 2025 19:14:48 for tetl by
1.9.8