Skip to content

Commit 7c99217

Browse files
committed
Avoid conflicting constructors for unsigned types
1 parent 0a4ff64 commit 7c99217

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

num/__private/unsigned_integer_macros.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,6 @@ class Tuple;
9494
*/ \
9595
constexpr inline T() noexcept = default; \
9696
\
97-
/** Construction from the underlying primitive type. \
98-
*/ \
99-
template <std::same_as<PrimitiveT> P> /* Prevent implicit conversions. */ \
100-
constexpr inline T(P val) noexcept : primitive_value(val) {} \
101-
\
10297
/** Assignment from the underlying primitive type. \
10398
*/ \
10499
template <std::same_as<PrimitiveT> P> /* Prevent implicit conversions. */ \

num/unsigned_integer.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,46 @@ namespace sus::num {
3030
/// A 32-bit unsigned integer.
3131
struct u32 final {
3232
_sus__unsigned_impl(u32, /*PrimitiveT=*/uint32_t, /*SignedT=*/i32);
33+
34+
/** Construction from the underlying primitive type.
35+
*/
36+
template <std::same_as<decltype(primitive_value)>
37+
P> // Prevent implicit conversions.
38+
constexpr inline u32(P val) noexcept : primitive_value(val) {}
3339
};
3440

3541
/// An 8-bit unsigned integer.
3642
struct u8 final {
3743
_sus__unsigned_impl(u8, /*PrimitiveT=*/uint8_t, /*SignedT=*/i8);
44+
45+
/** Construction from the underlying primitive type.
46+
*/
47+
template <std::same_as<decltype(primitive_value)>
48+
P> // Prevent implicit conversions.
49+
constexpr inline u8(P val) noexcept : primitive_value(val) {}
3850
};
3951

4052
/// A 16-bit unsigned integer.
4153
struct u16 final {
4254
_sus__unsigned_impl(u16, /*PrimitiveT=*/uint16_t, /*SignedT=*/i16);
55+
56+
/** Construction from the underlying primitive type.
57+
*/
58+
template <std::same_as<decltype(primitive_value)>
59+
P> // Prevent implicit conversions.
60+
constexpr inline u16(P val) noexcept : primitive_value(val) {}
4361
};
4462

4563
/// A 64-bit unsigned integer.
4664
struct u64 final {
4765
_sus__unsigned_impl(u64, /*PrimitiveT=*/uint64_t,
4866
/*SignedT=*/i64);
67+
68+
/** Construction from the underlying primitive type.
69+
*/
70+
template <std::same_as<decltype(primitive_value)>
71+
P> // Prevent implicit conversions.
72+
constexpr inline u64(P val) noexcept : primitive_value(val) {}
4973
};
5074

5175
/// A pointer-sized unsigned integer.

0 commit comments

Comments
 (0)