Using enum types
Meta
jared771 at gmail.com
Tue Dec 5 00:17:58 UTC 2017
On Monday, 4 December 2017 at 22:34:41 UTC, helxi wrote:
> Why can't enums be used as types in this (simplified) example?
>
> enum Positivity
> {
> Positive,
> Negative
> }
>
> struct Wave
> {
> public:
> Positivity slope;
> }
>
> enum Waves
> {
> Sin = Wave(Positivity.Positive),
> Cos = Wave(Positivity.Negative)
> }
>
> int nth_value(T : Waves)(int n);
>
> int nth_value(T : Waves.Sin)(int n)
> {
> return n % 2 ? 1 : -1;
> }
>
> int nth_value(T : Waves.Cos)(int n)
> {
> return n % 2 ? -1 : 1;
> }
We Adam said, Waves.Sin and Waves.Cos are values, while Waves
itself is the type. You want to do the following:
int nth_value(Waves w: Waves.Sin)(int n)
{
//Etc.
}
At least I *think* that's what you want. I'm on mobile and dpaste
is down so I have no way to double check the syntax, which I can
never remember.
More information about the Digitalmars-d-learn
mailing list