Can somebody give me an example of using an "open interval for the upper limit of a range"?

Ali Çehreli acehreli at yahoo.com
Tue Mar 11 17:28:17 UTC 2025


On 3/11/25 9:56 AM, WhatMeWorry wrote:

 > In D language, an open interval for the upper limit is indicated by
 > using a parenthesis ")" at the end of the range expression, meaning the
 > upper bound value itself is not included in the interval.

The only place in D that I know of where that's the case is the 
std.random module. The following template argument has the quoted effect:

import std.stdio;
import std.random;

void main() {
     foreach (_; 0 .. 10) {
         writeln(uniform!"[)"(0, 3));
     }
}

The value 3 should never be printed there. (But "[)" happens to be the 
default for it anyway.)

Ali



More information about the Digitalmars-d-learn mailing list