lazy compilation of templated class members
Bill Baxter
dnewsgroup at billbaxter.com
Sun Dec 24 23:19:10 PST 2006
I have a need to define methods in a templated class that only
conditionally exist. For instance with a 'class Foo(T)', I'd like to
give it an opNeg method as long as T is a type that can be negated.
So far so good, I can get that with:
class Foo(T)
{
static if(is(typeof(-T.init))) {
Foo neg() {
auto ret = new Foo;
ret.m_value = -m_value;
return ret;
}
}
T m_value;
}
1)
Is this something useful enough that it might be worth special syntax?
Something like 'lazy' in front of the method declaration:
lazy Foo neg() {
auto ret = new Foo;
ret.m_value = -m_value;
return ret;
}
The lazy meaning basically "leave this method out if it contains
semantic errors".
2)
I can't figure out how to do the static if for opXXXAssign type methods.
static if(is(typeof(T.init+=T.init))) is always false, I guess because
T.init isn't assignable. Is there some way to do that check?
--bb
More information about the Digitalmars-d
mailing list