www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Convert a single element into a range

reply A Guy With a Question <aguywithanquestion gmail.com> writes:
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?
Nov 30 2017
parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
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
Nov 30 2017
parent A Guy With a Question <aguywithanquestion gmail.com> writes:
On Thursday, 30 November 2017 at 22:52:33 UTC, Ali Çehreli wrote:
 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
Excellent!
Nov 30 2017