[Issue 8520] Simple "in"-constrained opBinaryRight in interface doesn't work

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Aug 8 10:11:42 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=8520


Jonathan M Davis <jmdavisProg at gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg at gmx.com


--- Comment #4 from Jonathan M Davis <jmdavisProg at gmx.com> 2012-08-08 10:11:34 PDT ---
> I could understand if the opBinaryRight template wasn't constrained to "in",
but it is, so I see no reason why it cannot be in the vtable since it can only
ever have one instance in a class.

Because templated functions _never_ end up in the vtable. Mixed in templates
may if they're fully instantiated when mixed in (I don't remember), but a
templated function written directly in the class is _never_ virtual.

That doesn't necessarily mean that there are no situations where the language
could be enhanced to make a templated function virtual if it's actually
restricted enough (and this may be such a case), but as it stands, being a
template is enough to make it non-virtual regardless of what it does or how
constrained it is or isn't. I don't believe that even

int func()() { return 2; }

would be virtual, and that's pretty much as constrained as it gets.

Of course, if such a function _did_ get changed to virtual, then it would
always defined, whereas right now it's only defined if used, which could be a
definite negative, depending on the programmer's intent. So, there's defintely
a tradeoff here even if it's possible to make some templated functions virtual.

-- 
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