std.string.join & co. do a character-by-character copy because hasLength!string is false

Jonathan M Davis jmdavisProg at gmx.com
Fri May 27 11:18:40 PDT 2011


On 2011-05-27 11:05, Vladimir Panteleev wrote:
> Why hasLength!string is false:
> https://github.com/D-Programming-Language/phobos/blob/96941d5384a5fee302df/
> std/range.d#L767
> 
> Would it make sense to introduce a hasOpaqueLength oslt. to fix this?

Um. Why? What would it give you? hasLength is intended for range-based stuff. 
and and any arrays of char or wchar are ranges of dchar, so they don't have a 
length property as far as ranges are concerned. If you want your template to 
work with any of the string types, then just use isSomeString to check whether 
it's a string. What would hasOpaqueLength do? What would it get you? Yes, the 
situation with char and wchar technically having a length property but having 
hasLength be false for them is a bit odd, but it works, and hasLength does 
exactly what it's supposed to - check whether the type has a length property 
for use with ranges. And char and wchar arrays don't.

- Jonathan M Davis


More information about the Digitalmars-d mailing list