On 3/23/14, Philippe Sigaud wrote:
> Now, if only __traits could be beautified somewhat... I mean: everyone
> is using it, it's time to make it more palatable.
That's what std.traits is for, to hide the __traits and is() uglyness.
On Sunday, 23 March 2014 at 13:23:58 UTC, Dicebot wrote:
On Sunday, 23 March 2014 at 13:03:07 UTC, Adam D. Ruppe wrote:
That won't necessarily work in the presence of overloaded
functions since getMember only gets one of them.
Yeah, forgot to add this part, will make end result a bit less
pre
On Sun, Mar 23, 2014 at 2:50 PM, Andrej Mitrovic
wrote:
> Pretty sure it's because you're using 'alias' instead of 'enum'. This works:
Oww! For years, D told me I couldn't use __traits in an easy way like
this. I'll have to teach me out of it, and use enum :-) Damn, but
using enum is quite natur
On 3/23/14, Philippe Sigaud wrote:
> But this is not accepted by the grammar right now, because of __traits()
Pretty sure it's because you're using 'alias' instead of 'enum'. This works:
-
enum isSomething(T) = __traits(compiles,
{
int up;
T.init.doSomething(up)
On Sunday, 23 March 2014 at 13:03:07 UTC, Adam D. Ruppe wrote:
That won't necessarily work in the presence of overloaded
functions since getMember only gets one of them.
Yeah, forgot to add this part, will make end result a bit less
pretty indeed.
Updated version with overloads will be more
On Sunday, 23 March 2014 at 12:53:39 UTC, Dicebot wrote:
template isSomething(T)
{
enum isSomething =
is(typeof(__traits(getMember, T, "doSomething")) == function)
&& is(typeof(&__traits(getMember, T, "doSomething")) : void
function(Unrelated*));
}
That won't necessarily
On Sunday, 23 March 2014 at 13:00:09 UTC, Adam D. Ruppe wrote:
alias isSomething(T) = alias!(__traits(compiles,
oops that should say helper! not alias!
On Sunday, 23 March 2014 at 12:57:36 UTC, Philippe Sigaud wrote:
But this is not accepted by the grammar right now, because of
__traits()
That's easy enough to work around with an alias helper:
alias helper(alias T) = T;
alias isSomething(T) = alias!(__traits(compiles,
{
U
Ideally, the alias part of the grammar could be extended and
isSomething simplified as:
alias isSomething(T) = __traits(compiles,
{
Unrelated* up;
T.init.doSomething(up);
}
);
But this is not accepted by the grammar right now, because of __traits()
On Sun, Mar 23, 2014 at 1:40 PM, Steve Teale
wrote:
> What's the cool/idiomatic D way to test at compile time if a struct has a
> member function with a particular signature? Along the lines of:
>
> struct Unrelated
> {
>...
> }
>
> template isSomething(T)
> {
> enum bool isSomething = is(
template isSomething(T)
{
enum isSomething =
is(typeof(__traits(getMember, T, "doSomething")) == function)
&& is(typeof(&__traits(getMember, T, "doSomething")) : void
function(Unrelated*));
}
What's the cool/idiomatic D way to test at compile time if a
struct has a member function with a particular signature? Along
the lines of:
struct Unrelated
{
...
}
template isSomething(T)
{
enum bool isSomething = is(typeof(
(inout int = 0)
{
T???; // has a function void
12 matches
Mail list logo