Skip to content

Commit 3938872

Browse files
authored
Fix: mac compat of NodeBackendID cast (#358)
1 parent 720c83d commit 3938872

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/rdf4cpp/storage/identifier/NodeBackendID.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct alignas(uint64_t) NodeBackendID {
3131
};
3232

3333
public:
34-
NodeBackendID() noexcept = default;
34+
constexpr NodeBackendID() noexcept = default;
3535

3636
explicit constexpr NodeBackendID(underlying_type const underlying_id) noexcept : underlying_{underlying_id} {
3737
}
@@ -138,8 +138,9 @@ struct alignas(uint64_t) NodeBackendID {
138138
return underlying_;
139139
}
140140

141-
explicit constexpr operator underlying_type() const noexcept {
142-
return underlying_;
141+
template<std::unsigned_integral I> requires (sizeof(I) >= sizeof(underlying_type))
142+
explicit constexpr operator I() const noexcept {
143+
return static_cast<I>(underlying_);
143144
}
144145

145146
constexpr std::strong_ordering operator<=>(NodeBackendID const &other) const noexcept {
@@ -153,6 +154,9 @@ struct alignas(uint64_t) NodeBackendID {
153154

154155
static_assert(sizeof(NodeBackendID) == sizeof(uint64_t));
155156
static_assert(alignof(NodeBackendID) == alignof(uint64_t));
157+
static_assert(std::is_same_v<decltype(static_cast<uintptr_t>(NodeBackendID{})), uintptr_t>, "NodeBackendID must be convertible to uintptr_t");
158+
static_assert(std::is_same_v<decltype(static_cast<uint64_t>(NodeBackendID{})), uint64_t>, "NodeBackendID must be convertible to uint64_t");
159+
156160

157161
inline std::ostream &operator<<(std::ostream &os, NodeBackendID id) {
158162
if (id.is_literal()) {

0 commit comments

Comments
 (0)