Re: Templated delegate as template argument for structs

2021-02-20 Thread Simon van Bernem via Digitalmars-d-learn
Thanks! The alias solution works and is good enough for me. Also thanks for providing the code to typecheck the alias, I would have never been able to come up with that myself.

Re: Templated delegate as template argument for structs

2021-02-20 Thread Simen Kjærås via Digitalmars-d-learn
On Saturday, 20 February 2021 at 09:16:46 UTC, Simon van Bernem wrote: I have the following struct declaration: struct Hash_Table(Key, Value, u32 delegate(ref Key) custom_hash_function = null) [snip] I take it from the error that the problem is not actually the delegate that I am passing, but

Templated delegate as template argument for structs

2021-02-20 Thread Simon van Bernem via Digitalmars-d-learn
I have the following struct declaration: struct Hash_Table(Key, Value, u32 delegate(ref Key) custom_hash_function = null){ ... } When I try to instance the Type like this: Hash_Table!(Component*, Component_Tick_Info, (c) => hash32(c.handle.bitfield)) my_hash_table; I get the followin

Re: Templated delegate

2011-01-11 Thread Stanislav Blinov
10.01.2011 21:08, Mitja пишет: Thanks, toDelegate is what I've been looking for. It still segfaults, though. The setup: === module mod1; import std.algorithm; import std.functional; import std.stdio; void main( ) { auto haystack = ["a","b","c"]; auto needle = "b"; auto flt = de

Re: Templated delegate

2011-01-10 Thread Mitja
d is D 2.051. As well as on Windows XP as guest OS in VirtualBox. XP prints out: "object.Error: Access Violation" > > > It works fine when packages in mod2 are omitted. > > When which packages in mod2 are omitted? > > I can only make out that this is a compiler bug

Re: Templated delegate

2011-01-10 Thread Mitja
to result = filter!dg(haystack); >writeln(result); > } > > I would have to argue that the delegate is hardly templated, though. Not > sure what that means. > > > What would be the correct way for templated delegate? > > Depending on what you mean by &

Re: Templated delegate

2011-01-10 Thread Simen kjaeraas
= "b"; auto flt = (string s){return s == needle;}; auto dg = toDelegate( flt ); auto result = filter!dg(haystack); writeln(result); } I would have to argue that the delegate is hardly templated, though. Not sure what that means. What would be the correct way for templated d

Re: Templated delegate

2011-01-10 Thread Stewart Gordon
t way for templated delegate? It depends on what you're trying to do. Stewart.

Templated delegate

2011-01-10 Thread Mitja
the program would produce segmentation fault. It works fine when packages in mod2 are omitted. What would be the correct way for templated delegate?