diff options
| author | Eugen Wissner <belka@caraus.de> | 2026-08-06 23:12:01 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2026-08-06 23:12:01 +0200 |
| commit | eaf5934f81dcd8ce5705f13b651d7b93ca8c459f (patch) | |
| tree | 890d2d69a3e80d1d3a64e69cb4af69a190986c5f /boot/result.cc | |
| parent | b2dee14873402ee3d13d59ae5579593796ea862f (diff) | |
| download | elna-eaf5934f81dcd8ce5705f13b651d7b93ca8c459f.tar.gz | |
Implement compile time castings for integers
Diffstat (limited to 'boot/result.cc')
| -rw-r--r-- | boot/result.cc | 26 |
1 files changed, 2 insertions, 24 deletions
diff --git a/boot/result.cc b/boot/result.cc index e9090de..30b4576 100644 --- a/boot/result.cc +++ b/boot/result.cc @@ -328,28 +328,6 @@ namespace elna::boot return *this; } - std::optional<std::ptrdiff_t> integer_literal::to_signed() const - { - if (is_negative_minimum(sizeof(std::ptrdiff_t) * CHAR_BIT)) - { - return std::numeric_limits<ptrdiff_t>::min(); - } - auto [written, rop] = export_to_words<std::ptrdiff_t>(); - - if (written > 1 || rop < 0) - { - return std::nullopt; - } - return is_negative() ? -rop : rop; - } - - std::optional<std::size_t> integer_literal::to_unsigned() const - { - auto [written, rop] = export_to_words<std::size_t>(); - - return written > 1 ? std::nullopt : std::make_optional(rop); - } - bool integer_literal::fit_into(const std::size_t target_size) { if (fits_in(target_size * CHAR_BIT)) @@ -485,14 +463,14 @@ std::size_t std::hash<elna::boot::integer_literal>::operator()(const elna::boot: { if (key.is_signed()) { - if (auto converted = key.to_signed()) + if (auto converted = key.try_to<std::ptrdiff_t>()) { return std::hash<std::ptrdiff_t>{}(*converted); } } else { - if (auto converted = key.to_unsigned()) + if (auto converted = key.try_to<std::size_t>()) { return std::hash<std::size_t>{}(*converted); } |
