Date: Mon, 28 Jul 2025 10:15:08 +0200
On Mon, 28 Jul 2025, 04:23 Magnus Fromreide via Std-Proposals, <
std-proposals_at_[hidden]> wrote:
> On Fri, Jul 18, 2025 at 10:15:22AM +0100, Frederick Virchanza Gotham via
> Std-Proposals wrote:
> > Yes I realise that we have:
> >
> > std::numeric_limits<T>::max()
>
> Yes, std::numeric_limits<T> is annoyingly long and hard to get from a
> variable.
>
> When I need to use it I have found a little function like
>
> template <class T>
> constexpr std::numeric_limits<typename std::remove_cv<T>::type> bikeshed(T)
> { return { }; }
>
> to be helpful as
>
> bikeshed(n)::max() == n
>
> is simple to write.
>
P0437 proposed std::finite_max_v<T>.
Matthias Kretz and I plan to resurrect that proposal.
>
> > But I always do this:
> >
> > size_t n = my_string.find("bla bla");
> > if ( -1 == n ) DoSomething();
> >
> > I'm not keen on:
> >
> > size_t n = my_string.find("bla bla");
> > if ( std::numeric_limits<decltype(n)>::max() == n ) DoSomething();
> >
> > Nor am I keen on:
> >
> > size_t n = my_string.find("bla bla");
> > if ( string::npos == n ) DoSomething();
>
> Here I would write
>
> if (my_string.npos == n)
> DoSomething();
>
>
> > And it's annoying when a compiler emits a warning for "-1 == n" to say
> > that I'm comparing signed with unsigned.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
std-proposals_at_[hidden]> wrote:
> On Fri, Jul 18, 2025 at 10:15:22AM +0100, Frederick Virchanza Gotham via
> Std-Proposals wrote:
> > Yes I realise that we have:
> >
> > std::numeric_limits<T>::max()
>
> Yes, std::numeric_limits<T> is annoyingly long and hard to get from a
> variable.
>
> When I need to use it I have found a little function like
>
> template <class T>
> constexpr std::numeric_limits<typename std::remove_cv<T>::type> bikeshed(T)
> { return { }; }
>
> to be helpful as
>
> bikeshed(n)::max() == n
>
> is simple to write.
>
P0437 proposed std::finite_max_v<T>.
Matthias Kretz and I plan to resurrect that proposal.
>
> > But I always do this:
> >
> > size_t n = my_string.find("bla bla");
> > if ( -1 == n ) DoSomething();
> >
> > I'm not keen on:
> >
> > size_t n = my_string.find("bla bla");
> > if ( std::numeric_limits<decltype(n)>::max() == n ) DoSomething();
> >
> > Nor am I keen on:
> >
> > size_t n = my_string.find("bla bla");
> > if ( string::npos == n ) DoSomething();
>
> Here I would write
>
> if (my_string.npos == n)
> DoSomething();
>
>
> > And it's annoying when a compiler emits a warning for "-1 == n" to say
> > that I'm comparing signed with unsigned.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
Received on 2025-07-28 08:15:26