C++ Logo

std-proposals

Advanced search

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

From: connor horman <chorman64_at_[hidden]>
Date: Sat, 1 Oct 2022 19:13:42 -0400
Keep in mind also that the max value of any enumerator may not be the
maximum (or minimum) value the enum takes on. For example, an enum that is
already a bitfield, or a type like std::byte.

On Sat, 1 Oct 2022 at 17:12, Gergely Nagy via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> You can already do it on the underlying type
>> https://en.cppreference.com/w/cpp/types/underlying_type
>
>
> I don't think this is relevant at all. How do you tell what is the highest
> possible enum value using underlying_type for this:
>
> enum class A : int {
> x, y
> };
>
> Thiago Macieira via Std-Proposals <std-proposals_at_[hidden]> ezt
> írta (időpont: 2022. szept. 25., V, 16:54):
>
>> 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.
>>
>> --
>> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
>> Software Architect - Intel DCAI Cloud Engineering
>>
>>
>>
>> --
>> Std-Proposals mailing list
>> Std-Proposals_at_[hidden]
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2022-10-01 23:13:54