digitalmars.D.learn - pointer to std.algorithm.iteration : splitter
- Vino (21/21) Aug 30 2023 Hi All,
 - FeepingCreature (3/24) Aug 31 2023 Why are you trying to take pointers of lots of different things?
 - Dukc (24/45) Aug 31 2023 I'm assuming you want to instantiate `splitter` and take the
 - vino (2/8) Aug 31 2023 This is what I expected, thank you very much
 
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
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
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
On Thursday, 31 August 2023 at 10:46:53 UTC, Dukc wrote:On Thursday, 31 August 2023 at 05:16:02 UTC, Vino wrote:This is what I expected, thank you very much[...]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. [...]
 Aug 31 2023








 
 
 
 FeepingCreature <feepingcreature gmail.com> 