tetl
0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
set_bit.hpp
Go to the documentation of this file.
1
// SPDX-License-Identifier: BSL-1.0
2
3
#ifndef TETL_BIT_SET_BIT_HPP
4
#define TETL_BIT_SET_BIT_HPP
5
6
#include <
etl/_concepts/builtin_unsigned_integer.hpp
>
7
#include <
etl/_contracts/check.hpp
>
8
#include <
etl/_cstddef/size_t.hpp
>
9
#include <
etl/_limits/numeric_limits.hpp
>
10
11
namespace
etl
{
12
18
template
<etl::builtin_
unsigned
_
int
eger UInt>
19
[[nodiscard]]
constexpr
auto
set_bit
(UInt word, UInt pos)
noexcept
-> UInt
20
{
21
TETL_PRECONDITION
(
static_cast<
int
>
(pos) <
etl::numeric_limits<UInt>::digits
);
22
return
static_cast<
UInt
>
(word |
static_cast<
UInt
>
(UInt(1) << pos));
23
}
24
30
template
<etl::builtin_
unsigned
_
int
eger UInt>
31
[[nodiscard]]
constexpr
auto
set_bit
(UInt word, UInt pos,
bool
value) -> UInt
32
{
33
TETL_PRECONDITION
(
static_cast<
int
>
(pos) <
etl::numeric_limits<UInt>::digits
);
34
return
static_cast<
UInt
>
((word &
static_cast<
UInt
>
(~(UInt(1) << pos))) | (UInt(value) << pos));
35
}
36
41
template
<etl::
size_t
Pos, etl::builtin_
unsigned
_
int
eger UInt>
42
[[nodiscard]]
constexpr
auto
set_bit
(UInt word)
noexcept
-> UInt
43
{
44
static_assert
(Pos < etl::numeric_limits<UInt>::digits);
45
return
etl::set_bit
(word,
static_cast<
UInt
>
(Pos));
46
}
47
52
template
<etl::
size_t
Pos, etl::builtin_
unsigned
_
int
eger UInt>
53
[[nodiscard]]
constexpr
auto
set_bit
(UInt word,
bool
value)
noexcept
-> UInt
54
{
55
static_assert
(Pos < etl::numeric_limits<UInt>::digits);
56
return
etl::set_bit
(word,
static_cast<
UInt
>
(Pos), value);
57
}
58
59
}
// namespace etl
60
61
#endif
// TETL_BIT_SET_BIT_HPP
builtin_unsigned_integer.hpp
check.hpp
TETL_PRECONDITION
#define TETL_PRECONDITION(...)
Definition
check.hpp:16
etl::set_bit
constexpr auto set_bit(UInt word, UInt pos) noexcept -> UInt
Set bit at position pos.
Definition
set_bit.hpp:19
etl
Definition
adjacent_find.hpp:8
numeric_limits.hpp
size_t.hpp
etl::numeric_limits::digits
static constexpr int digits
Definition
numeric_limits.hpp:24
include
etl
_bit
set_bit.hpp
Generated on Sat Mar 8 2025 16:19:59 for tetl by
1.14.0