www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - pointer to std.algorithm.iteration : splitter

reply Vino <akashvino79 gmail.com> writes:
Hi All,

   Request your help on the below error

Program
```
void main()
{
	import std.stdio:writeln;
	import std.algorithm.iteration : splitter;
	
	auto splitter_ptr = &splitter!((a, b) => a.splitter(b).array);
     string str = "TEST1;TEST2;TEST3";
     auto words = splitter_ptr(str, ';');
     foreach (word; words) { writeln(word); }
}
```
```
Error: template instance `splitter!((a, b) => 
a.splitter(b).array)` does not match any template declaration
```

From,
Vino
Aug 30 2023
next sibling parent FeepingCreature <feepingcreature gmail.com> writes:
On Thursday, 31 August 2023 at 05:16:02 UTC, Vino wrote:
 Hi All,

   Request your help on the below error

 Program
 ```
 void main()
 {
 	import std.stdio:writeln;
 	import std.algorithm.iteration : splitter;
 	
 	auto splitter_ptr = &splitter!((a, b) => a.splitter(b).array);
     string str = "TEST1;TEST2;TEST3";
     auto words = splitter_ptr(str, ';');
     foreach (word; words) { writeln(word); }
 }
 ```
 ```
 Error: template instance `splitter!((a, b) => 
 a.splitter(b).array)` does not match any template declaration
 ```

 From,
 Vino
Why are you trying to take pointers of lots of different things? You should pretty much never need pointers in normal D code.
Aug 31 2023
prev sibling parent reply Dukc <ajieskola gmail.com> writes:
On Thursday, 31 August 2023 at 05:16:02 UTC, Vino wrote:
 Hi All,

   Request your help on the below error

 Program
 ```
 void main()
 {
 	import std.stdio:writeln;
 	import std.algorithm.iteration : splitter;
 	
 	auto splitter_ptr = &splitter!((a, b) => a.splitter(b).array);
     string str = "TEST1;TEST2;TEST3";
     auto words = splitter_ptr(str, ';');
     foreach (word; words) { writeln(word); }
 }
 ```
 ```
 Error: template instance `splitter!((a, b) => 
 a.splitter(b).array)` does not match any template declaration
 ```

 From,
 Vino
I'm assuming you want to instantiate `splitter` and take the address of the resulting function, so that `splitter_ptr` will be a function pointer or a delegate. You are getting the compile time arguments to `splitter` utterly wrong. It should take: - A function that checks equality between an element and a separator. - a `keepSeparators` flag. - type of the range you're passing in, `string` in this case. - type of the separator, `char` or `dchar` in this case. You can find this all in [the docs](https://dlang.org/phobos/std_algorithm_iteration.html#.splitter). I think you accidentally passed what you wanted to do with `splitter` as a compile-time parameter to it. I don't think it's very practical to try instantiating a complex templated function like `splitter` without calling it. It's just not designed for that. I'd rather define a function that wraps a call to it, like (not tested, may have errors): ```D auto splitter_ptr = (string str, dchar sep) => str.splitter(sep).array; ``` Maybe that's what you tried in the first place. You don't need `&` here, because a lambda (which we use here) is already a function pointer (or a delegate).
Aug 31 2023
parent vino <akashvino79 gmail.com> writes:
On Thursday, 31 August 2023 at 10:46:53 UTC, Dukc wrote:
 On Thursday, 31 August 2023 at 05:16:02 UTC, Vino wrote:
 [...]
I'm assuming you want to instantiate `splitter` and take the address of the resulting function, so that `splitter_ptr` will be a function pointer or a delegate. [...]
This is what I expected, thank you very much
Aug 31 2023