equivariant functions

Walter Bright newshound1 at digitalmars.com
Sun Oct 12 14:41:26 PDT 2008


Hmm. Given:

   typeof(s) foo(long s);
   auto x = foo(1);

is x going to be declared as an int? If so, is the cast of the return 
type of foo() an implicit cast, or an explicit one? If explicit, what 
about downcast conversions? For example:

   class A : B { }
   typeof(a) foo(A a) { return new A(); }
   auto x = foo(b);

If we do an explicit cast, we've got null in x. I suppose that's ok.

What about this:

    typeof(s) foo(const char[] s) { auto x = new char[3]; ...; return x; }
    invariant(char)[] t;
    auto s = foo(t);

now s will be unsafely typed as invariant(char)[]. Since const cannot be 
safely cast to invariant or mutable, we might have a serious problem.



More information about the Digitalmars-d mailing list