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

           Summary: Allow operator overloading on non-type template
                    instances
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: simen.kja...@gmail.com


--- Comment #0 from Simen Kjaeraas <simen.kja...@gmail.com> 2010-11-03 04:52:02 
PDT ---
template foo( alias A ) {
    void opAssign( typeof( A ) arg ) {
        A = arg;
    }
}

int a;
foo!a = 4;

The above currently does not work. Allowing this to compile and run would
enable the creation of throwaway types that do nothing but simple operator
overloading, allowing for e.g. reference tuple elements:

import std.typecons;
import std.typetuple;
import dranges.templates;
import dranges.typetuple;

template _( T... ) if ( allSatisfy!( isAlias, T ) ) {
    Tuple!( StaticMap!( TypeOf, T ) ) opAssign( Tuple!( StaticMap!( TypeOf, T )
) args ) {
        foreach ( i, e; T ) {
            e = args[i];
        }
        return args;
    }
}


unittest {
    int a = 1; b = 1;
    _!( a, b ) = tuple( b, a+b ); // Equivalent to _!( a, b ).opAssign( b, a+b
);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to