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// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
3
4#ifndef TETL_BIT_HAS_SINGLE_BIT_HPP
5#define TETL_BIT_HAS_SINGLE_BIT_HPP
6
7#include <etl/_bit/popcount.hpp>
8#include <etl/_concepts/builtin_unsigned_integer.hpp>
9
10namespace etl {
11
12/// \brief Checks if x is an integral power of two.
13///
14/// \details This overload only participates in overload resolution if T is an
15/// unsigned integer type (that is, unsigned char, unsigned short, unsigned int,
16/// unsigned long, unsigned long long, or an extended unsigned integer type).
17///
18/// \returns true if x is an integral power of two; otherwise false.
19///
20/// \ingroup bit
21template <etl::builtin_unsigned_integer UInt>
22[[nodiscard]] constexpr auto has_single_bit(UInt x) noexcept -> bool
23{
24 return etl::popcount(x) == 1;
25}
26
27} // namespace etl
28
29#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:22
Definition adjacent_find.hpp:9