byval keyword to make objects act as value types
Christopher Wright
dhasenan at gmail.com
Sat Dec 22 20:01:30 PST 2007
BC wrote:
> so that 'byval MyClass' is a new type that acts like MyClass in all ways
> (ie. is polymorphic) except that it gets dupped on non-const assignment
> from other byval MyClasses and normal MyClasses. possibly also on
> assignment to normal MyClasses. this would require that it *has* a dup
> method, or maybe a copy constructor
Perhaps this would be better as a class declaration modifier?
byval class Foo {} // acts like a struct
Or:
valueclass Foo {}
It would be simpler, at least: an opAssign overload.
> byval Base b = new Derived;
>
> despite the name 'byval' b actually holds a reference to a copy of
> Derived, so slicing is avoided.
> or, if that's too inefficient perhaps the linker can figure out the size
> of the largest class derived from Base and allocate that much on the
> stack/inside a containing class.
If we get this, I'm going to ask for virtual template methods in classes
again. It's not happening.
> myFunction(ref Base arg)
> {
> ++arg;
> }
>
> myFunction(b)
>
> i'm thinking it should be overridable so that the above function *does*
> change the value of b
Besides which, arg isn't assigned to...
void func(ref ValueClass arg) {
arg = new ValueClass();
}
> question: are calls to final class member functions non-virtual?
Well, yes. But do you mean, are they found in the vtbl? You could check:
class Foo {
final void a(){}
final void b(){}
final void c(){}
}
assert (Foo.classinfo.vtbl.length == Object.classinfo.vtbl.length);
> i notice the tango iterators are classes. surely we want to use
> iterators as value types... this way, we can.
>
> alternatively, since scope objects are a bit like value types already,
> perhaps we can just add the functionality to that.
Ugh. No.
> then, we just need to return refs from functions, and it's goodbye C++!
More information about the Digitalmars-d
mailing list