tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
has_single_bit.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_BIT_HAS_SINGLE_BIT_HPP
4#define TETL_BIT_HAS_SINGLE_BIT_HPP
5
8
9namespace etl {
10
20template <etl::builtin_unsigned_integer UInt>
21[[nodiscard]] constexpr auto has_single_bit(UInt x) noexcept -> bool
22{
23 return etl::popcount(x) == 1;
24}
25
26} // namespace etl
27
28#endif // TETL_BIT_HAS_SINGLE_BIT_HPP
constexpr auto has_single_bit(UInt x) noexcept -> bool
Checks if x is an integral power of two.
Definition has_single_bit.hpp:21
constexpr auto popcount(UInt val) noexcept -> int
Returns the number of 1 bits in the value of x.
Definition popcount.hpp:38
Definition adjacent_find.hpp:8