Convert a single element into a range

Ali Çehreli acehreli at yahoo.com
Thu Nov 30 22:52:33 UTC 2017


On 11/30/2017 02:47 PM, A Guy With a Question wrote:
> This is probably a dumb question, but what I did looks ugly. Is there a 
> way (preferably a one liner) to convert a single element, like an int or 
> char or bool, into a range?

import std.range;

void main() {
     auto r = only(42);
     static assert(isInputRange!(typeof(r)));
}

Ali


More information about the Digitalmars-d-learn mailing list