Compile-time Interfaces
so
so at so.so
Sun Nov 27 08:15:45 PST 2011
On Sun, 27 Nov 2011 02:40:08 +0200, Kapps <Kapps at notvalidemail.com> wrote:
> Which brings in, compile-time interfaces. It seems like a natural thing
> to include when you have the above tools. Instead of having a method
> such as:
> auto DoSomething(T)(T Data) if(isInputRange!(T)) { }
> You could simply do:
> auto DoSomething(Range Data) { }
> where Range is defined as:
> enum interface Range {
> void popFront() const;
> @property bool empty() const;
> @property auto front();
> }
> Much nicer than this very confusing looking statement (taken from
> std.range):
> template isInputRange(R)
> {
> enum bool isInputRange = is(typeof(
> {
> R r; // can define a range object
> if (r.empty) {} // can test for empty
> r.popFront(); // can invoke popFront()
> auto h = r.front; // can get the front of the range
> }()));
> }
I sort of like the current solution, (it uses the language's most powerful
feature) but for such common use the syntax is ugly.
As it was suggested many times (std.meta), we really need to simplify this
to at least something like:
> template isInputRange(R)
> {
> enum bool isInputRange = compiles
> {
> R r; // can define a range object
> if (r.empty) {} // can test for empty
> r.popFront(); // can invoke popFront()
> auto h = r.front; // can get the front of the range
> }
> }
More information about the Digitalmars-d
mailing list