Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
January 27, 2014 A small question default values in tmplate-functions | ||||
---|---|---|---|---|
| ||||
Hello, Suppose I have the following function auto veryStableAPI(string parameter,VaraiadicParams...)() { // do something very slow and stable; .... } auto experimentalReplacement(string parameter,VaraidcParams ...)() { // do the same thing very fast and dangerous } is the following auto veryStableAPI(bool brave=false, string parameter,VaraiadicParams...) { static if (!brave) // do something very slow and stable; else // do the same thing very fast and dangerous } valid according to spec ? |
January 28, 2014 Re: A small question default values in tmplate-functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Uplink_Coder | On Monday, 27 January 2014 at 19:56:05 UTC, Uplink_Coder wrote:
> Hello,
>
> Suppose I have the following function
>
> auto veryStableAPI(string parameter,VaraiadicParams...)() {
> // do something very slow and stable;
> ....
> }
>
> auto experimentalReplacement(string parameter,VaraidcParams ...)() {
> // do the same thing very fast and dangerous
> }
>
> is the following
>
> auto veryStableAPI(bool brave=false, string parameter,VaraiadicParams...) {
> static if (!brave)
> // do something very slow and stable;
> else
> // do the same thing very fast and dangerous
> }
> valid according to spec ?
import std.stdio;
import core.vararg;
auto veryStableAPI(bool brave = false)(string parameter, ...)
{
static if (!brave)
{
pragma(msg, "I'm not brave");
}
else
{
pragma(msg, "I'm very brave");
}
}
void main(string[] args)
{
veryStableAPI("test");
veryStableAPI!(true)("test");
}
|
January 29, 2014 Re: A small question default values in tmplate-functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gary Willoughby | > import std.stdio;
> import core.vararg;
>
> auto veryStableAPI(bool brave = false)(string parameter, ...)
> {
> static if (!brave)
> {
> pragma(msg, "I'm not brave");
> }
> else
> {
> pragma(msg, "I'm very brave");
> }
> }
>
> void main(string[] args)
> {
> veryStableAPI("test");
> veryStableAPI!(true)("test");
> }
Sorry but that does not anwer my question.
is it legal or is it not ?
|
January 29, 2014 Re: A small question default values in tmplate-functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Uplink_Coder | > valid according to spec ?
Only trailing parameter can have default arguments.
|
January 29, 2014 Re: A small question default values in tmplate-functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Uplink_Coder | On Wednesday, 29 January 2014 at 18:24:22 UTC, Uplink_Coder wrote:
> is it legal or is it not ?
Yours isn't, no.
|
Copyright © 1999-2021 by the D Language Foundation