www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Reducing visual clutter.

reply Nicholas Wilson <iamthewilsonator hotmail.com> writes:
so I have

```
struct Pipeline
{
      // some fields.
     ref typeof(this) invoke(alias kernel)(TransformArgsOf!kernel 
args)
     {
         //...
         return this;
     }
}
```

and it will be used like

```
void fun1(int a) {}
void fun2(double b) {}
void funn(ulong c) {}
//...
auto pipe = Pipeline(...);
pipe.invoke!fun1(42)
     .invoke!fun2(3.14)
     .invoke!funn(1u)
     //...
     ;
```

is there anyway to reduce the visual noise of the `invoke`?

I was thinking of trying to (ab)use opDispatch + mixins that 
returns a callable whose opCall returns the Pipeline by ref. I'm 
not sure how well that would go given I need `kernel.mangleof`, 
`typeof(kernel)` and `Parameters!kernel`.

Is there a nicer way to achieve this? Or is this shenanigans not 
worth it?
Dec 31 2016
parent reply Nicholas Wilson <iamthewilsonator hotmail.com> writes:
On Saturday, 31 December 2016 at 11:39:39 UTC, Nicholas Wilson 
wrote:
 [...]
Oh and `kernel` could be a template function that would need its args forwarded to it.
Dec 31 2016
next sibling parent Ignacious <I.D.T ProjectMaya.com> writes:
On Saturday, 31 December 2016 at 12:31:07 UTC, Nicholas Wilson 
wrote:
 On Saturday, 31 December 2016 at 11:39:39 UTC, Nicholas Wilson 
 wrote:
 [...]
Oh and `kernel` could be a template function that would need its args forwarded to it.
Alias it away using a wrapper?
Dec 31 2016
prev sibling parent Nicholas Wilson <iamthewilsonator hotmail.com> writes:
On Saturday, 31 December 2016 at 12:31:07 UTC, Nicholas Wilson 
wrote:
 On Saturday, 31 December 2016 at 11:39:39 UTC, Nicholas Wilson 
 wrote:
 [...]
Oh and `kernel` could be a template function that would need its args forwarded to it.
It's worse than that `kernel` could be a qualified name which would require the opDispatch shenanigans to attempt to recreate piece-by-piece the QN with successive opDispatch's. Urgh. As much as I don't want to, C++ style opBinary!"<<" is looking the cleanest.
Jan 01 2017