Date: Mon, 18 Aug 2025 19:24:15 +0200
I should probably have made that
inline constexpr struct final {} _Max;
/Ted
Den 2025-08-18 kl. 19:17, skrev Ted Lyngmo:
> Den 2025-07-18 kl. 11:15, skrev Frederick Virchanza Gotham via Std-
> Proposals:
>> And it's annoying when a compiler emits a warning for "-1 == n" to say
>> that I'm comparing signed with unsigned.
>>
>> I wonder could we standardise some shorthand for this?
>
> `if (n == -1uz)` - but MSVC warns about that.
>
> Another way that you could define yourself (except you shouldn't use a
> reserved identifier):
> ```
> inline constexpr struct {} _Max;
>
> template <class T>
> constexpr auto operator<=>(decltype(_Max), T other) {
> return std::numeric_limits<T>::max() <=> other;
> }
> template <class T>
> constexpr bool operator==(decltype(_Max), T other) {
> return std::numeric_limits<T>::max() == other;
> }
> ```
> But I don't really see a compelling reason _not_ to use `npos` which is
> defined specifically for this situation. Sure, `_Max` is shorter, but
> still.
>
> Br,
> Ted
>
inline constexpr struct final {} _Max;
/Ted
Den 2025-08-18 kl. 19:17, skrev Ted Lyngmo:
> Den 2025-07-18 kl. 11:15, skrev Frederick Virchanza Gotham via Std-
> Proposals:
>> And it's annoying when a compiler emits a warning for "-1 == n" to say
>> that I'm comparing signed with unsigned.
>>
>> I wonder could we standardise some shorthand for this?
>
> `if (n == -1uz)` - but MSVC warns about that.
>
> Another way that you could define yourself (except you shouldn't use a
> reserved identifier):
> ```
> inline constexpr struct {} _Max;
>
> template <class T>
> constexpr auto operator<=>(decltype(_Max), T other) {
> return std::numeric_limits<T>::max() <=> other;
> }
> template <class T>
> constexpr bool operator==(decltype(_Max), T other) {
> return std::numeric_limits<T>::max() == other;
> }
> ```
> But I don't really see a compelling reason _not_ to use `npos` which is
> defined specifically for this situation. Sure, `_Max` is shorter, but
> still.
>
> Br,
> Ted
>
Received on 2025-08-18 17:24:18