Skip to content

Commit 54ac725

Browse files
<__msvc_int128.hpp>: Move UDLs to test code (#3252)
Co-authored-by: Casey Carter <[email protected]>
1 parent 8086a2b commit 54ac725

File tree

2 files changed

+203
-193
lines changed

2 files changed

+203
-193
lines changed

stl/inc/__msvc_int128.hpp

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,109 +1420,6 @@ struct common_type<_Unsigned128, _Signed128> {
14201420
using type = _Unsigned128;
14211421
};
14221422

1423-
inline namespace literals {
1424-
inline namespace _Int128_literals {
1425-
namespace _Int128_detail {
1426-
enum class _U128_parse_status : unsigned char {
1427-
_Valid,
1428-
_Overflow,
1429-
_Invalid,
1430-
};
1431-
1432-
struct _U128_parse_result {
1433-
_U128_parse_status _Status_code;
1434-
_Unsigned128 _Value;
1435-
};
1436-
1437-
_NODISCARD _CONSTEVAL unsigned int _Char_to_digit(const char _Ch) noexcept {
1438-
if (_Ch >= '0' && _Ch <= '9') {
1439-
return static_cast<unsigned int>(_Ch - '0');
1440-
}
1441-
1442-
if (_Ch >= 'A' && _Ch <= 'F') {
1443-
return static_cast<unsigned int>(_Ch - 'A' + 10);
1444-
}
1445-
1446-
if (_Ch >= 'a' && _Ch <= 'f') {
1447-
return static_cast<unsigned int>(_Ch - 'a' + 10);
1448-
}
1449-
1450-
return static_cast<unsigned int>(-1);
1451-
}
1452-
1453-
template <unsigned int _Base, char... _Chars>
1454-
struct _Parse_u128_impl {
1455-
_NODISCARD static _CONSTEVAL _U128_parse_result _Parse() noexcept {
1456-
if constexpr (sizeof...(_Chars) == 0) {
1457-
return {_U128_parse_status::_Valid, 0};
1458-
} else {
1459-
constexpr char _Char_seq[]{_Chars...};
1460-
constexpr auto _U128_max = (numeric_limits<_Unsigned128>::max)();
1461-
1462-
_Unsigned128 _Val{};
1463-
for (const char _Ch : _Char_seq) {
1464-
if (_Ch == '\'') {
1465-
continue;
1466-
}
1467-
1468-
const unsigned int _Digit = _Char_to_digit(_Ch);
1469-
if (_Digit == static_cast<unsigned int>(-1)) {
1470-
return {_U128_parse_status::_Invalid, _Unsigned128{}};
1471-
}
1472-
1473-
if (_Val > _U128_max / _Base || _Base * _Val > _U128_max - _Digit) {
1474-
return {_U128_parse_status::_Overflow, _Unsigned128{}};
1475-
}
1476-
1477-
_Val = _Base * _Val + _Digit;
1478-
}
1479-
return {_U128_parse_status::_Valid, _Val};
1480-
}
1481-
}
1482-
};
1483-
1484-
template <char... _Chars>
1485-
struct _Parse_u128 : _Parse_u128_impl<10, _Chars...> {};
1486-
1487-
template <char... _Chars>
1488-
struct _Parse_u128<'0', 'X', _Chars...> : _Parse_u128_impl<16, _Chars...> {};
1489-
1490-
template <char... _Chars>
1491-
struct _Parse_u128<'0', 'x', _Chars...> : _Parse_u128_impl<16, _Chars...> {};
1492-
1493-
template <char... _Chars>
1494-
struct _Parse_u128<'0', 'B', _Chars...> : _Parse_u128_impl<2, _Chars...> {};
1495-
1496-
template <char... _Chars>
1497-
struct _Parse_u128<'0', 'b', _Chars...> : _Parse_u128_impl<2, _Chars...> {};
1498-
1499-
template <char... _Chars>
1500-
struct _Parse_u128<'0', _Chars...> : _Parse_u128_impl<8, _Chars...> {};
1501-
} // namespace _Int128_detail
1502-
1503-
template <char... _Chars>
1504-
_NODISCARD _CONSTEVAL _Unsigned128 operator"" __u128() noexcept {
1505-
constexpr auto _Parsed_result = _Int128_detail::_Parse_u128<_Chars...>::_Parse();
1506-
static_assert(_Parsed_result._Status_code != _Int128_detail::_U128_parse_status::_Invalid,
1507-
"Invalid characters in the integer literal");
1508-
static_assert(_Parsed_result._Status_code != _Int128_detail::_U128_parse_status::_Overflow,
1509-
"The integer literal is too large for an unsigned 128-bit number");
1510-
return _Parsed_result._Value;
1511-
}
1512-
1513-
template <char... _Chars>
1514-
_NODISCARD _CONSTEVAL _Signed128 operator"" __i128() noexcept {
1515-
constexpr auto _Parsed_result = _Int128_detail::_Parse_u128<_Chars...>::_Parse();
1516-
static_assert(_Parsed_result._Status_code != _Int128_detail::_U128_parse_status::_Invalid,
1517-
"Invalid characters in the integer literal");
1518-
static_assert(_Parsed_result._Status_code != _Int128_detail::_U128_parse_status::_Overflow
1519-
&& _Parsed_result._Value._Word[1] < (static_cast<uint64_t>(1) << 63),
1520-
"The integer literal is too large for a signed 128-bit number");
1521-
return static_cast<_Signed128>(_Parsed_result._Value);
1522-
}
1523-
} // namespace _Int128_literals
1524-
} // namespace literals
1525-
15261423
#undef _STL_128_INTRINSICS
15271424
#undef _STL_128_DIV_INTRINSICS
15281425

0 commit comments

Comments
 (0)