Thread overview | |||||
---|---|---|---|---|---|
|
February 03, 2012 Re: Function signature constraint syntax | ||||
---|---|---|---|---|
| ||||
Attachments:
| >
> Quick question: I have a function that takes an alias parameter:
>
> struct X { ... };
>
> void func(alias G)(object O) {
> ...
> X x = ...;
> G(x);
> ...
> }
>
> How do I write a signature constraint that essentially specifies that G should take a parameter of type X and return void?
if ( is(typeof(G(X.init ) ) == void))
For the expression to work, G must accept an X and return a void.
|
February 03, 2012 Re: Function signature constraint syntax | ||||
---|---|---|---|---|
| ||||
On Fri, Feb 03, 2012 at 06:51:56AM +0100, Philippe Sigaud wrote: > > > > Quick question: I have a function that takes an alias parameter: > > > > struct X { ... }; > > > > void func(alias G)(object O) { > > ... > > X x = ...; > > G(x); > > ... > > } > > > > How do I write a signature constraint that essentially specifies that G should take a parameter of type X and return void? > > if ( is(typeof(G(X.init ) ) == void)) > > For the expression to work, G must accept an X and return a void. Ah, I forgot about .init. Thanks, that's exactly what I was looking for. T -- Береги платье снову, а здоровье смолоду. |
February 03, 2012 Re: Function signature constraint syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Murphy | On Fri, Feb 03, 2012 at 04:50:24PM +1100, Daniel Murphy wrote: > void func(alias G)(object O) if (is(typeof(G(O)) == void)) { No, the problem was that G takes another type as parameter, not 'object'. --T > "H. S. Teoh" <hsteoh@quickfur.ath.cx> wrote in message news:mailman.295.1328245356.25230.digitalmars-d-learn@puremagic.com... > > Quick question: I have a function that takes an alias parameter: > > > > struct X { ... }; > > > > void func(alias G)(object O) { > > ... > > X x = ...; > > G(x); > > ... > > } > > > > How do I write a signature constraint that essentially specifies that G should take a parameter of type X and return void? > > > > > > T > > > > -- > > When solving a problem, take care that you do not become part of the problem. > > -- Without geometry, life would be pointless. -- VS |
Copyright © 1999-2021 by the D Language Foundation