Skip to content

Commit

Permalink
Allow parenthesis-less pdef
Browse files Browse the repository at this point in the history
  • Loading branch information
John-Colvin committed Jul 4, 2015
1 parent 23ad538 commit 847dce0
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions ppyd.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,22 @@ import std.typetuple : Arguments = TypeTuple, Map = staticMap, Filter;
import std.typecons : tuple, Tuple;
import std.traits;

struct pdef(Args ...){}
private struct Pdef(Args ...){}

@property auto pdef(Args ...)()
{
return Pdef!Args();
}

template TryTypeof(TL ...)
if(TL.length == 1)
{
static if(is(TL[0]))
alias TryTypeof = TL[0];
else static if(is(typeof(TL[0])))
alias TryTypeof = typeof(TL[0]);
else static assert("Can't get a type out of this");
}

/*
* With the builtin alias declaration, you cannot declare
Expand Down Expand Up @@ -39,7 +54,7 @@ unittest
bool containsPdef(attrs...)()
{
foreach(attr; attrs)
static if(is(attr == pdef!Args, Args...))
static if(is(TryTypeof!attr == Pdef!Args, Args...))
{
return true;
}
Expand All @@ -56,7 +71,7 @@ private auto registerFunctionImpl(alias define, alias parent, string mem)()
static if(containsPdef!attrs)
foreach(attr; attrs)
{
static if(is(attr == pdef!Args, Args...))
static if(is(TryTypeof!attr == Pdef!Args, Args...))
{
return define!(ol, Args)();
}
Expand Down Expand Up @@ -84,7 +99,7 @@ private auto MemberHelper(alias parent, string mem)()
alias attrs = Arguments!(__traits(getAttributes, agg));
foreach(i, attr; attrs)
{
static if(is(attr == pdef!Args, Args...))
static if(is(TryTypeof!attr == Pdef!Args, Args...))
{
return Member!(mem, Args)();
}
Expand All @@ -105,7 +120,7 @@ auto registerAggregateType(string aggStr, alias parent)()
alias attrs = Arguments!(__traits(getAttributes, agg));
foreach(attr; attrs)
{
static if(is(attr == pdef!Args, Args...))
static if(is(TryTypeof!attr == Pdef!Args, Args...))
{
enum NotVoid(T) = !is(T == void);
return wrap_class!(agg, Args,
Expand Down

0 comments on commit 847dce0

Please sign in to comment.