Subrange type

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Jan 27 22:00:13 UTC 2020


On Mon, Jan 27, 2020 at 09:15:58PM +0000, Herbert via Digitalmars-d-learn wrote:
[...]
> How can I have a function parameter with this type (DiceValue)?

Just take an integer type and add a contract that enforces range. For
example:

	auto myFunc(int diceValue)
		in (diceValue >= 1 && diceValue <= 6)
	{
		// do stuff here
	}


T

-- 
Which is worse: ignorance or apathy? Who knows? Who cares? -- Erich Schubert


More information about the Digitalmars-d-learn mailing list