On 2011-06-13 06:21:47 +0300, Mehrdad said:
Yeah I was referring to something similar to what C# has (aside from
the lack of boxing).
On 6/12/2011 6:46 PM, Andrei Alexandrescu wrote:
On 6/12/11 8:28 PM, Jonathan M Davis wrote:
They aren't virtual. For an interface to work, it has to be virtual. structs
are value types, not reference types. They have no virtual table and have no
polymorphism.
Why would they need to be virtual? They obviously aren't in C#, but
they still work pretty well (e.g. foreach loops work with
List<T>.Enumerator, which is a struct but which can be treated as the
IEnumerator<T> interface), right?
In C# compiler can do stuff that you are not allowed to do, such as
autoboxing structs in objects to allow Interface usage, calling Object
methods or some magic duck typing. In most cases it devirtualizes
calls, so there is no overhead in boxing.
He must be referring to nominal conformance. It's been discussed many
times. There are important disadvantages (e.g. you can't "implement" a
type alias) but there are advantages too.
Ultimately we never got around to it.
Andrei
Haha ok, that's a good reason in its own way, thanks. :)