Skip to content

Commit 006cef9

Browse files
committed
🎨 Don't throw away argument to smallest_uint
Problem: - `smallest_uint` returns zero rather than the template argument it is passed. Solution: - Return the argument passed.
1 parent be8e1b2 commit 006cef9

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

docs/bit.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ integral type that will fit a compile-time value.
125125

126126
[source,cpp]
127127
----
128-
constexpr auto x = stdx::smallest_uint<42>(); // std::uint8_t{}
129-
constexpr auto y = stdx::smallest_uint<1337>(); // std::uint16_t{}
128+
constexpr auto x = stdx::smallest_uint<42>(); // std::uint8_t{42}
129+
constexpr auto y = stdx::smallest_uint<1337>(); // std::uint16_t{1337}
130130
131131
// smallest_uint_t is the type of a call to smallest_uint
132132
using T = stdx::smallest_uint_t<1337>; // std::uint16_t

include/stdx/bit.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,13 +421,13 @@ template <typename T> constexpr auto bit_size() -> std::size_t {
421421

422422
template <std::size_t N> CONSTEVAL auto smallest_uint() {
423423
if constexpr (N <= std::numeric_limits<std::uint8_t>::digits) {
424-
return std::uint8_t{};
424+
return std::uint8_t{N};
425425
} else if constexpr (N <= std::numeric_limits<std::uint16_t>::digits) {
426-
return std::uint16_t{};
426+
return std::uint16_t{N};
427427
} else if constexpr (N <= std::numeric_limits<std::uint32_t>::digits) {
428-
return std::uint32_t{};
428+
return std::uint32_t{N};
429429
} else {
430-
return std::uint64_t{};
430+
return std::uint64_t{N};
431431
}
432432
}
433433

0 commit comments

Comments
 (0)