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 12:00:35 PDT 2011
On 2011-05-27 11:51, Vladimir Panteleev wrote:
> On Fri, 27 May 2011 21:29:10 +0300, KennyTM~ <kennytm at gmail.com> wrote:
> > On May 28, 11 02: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?
> >
> > You mean std.array.join? The 2-argument overload has specialization for
> > strings
> > (https://github.com/D-Programming-Language/phobos/blob/master/std/array.d
> > #L966).
> >
> > static if (isForwardRange!RoR && hasLength!RoR
> >
> > && (hasLength!(ElementType!RoR) ||
> >
> > isSomeString!(ElementType!RoR))
> > // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> >
> > && hasLength!R)
> >
> > It doesn't exist for the 1-argument overload though.
>
> Thanks! But it looks like the 2-argument overload is broken too. It
> doesn't check if the separator is a string, so that branch isn't taken for
> join(string[], string). In fact, it doesn't work at all when the second
> argument is an iterator with length:
>
> C:\Soft\dmd2\src\phobos\std\array.d(778): Error: template
> std.algorithm.copy(Range1,Range2) if (isInputRange!(Range1) &&
> isOutputRange!(Range2,ElementType!(Range1))) does not match any function
> template declaration
> C:\Soft\dmd2\src\phobos\std\array.d(778): Error: template
> std.algorithm.copy(Range1,Range2) if (isInputRange!(Range1) &&
> isOutputRange!(Range2,ElementType!(Range1))) cannot deduce template
> function from argument types !()(Result,string)
> test26.d(9): Error: template instance
> std.array.join!(string[],Map!(result,string)) error instantiating
>
> Program:
>
> import std.array;
> import std.algorithm;
>
> void main()
> {
> string[] arr;
> string sep;
>
> join(arr, map!"a"(sep));
> }
Create a bug report and I'll look into it.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list