On 2011-05-27 11:25, Vladimir Panteleev wrote: > On Fri, 27 May 2011 21:18:40 +0300, Jonathan M Davis <jmdavisp...@gmx.com> > > wrote: > > On 2011-05-27 11:05, Vladimir Panteleev wrote: > >> Why hasLength!string is false: > >> https://github.com/D-Programming-Language/phobos/blob/96941d5384a5fee302 > >> df/ 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. > > Wow, you sure took your time to bash my stupid suggestion :) I agree > completely, TBH I only added that because I didn't want my post to look > like a complaint without even an attempt to suggest a solution. > > As long as std.array.join & co. don't do a character-by-character copy for > strings, I'm happy. Still, putting isSomeString in std.array/std.range > checks seems like a hack to me.
In some cases, where two strings are of the same type, character by character processing can be avoided (it depends on the function), but in many cases, it can't be, and if the string types differ, it definitely can't be. So, it may be that some functions could be improved to handle string processing better, but in the general case, the strings have to be decoded to process them, which means operating on them character by character. But if you notice a function which could and should do a better job with strings and you have an improved implementation, please create a pull request for it. There _are_ quite a few functions, however, which are optimized for string-processing. - Jonathan M Davis