Date: Mon, 17 Mar 2025 13:51:06 +1300
Hi Filip.
I thought about this not so long ago.
You actually can do almost the same, using hashes.
Something like:
constexpr int MakeHash(std::string);
enum class Strings
{
ThisIsAnExample = MakeHash("This is an Example"),
ThisIsATest = MakeHash("This is a test")
}
it would work and you can compare strings with enum values, you can convert
string to enum and so on.
But again, it would require some functions specific to this enum.
Kind regards,
Dmitrii Shabalin.
сб, 15 мар. 2025 г. в 05:27, Filip via Std-Proposals <
std-proposals_at_[hidden]>:
> Hi everyone, in other thread “lambdas in enums”
> I have talked about enums having different underlying type.
> I’m starting a new thread to organise the features.
>
> ------
>
> I would like to use enums with different underlying type.
> I have considered using inheritance style list:
>
> ```
> enum struct Foo : int, float {
> A {3, 0.f},
> B { …, 1.f} // `…` to indicate that following element should
> follow increment from previous value
> };
> ```
>
> However it does pose several problems so other possibility is to use only
> one type and an initializer list.
> Type used should have:
> + constexpr constructor,
> + constexpr default constructor
> + constexpr operator ++ const [if the values are not provided, could be
> explicitly deleted to force user to implement all values]
>
> ```
> enum struct Foo : someType {
> A{ ~initializer list for `someType`~ },
> B, // by default it calls ++ operator on previous
> enum value
> C = default, // this could be an explicit way to show that enum
> generation should increment the value
> D {} // default initialisation of someType
> };
> ```
>
> The second option of new syntax allows us to easily access different
> values that we want to store.
> ```
> Foo::A // is equivalent to static constexpr someType
> ```
>
> Additional concerns:
> + sizeof(Foo) should be consistent with current enum sizeof functionality
> and return sizeof(someType).
> + initializer list is probably the only way to have multiple values per
> symbol
> + different enum values are not compared to each other when created not
> now so should not be with custom objects.
> + template enum struct should be possible in the future:
>
> ```
> template <typename T, typename U>
> enum struct Bar : std::pair<T, U>{};
> ```
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
I thought about this not so long ago.
You actually can do almost the same, using hashes.
Something like:
constexpr int MakeHash(std::string);
enum class Strings
{
ThisIsAnExample = MakeHash("This is an Example"),
ThisIsATest = MakeHash("This is a test")
}
it would work and you can compare strings with enum values, you can convert
string to enum and so on.
But again, it would require some functions specific to this enum.
Kind regards,
Dmitrii Shabalin.
сб, 15 мар. 2025 г. в 05:27, Filip via Std-Proposals <
std-proposals_at_[hidden]>:
> Hi everyone, in other thread “lambdas in enums”
> I have talked about enums having different underlying type.
> I’m starting a new thread to organise the features.
>
> ------
>
> I would like to use enums with different underlying type.
> I have considered using inheritance style list:
>
> ```
> enum struct Foo : int, float {
> A {3, 0.f},
> B { …, 1.f} // `…` to indicate that following element should
> follow increment from previous value
> };
> ```
>
> However it does pose several problems so other possibility is to use only
> one type and an initializer list.
> Type used should have:
> + constexpr constructor,
> + constexpr default constructor
> + constexpr operator ++ const [if the values are not provided, could be
> explicitly deleted to force user to implement all values]
>
> ```
> enum struct Foo : someType {
> A{ ~initializer list for `someType`~ },
> B, // by default it calls ++ operator on previous
> enum value
> C = default, // this could be an explicit way to show that enum
> generation should increment the value
> D {} // default initialisation of someType
> };
> ```
>
> The second option of new syntax allows us to easily access different
> values that we want to store.
> ```
> Foo::A // is equivalent to static constexpr someType
> ```
>
> Additional concerns:
> + sizeof(Foo) should be consistent with current enum sizeof functionality
> and return sizeof(someType).
> + initializer list is probably the only way to have multiple values per
> symbol
> + different enum values are not compared to each other when created not
> now so should not be with custom objects.
> + template enum struct should be possible in the future:
>
> ```
> template <typename T, typename U>
> enum struct Bar : std::pair<T, U>{};
> ```
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
Received on 2025-03-17 00:51:21