[Issue 1023] Struct implementing interfaces and struct member enumeration
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Dec 13 11:56:33 PST 2011
http://d.puremagic.com/issues/show_bug.cgi?id=1023
Trass3r <mrmocool at gmx.de> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mrmocool at gmx.de
--- Comment #7 from Trass3r <mrmocool at gmx.de> 2011-12-13 11:56:26 PST ---
(In reply to comment #6)
> Adding 'static interface' might be the way to differentiate between
> class-interface and struct-interface.
..
> In my case, struct is the right mechanism for speed and stack allocation, while
> the interface is nice to provide a single point to document and to have the
> compiler verify.
Exactly!
Phobos circumvents the problem by using lots of templates in constraints:
template isInputRange(R)
{
enum bool isInputRange = is(typeof(
{
R r = void; // 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
}));
}
While this works fine, it does have some disadvantages.
It adds lots of overhead cause all of that code must be evaluated with errors
gagged, mustn't alter the AST and whatever. Also there are a lot of bugs
introduced by that here in bugzilla.
Furthermore there are no useful error messages with template constraints, so
you don't even know what exactly went wrong when you implemented the interface.
> So for example, if an interface is declared "static interface" or "duck
> interface" or whatever, then getting a reference to it is impossible, because
> it makes no promises about the underlying type.
Yep, but one would need them as parameters. Maybe
foo(Bla b)
with Bla being a static interface could be shorthand for a compiler internal
equivalent of the currently used, ugly
foo(Blub)(Blub b) if (conformsToBlaStructure!Blub)
OTOH, how to express if you want a struct conforming to multiple structural
interfaces?
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list