Changeset 1350

Show
Ignore:
Timestamp:
11/30/09 04:45:43 (2 years ago)
Author:
walter
Message:

add opPow opDispatch remove opDot

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/docsrc/operatoroverloading.dd

    r989 r1350  
    1515    $(LI $(LINK2 #Assignment, Assignment Operator Overloading)) 
    1616$(V2 
    17     $(LI $(LINK2 #Dot, Forwarding)) 
     17    $(DOT $(LI $(LINK2 #Dot, Forwarding))) 
     18    $(LI $(LINK2 #Dispatch, Forwarding)) 
    1819) 
    1920    $(LI $(LINK2 #Future, Future Directions)) 
     
    160161 
    161162    $(TR $(TD %) $(TD no) $(TD $(CODE opMod)) $(TD $(CODE opMod_r))) 
    162  
     163$(V2 
     164    $(TR $(TD ^^) $(TD no) $(TD $(CODE opPow)) $(TD $(CODE opPow_r))) 
     165
    163166    $(TR $(TD &) $(TD yes) $(TD $(CODE opAnd)) $(TD $(CODE opAnd_r))) 
    164167 
     
    560563 
    561564$(V2 
     565$(DOT 
    562566<h2><a name="Dot">Forwarding</a></h2> 
    563567 
     
    616620--- 
    617621) 
    618  
     622
     623 
     624$(V2 
     625<h2><a name="Dispatch">Forwarding</a></h2> 
     626 
     627    $(P Member names not found in a class or struct can be forwarded 
     628    to a template function named $(CODE opDispatch) for resolution. 
     629    ) 
     630 
     631--- 
     632import std.stdio; 
     633 
     634struct S 
     635
     636    void opDispatch(string s, T)(T i) 
     637    { 
     638    writefln("S.opDispatch('%s', %s)", s, i); 
     639    } 
     640
     641 
     642class C 
     643
     644    void opDispatch(string s)(int i) 
     645    { 
     646    writefln("S.opDispatch('%s', %s)", s, i); 
     647    } 
     648
     649 
     650struct D 
     651
     652    template opDispatch(string s) 
     653    { 
     654    enum int opDispatch = 8; 
     655    } 
     656
     657 
     658void main() 
     659
     660    S s; 
     661    s.opDispatch!("hello")(7); 
     662    s.foo(7); 
     663 
     664    auto c = new C(); 
     665    c.foo(8); 
     666 
     667    D d; 
     668    writefln("d.foo = %s", d.foo); 
     669    assert(d.foo == 8); 
     670
     671--- 
     672
    619673<h2><a name="Future">Future Directions</a></h2> 
    620674