www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Problem with std.array(std.regex.splitter())

reply bearophile <bearophileHUGS lycos.com> writes:
This D2 code:

import std.regex: splitter, regex;
import std.array: array;
void main() {
    array(splitter(", abc, de", regex(", *")));
}


Gives the errors:

test.d(4): Error: template std.array.array(Range) if (isForwardRange!(Range))
does not match any function template declaration
test.d(4): Error: template std.array.array(Range) if (isForwardRange!(Range))
cannot deduce template function from argument types !()(Splitter!(string))

Do you know what's wrong in it?

Bye and thank you,
bearophile
Aug 08 2010
parent reply Pelle <pelle.mansson gmail.com> writes:
On 08/09/2010 12:50 AM, bearophile wrote:
 This D2 code:

 import std.regex: splitter, regex;
 import std.array: array;
 void main() {
      array(splitter(", abc, de", regex(", *")));
 }


 Gives the errors:

 test.d(4): Error: template std.array.array(Range) if (isForwardRange!(Range))
does not match any function template declaration
 test.d(4): Error: template std.array.array(Range) if (isForwardRange!(Range))
cannot deduce template function from argument types !()(Splitter!(string))

 Do you know what's wrong in it?

 Bye and thank you,
 bearophile
std.array.array() erroneously requires a forward range, where it should require an input range. Splitter also does not define save(), so it's not a forward range.
Aug 09 2010
parent reply Jonathan M Davis <jmdavisprog gmail.com> writes:
On Monday 09 August 2010 01:13:30 Pelle wrote:
 std.array.array() erroneously requires a forward range, where it should
 require an input range.
 
 Splitter also does not define save(), so it's not a forward range.
Well, the requirement for save() being part of a forward range is fairly recent, and a bunch of ranges which are supposed to be forward ranges don't have them even though they're supposed to. The change was made fairly close to the release of 2.047, I believe, and it was missed for many ranges. It's mostly if not entirely fixed in svn. Actually, if I try and compile Bearophile's code on my machine (which has a fairly recent version of phobos), it compiles just fine. So, I don't know if array() should require an input range or a forward range, but the issue here has to do with recent changes to forward ranges which didn't make it into all forward ranges. It should be fixed with 2.048. - Jonathan M Davis
Aug 09 2010
parent reply bearophile <bearophileHUGS lycos.com> writes:
Jonathan M Davis:
 Well, the requirement for save() being part of a forward range is fairly
recent, 
 and a bunch of ranges which are supposed to be forward ranges don't have them 
 even though they're supposed to. The change was made fairly close to the
release 
 of 2.047, I believe, and it was missed for many ranges. It's mostly if not 
 entirely fixed in svn. Actually, if I try and compile Bearophile's code on my 
 machine (which has a fairly recent version of phobos), it compiles just fine.
I have tried the latest beta and indeed it works, thank you. Where can I find information about the purposes and meaning of save()? TDPL? Bye, bearophile
Aug 09 2010
next sibling parent "Lars T. Kyllingstad" <public kyllingen.NOSPAMnet> writes:
On Mon, 09 Aug 2010 07:31:21 -0400, bearophile wrote:

 Jonathan M Davis:
 Well, the requirement for save() being part of a forward range is
 fairly recent, and a bunch of ranges which are supposed to be forward
 ranges don't have them even though they're supposed to. The change was
 made fairly close to the release of 2.047, I believe, and it was missed
 for many ranges. It's mostly if not entirely fixed in svn. Actually, if
 I try and compile Bearophile's code on my machine (which has a fairly
 recent version of phobos), it compiles just fine.
I have tried the latest beta and indeed it works, thank you. Where can I find information about the purposes and meaning of save()? TDPL?
It should be in the documentation of std.range.isForwardRange(), but Andrei seems to have forgotten it. He did describe it in his 'On Iteration' article, though: http://www.informit.com/articles/article.aspx?p=1407357 Check out page 7, section 'Forward Ranges'. (I think the whole article is worth reading, if you haven't already -- it really helped me understand ranges.) -Lars
Aug 09 2010
prev sibling parent Jonathan M Davis <jmdavisprog gmail.com> writes:
On Monday, August 09, 2010 04:31:21 bearophile wrote:
 Jonathan M Davis:
 Well, the requirement for save() being part of a forward range is fairly
 recent, and a bunch of ranges which are supposed to be forward ranges
 don't have them even though they're supposed to. The change was made
 fairly close to the release of 2.047, I believe, and it was missed for
 many ranges. It's mostly if not entirely fixed in svn. Actually, if I
 try and compile Bearophile's code on my machine (which has a fairly
 recent version of phobos), it compiles just fine.
I have tried the latest beta and indeed it works, thank you. Where can I find information about the purposes and meaning of save()? TDPL? Bye, bearophile
save() gives you a generic way to get a copy of the range so that you can mess with the copy without altering the original. That way you don't have to worry about the different copy semantics for classes, structs, and arrays. - Jonathan M Davis
Aug 09 2010