4#ifndef TETL_BIT_SET_BIT_HPP
5#define TETL_BIT_SET_BIT_HPP
7#include <etl/_concepts/builtin_unsigned_integer.hpp>
8#include <etl/_contracts/check.hpp>
9#include <etl/_cstddef/size_t.hpp>
10#include <etl/_limits/numeric_limits.hpp>
19template <
etl::builtin_unsigned_integer UInt>
20[[nodiscard]]
constexpr auto set_bit(UInt word, UInt pos)
noexcept -> UInt
22 TETL_PRECONDITION(
static_cast<
int>(pos) < etl::numeric_limits<UInt>::digits);
23 return static_cast<UInt>(word |
static_cast<UInt>(UInt(1) << pos));
31template <
etl::builtin_unsigned_integer UInt>
32[[nodiscard]]
constexpr auto set_bit(UInt word, UInt pos,
bool value) -> UInt
34 TETL_PRECONDITION(
static_cast<
int>(pos) < etl::numeric_limits<UInt>::digits);
35 return static_cast<UInt>((word &
static_cast<UInt>(~(UInt(1) << pos))) | (UInt(value) << pos));
42template <
etl::size_t Pos,
etl::builtin_unsigned_integer UInt>
43[[nodiscard]]
constexpr auto set_bit(UInt word)
noexcept -> UInt
46 return etl::set_bit(word,
static_cast<UInt>(Pos));
53template <
etl::size_t Pos,
etl::builtin_unsigned_integer UInt>
54[[nodiscard]]
constexpr auto set_bit(UInt word,
bool value)
noexcept -> UInt
57 return etl::set_bit(word,
static_cast<UInt>(Pos), value);
constexpr auto set_bit(UInt word, UInt pos) noexcept -> UInt
Set bit at position pos.
Definition set_bit.hpp:20
constexpr auto set_bit(UInt word, UInt pos, bool value) -> UInt
Set bit at position pos to value.
Definition set_bit.hpp:32
constexpr auto set_bit(UInt word) noexcept -> UInt
Set bit at position Pos
Definition set_bit.hpp:43
constexpr auto set_bit(UInt word, bool value) noexcept -> UInt
Set bit at position Pos to value.
Definition set_bit.hpp:54
Definition adjacent_find.hpp:9
Definition numeric_limits.hpp:18