| Thread overview | ||||||
|---|---|---|---|---|---|---|
|
January 05, 2015 Conditional functions | ||||
|---|---|---|---|---|
| ||||
Is it possible to use static if in a template structure to have some member functions only for specific types?
E.g.:
struct Foo(T)
{
...
T get() { ... }
static if(isMutable!T)
{
void set(T x) { ... }
}
}
| ||||
January 05, 2015 Re: Conditional functions | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Dominikus Dittes Scherkl | On Mon, 05 Jan 2015 17:47:09 +0000, Dominikus Dittes Scherkl wrote:
> Is it possible to use static if in a template structure to have some member functions only for specific types?
Yep. This is actually a frequently used pattern in functions that return ranges.
| |||
January 05, 2015 Re: Conditional functions | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Justin Whear | On Monday, 5 January 2015 at 17:55:49 UTC, Justin Whear wrote:
> On Mon, 05 Jan 2015 17:47:09 +0000, Dominikus Dittes Scherkl wrote:
>
>> Is it possible to use static if in a template structure to have some
>> member functions only for specific types?
>
> Yep. This is actually a frequently used pattern in functions that return
> ranges.
Cool.
I'm every day again astonished how cool D really is.
| |||
January 05, 2015 Re: Conditional functions | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Dominikus Dittes Scherkl | On Monday, January 05, 2015 17:58:06 Dominikus Dittes Scherkl via Digitalmars-d-learn wrote:
> Cool.
> I'm every day again astonished how cool D really is.
And I'm increasingly frustrated with how other languages lack many of D's cool features...
:)
- Jonathan M Davis
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply