Iros
 
Loading...
Searching...
No Matches
bit_ceil.h
Go to the documentation of this file.
1#pragma once
2
4#include "di/meta/core.h"
5
6namespace di::bit {
7namespace detail {
9 template<concepts::UnsignedInteger T>
10 constexpr auto operator()(T value) const -> T {
11 if (value <= 1U) {
12 return T(1);
13 }
14 if constexpr (concepts::SameAs<T, decltype(+value)>) {
15 return T(1) << bit_width(T(value - 1));
16 } else {
17 // Ensure UB if the result cannot fit inside T. This is needed because
18 // T promotes to an int automatically.
20 return T(1U << (bit_width(T(value - 1)) + extra_offset) >> extra_offset);
21 }
22 }
23 };
24}
25
26constexpr inline auto bit_ceil = detail::BitCeilFunction {};
27}
28
29namespace di {
30using bit::bit_ceil;
31}
Definition core.h:114
Definition bit_proxy_reference.h:5
Definition bit_proxy_reference.h:5
constexpr auto bit_width
Definition bit_width.h:15
constexpr auto bit_ceil
Definition bit_ceil.h:26
Definition zstring_parser.h:9
Definition bit_ceil.h:8
constexpr auto operator()(T value) const -> T
Definition bit_ceil.h:10
Definition numeric_limits.h:7