Thread overview
pointer to std.algorithm.iteration : splitter
Aug 31, 2023
Vino
Aug 31, 2023
FeepingCreature
Aug 31, 2023
Dukc
Sep 01, 2023
vino
August 31, 2023

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

August 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

Why are you trying to take pointers of lots of different things? You should pretty much never need pointers in normal D code.

August 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. 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):

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).

September 01, 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:

>

[...]

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