Using enum types

helxi brucewayneshit at gmail.com
Mon Dec 4 22:34:41 UTC 2017


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;
}

void main()
{
	import std.stdio;

	writeln(nth_value!(Waves.Sin)(1));
}


More information about the Digitalmars-d-learn mailing list