C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Support std::numeric_limits for enums

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Sun, 25 Sep 2022 10:55:18 -0400
On Sun, Sep 25, 2022 at 10:54 AM Thiago Macieira via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> On Sunday, 25 September 2022 06:15:33 PDT Gergely Nagy via Std-Proposals
> wrote:
> > This would be a really basic and quite useful feature. min() and max() for
> > enums would make it possible to create generic enum sets using std::bitset,
>
> You can already do it on the underlying type
> https://en.cppreference.com/w/cpp/types/underlying_type
>
> > Additionally there could be an is_sparse() member that would tell if there
> > is any gap, or even some gap statistics, so one could statically use
> > std::unordered_set for very sparse enums and something more lightweight
> > (like bitset) for dense ones.
>
> That's reflection, not numeric_limits.

That should not be to say that we shouldn't have higher-level
metafunctions to compute these kinds of aspects of an enumeration than
saying "build it yourself with reflection whenever we bother to give
that." But they should not be called "numeric_limits".

Received on 2022-09-25 14:56:17