Template return values?
    Era Scarecrow 
    rtcvb32 at yahoo.com
       
    Tue Dec  4 16:55:58 PST 2012
    
    
  
On Tuesday, 4 December 2012 at 17:43:21 UTC, Dmitry Olshansky 
wrote:
> Well TDPL claims multiple alias this is allowed so in some 
> distant future it maybe possible for Varaint to alias this to 
> all built-in types.
  Maybe....
  I remember back when I was originally reading about C++ and 
overloading how the signature would let you overload a function 
multiple times (C++ Primer 5th I think); I was going to try 
making a few classes to get a good understanding only to find it.
class Something {
   long value;
   long operator+(Something& rhs) {
     return value + rhs.value;
   }
   Something operator+(Something& rhs) {
     value += rhs.value;
     return this;
   }
}
  The above would refuse to compile (and likely still does) 
although it has a minorly different signature; Then I came to 
realize the return type wasn't part of the signature, and never 
was part of the identifying/overload-able part of OO. It makes 
sense to some limited degree but it's annoying...
  In certain unique cases I wonder if having a template return 
type would be an answer to certain problems... We know that 
sometimes the compiler can rewrite 'a.func(b,c)' to 'func(a,b,c)' 
, it's just syntactical sugar. Why couldn't it also try (when 
appropriately identifiable in the signature) 't = a.func(b,c)' to 
't = a.func!(typeof(t))(b, c)'?
  Mind you full template functions (where ! is required) this 
wouldn't apply for or even work for.
    
    
More information about the Digitalmars-d-learn
mailing list