Arrays of functions, function signatures and template instantiation
JR
zorael at gmail.com
Tue Apr 30 03:02:05 PDT 2013
On Tuesday, 30 April 2013 at 09:18:56 UTC, anonymous wrote:
> On Tuesday, 30 April 2013 at 08:42:57 UTC, JR wrote:
>> On Tuesday, 30 April 2013 at 02:38:27 UTC, anonymous wrote:
> Don't know what's going wrong there. It works for me:
> http://dpaste.dzfl.pl/5c71f80e
My bad, I switched the wrong runner/&runner and in the wrong
direction. Thanks!
Any other protips?
For instance, is it possible to have MatrixWalker's F type to
have a default value of a NOP void function(), have the innermost
foreach loop check if the element is a function, and if so call
it directly without needing FuncRunner at all?
Also, is there a clever approach to have MatrixWalker call its
passed function variadically with only the arguments that its
signature allows? As in;
-------------
> import std.stdio;
> import std.concurrency;
>
> struct Event { /* ... type, sender, target, content and friends
> ... */ };
>
> template MatrixWalker(F,E: E[I][T],I,T) {
> // note addition of Event below
> void applyFunc(ref Event evt, F func, E[I][T] matrix) {
> /* ... Inception foreach ... */
> func(evt, /* only the arguments of E, I and/or T that
> type F accepts */);
> }
> }
>
> const alias Blaawp MAJOR;
> const alias Oorgle MINOR;
> static void function(ref Event, MINOR)[MINOR][MAJOR]
> funcyMatrix;
> // note no MAJOR in func sig
>
> void populate() {
> /* ... */
> }
>
> void traverse() {
> sendMessageAdapter = void function(ref Event evt, Tid) {
> std.concurrency.send(tid, evt);
> };
>
> alias
> MatrixWalker!(typeof(&sendMessageAdapter),typeof(funkyMatrix)).applyFunc
> apply;
>
> writeln("Traversing funcy matrix");
> apply(&sendMessageAdapter, funkyMatrix);
> }
>
> void main(string[] args) {
> populate();
> traverse();
> }
-------------
That sounds too good to be true, but it would make me warm and
fuzzy inside if I didn't have to resort to keeping a dozen
adapter/shim functions around.
More information about the Digitalmars-d-learn
mailing list