digitalmars.D.learn - A small question default values in tmplate-functions
- Uplink_Coder (19/19) Jan 27 2014 Hello,
- Gary Willoughby (19/38) Jan 28 2014 import std.stdio;
- Uplink_Coder (2/20) Jan 29 2014 Sorry but that does not anwer my question.
- Gary Willoughby (2/3) Jan 29 2014 Yours isn't, no.
- Tobias Pankrath (1/2) Jan 29 2014 Only trailing parameter can have default arguments.
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 ?
Jan 27 2014
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");
}
Jan 28 2014
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 ?
Jan 29 2014
On Wednesday, 29 January 2014 at 18:24:22 UTC, Uplink_Coder wrote:is it legal or is it not ?Yours isn't, no.
Jan 29 2014
valid according to spec ?Only trailing parameter can have default arguments.
Jan 29 2014









"Gary Willoughby" <dev nomad.so> 