Class/Interface Modeling of Ranges
BCS
none at anon.com
Mon Nov 23 15:06:44 PST 2009
Hello dsimcha,
> 3. Can we simplify this by using runtime exceptions instead of
> compile time errors for some of this stuff? For example, every range
> would have a hasLength() method and a length() method. If hasLength()
> is false, length() would throw. Though this sacrifices compile time
> error checking, it might be better in some ways. For example, if a
> given compile time type may or may not have length depending on its
> runtime type, you could check at runtime whether it has a length and
> adapt your handling of it accordingly.
>
make hasLength a static const variable and it can be used for reflection
if you need polymorphism add a function that returns this.hasLength. Following
that pattern, you could make much of the boiler plate into a mixin:
template Range()
{
bool p_hasLength() { return this.hasLength; }
int length() { static if(this.hasLength) return iLength() else thrown
... ; }
}
More information about the Digitalmars-d
mailing list