Conditional Pure?

%u wfunction at hotmail.com
Sat Jan 22 15:51:16 PST 2011


> I see. I'd like a more general-purpose solution, something that works with
nothrow too and other future attributes too.

Funny, that was going to be my next comment. :)
The only thing that scares me a bit is that code like this:

public(isPublic!(TFn)) static(isStatic!(TFn)) int memoize(TFn)(TFn fn)
    pure(isPure!(TFn))
    if (isCallable!(TFn))
{
    //etc.
}

might turn out a bit unreadable. And, furthermore, I'd *like* to be able to say
something like "this method returns a shared const value iff the given type is int
or long" but this won't work with const() or shared() because of their syntax (you
can't say const(is(T == int))). Any ideas on how we might be able to get that to work?


Oh, and while on the note of const, here's a somewhat unrelated concern: I've
noticed that code like this:

static const int* addressOf(ref int x) { return &x; }

is *very* tricky and misleading, because it's declaring the method as const, not
the pointer. Would it be a bad idea to forbid const, pure, nothrow, and the like
from coming before the method name? That way it won't be ambiguous like this.


More information about the Digitalmars-d mailing list