[Issue 8106] func.stringof with default args
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jun 14 18:37:26 PDT 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8106
--- Comment #14 from Kenji Hara <k.hara.pg at gmail.com> 2012-06-14 18:39:37 PDT ---
Now, this small utility works as expected.
/*
*/
template ParameterDefaultValueTuple(alias func)
{
alias ParameterTypeTuple!func PT;
template DefArg(size_t i)
{
enum get = (PT[i..i+1] args) => args[0];
static if (is(typeof(get())))
enum DefArg = get();
else
alias void DefArg;
// If default arg doesn't exist, returns void instead.
}
template Impl(size_t i = 0)
{
static if (i == PT.length)
alias TypeTuple!() Impl;
else
alias TypeTuple!(DefArg!(i), Impl!(i+1)) Impl;
}
alias Impl!() ParameterDefaultValueTuple;
}
unittest
{
void foo(int n = 1, string s = "hello"){}
//pragma(msg, ParameterDefaultValueTuple!foo);
static assert(ParameterDefaultValueTuple!foo.length == 2);
static assert(ParameterDefaultValueTuple!foo[0] == 1);
static assert(ParameterDefaultValueTuple!foo[1] == "hello");
static assert(is(typeof(ParameterDefaultValueTuple!foo) ==
typeof(TypeTuple!(1, "hello"))));
void bar(int x, int n = 1, string s = "hello"){}
//pragma(msg, ParameterDefaultValueTuple!bar);
static assert(ParameterDefaultValueTuple!bar.length == 3);
static assert(is(ParameterDefaultValueTuple!bar[0] == void));
static assert( ParameterDefaultValueTuple!bar[1] == 1);
static assert( ParameterDefaultValueTuple!bar[2] == "hello");
static assert(is(typeof(ParameterDefaultValueTuple!bar) ==
typeof(TypeTuple!(void, 1, "hello"))));
struct Colour
{
ubyte a,r,g,b;
immutable Colour white = Colour(255,255,255,255);
}
void bug8106(Colour c = Colour.white){}
//pragma(msg, ParameterDefaultValueTuple!bug8106);
static assert(ParameterDefaultValueTuple!bug8106[0] == Colour.white);
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list