www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Variable cannot be read at compile time.

reply aliak <something something.com> writes:
Hi, I'm having a bit a trouble doing some compile time parsing. 
This works:

immutable str = "he-.llo-the.re";
immutable separators = "-.";
enum a = str.splitter(separators).array;

But this does not:

enum b = str.splitter!(a => separators.canFind(a)).array;

The error is: cannot deduce function from argument types !((a) => 
separators.canFind(a))(immutable(string))

And this does:

enum c = str.splitter!(a => a == a).array;

And this does not:

enum d = str.splitter!(a => a == separators).array;

What am I missing?

Thanks!
Dec 07 2017
parent =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 12/07/2017 04:45 PM, aliak wrote:
 Hi, I'm having a bit a trouble doing some compile time parsing. This works:
 
 immutable str = "he-.llo-the.re";
 immutable separators = "-.";
 enum a = str.splitter(separators).array;
 
 But this does not:
 
 enum b = str.splitter!(a => separators.canFind(a)).array;
 
 The error is: cannot deduce function from argument types !((a) => 
 separators.canFind(a))(immutable(string))
 
 And this does:
 
 enum c = str.splitter!(a => a == a).array;
 
 And this does not:
 
 enum d = str.splitter!(a => a == separators).array;
 
 What am I missing?
 
 Thanks!
 
 
Most work with 2.076 for me. 'd' does not work because while str.front is dchar, separators is a string, so 'a == separators' does not compile: import std.stdio; import std.algorithm; import std.range; void main() { immutable str = "he-.llo-the.re"; immutable separators = "-."; enum a = str.splitter(separators).array; enum b = str.splitter!(a => separators.canFind(a)).array; enum c = str.splitter!(a => a == a).array; // enum d = str.splitter!(a => a == separators).array; writeln(a); writeln(b); writeln(c); } ["he", "llo-the.re"] ["he", "", "llo", "the", "re"] ["", "", "", "", "", "", "", "", "", "", "", "", "", "", ""] Ali
Dec 07 2017