How to work with an "arbitrary input range"?

Jonathan M Davis jmdavisProg at gmx.com
Thu Oct 21 17:35:34 PDT 2010


On Thursday, October 21, 2010 17:13:32 Simen kjaeraas wrote:
> Jonathan M Davis <jmdavisProg at gmx.com> wrote:
> >> void fun( T )( T t ) if ( isInputRange!T && is( ElementType!T == dchar
> >> ) )
> >> {}
> > 
> > Though I'd suggest using Unqual!(ElementType!T).
> 
> You're right, of course.

It can be quite baffling to have a template constraint start failing on you 
(particularly when it's several levels deep) just because you ended up using it 
with const. That's one of the reason that I specifically tested const and 
immutable versions of the various types in the datetime code that I have up for 
review. Without that, it's far too easy to miss things like a necessary Unqual!
() and boom, your code doesn't work with const or immutable. Though I still 
haven't figured how to make SysTime immutable... (I think that it's because of 
the bug that makes postblit not work with const or immutable, but since the bug 
hasn't been fixed, I can't verify that...).

- Jonathan M Davis


More information about the Digitalmars-d mailing list