Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changeset 1571

Show
Ignore:
Timestamp:
06/01/10 19:44:00 (15 years ago)
Author:
Masahiro Nakagawa
Message:

Replace static opCall with Constructor. static opCall for struct construction is old style.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/phobos/osx.mak

    r1478 r1571  
    112112ifeq (,$(findstring win,$(OS))) 
    113113    LIB = $(ROOT)/libphobos2.a 
    114114else 
    115115    LIB = $(ROOT)/phobos.lib 
    116116endif 
    117117 
    118118################################################################################ 
    119119MAIN = $(ROOT)/emptymain.d 
    120120 
    121121# Stuff in std/ 
    122 STD_MODULES = $(addprefix std/, algorithm array atomics base64 bigint
     122STD_MODULES = $(addprefix std/, algorithm array atomics base64    \ 
    123123        bitmanip boxer compiler complex contracts conv cpuid cstream    \ 
    124124        ctype date datebase dateparse demangle encoding file format     \ 
    125125        functional getopt intrinsic iterator json loader math md5       \ 
    126126        metastrings mmfile numeric outbuffer path perf process random   \ 
    127127        range regex regexp signals socket socketstream stdint stdio     \ 
    128128        stdiobase stream string syserror system traits typecons         \ 
    129129        typetuple uni uri utf variant xml zip zlib) 
    130130 
    131131# Other D modules that aren't under std/ 
    132132EXTRA_MODULES := $(addprefix std/c/, stdarg stdio) $(addprefix etc/c/,  \ 
  • trunk/phobos/std/encoding.d

    r1519 r1571  
    533533        return e.decodeReverse(); 
    534534    } 
    535535} 
    536536 
    537537//========================================================================= 
    538538 
    539539struct CodePoints(E) 
    540540{ 
    541541    const(E)[] s; 
    542542 
    543     static CodePoints opCall(const(E)[] s) 
     543    this(const(E)[] s) 
    544544    in 
    545545    { 
    546546        assert(isValid(s)); 
    547547    } 
    548548    body 
    549549    { 
    550         CodePoints codePoints; 
    551         codePoints.s = s; 
    552         return codePoints; 
     550        this.s = s; 
    553551    } 
    554552 
    555553    int opApply(scope int delegate(ref dchar) dg) 
    556554    { 
    557555        int result = 0; 
    558556        while (s.length != 0) 
    559557        { 
    560558            dchar c = decode(s); 
    561559            result = dg(c); 
    562560            if (result != 0) break; 
     
    603601            if (result != 0) break; 
    604602        } 
    605603        return result; 
    606604    } 
    607605} 
    608606 
    609607struct CodeUnits(E) 
    610608{ 
    611609    E[] s; 
    612610 
    613     static CodeUnits opCall(dchar d) 
     611    this(dchar d) 
    614612    in 
    615613    { 
    616614        assert(isValidCodePoint(d)); 
    617615    } 
    618616    body 
    619617    { 
    620         CodeUnits codeUnits; 
    621         codeUnits.s = encode!(E)(d); 
    622         return codeUnits; 
     618        s = encode!(E)(d); 
    623619    } 
    624620 
    625621    int opApply(scope int delegate(ref E) dg) 
    626622    { 
    627623        int result = 0; 
    628624        foreach(E c;s) 
    629625        { 
    630626            result = dg(c); 
    631627            if (result != 0) break; 
    632628        } 
  • trunk/phobos/std/iterator.d

    r1279 r1571  
    106106    return first[0 .. last - first]; 
    107107} 
    108108 
    109109/** 
    110110Type that reverses the iteration order of a range. 
    111111*/ 
    112112 
    113113struct Retro(R : E[], E) 
    114114{ 
    115115    E[] forward; 
    116     static Retro opCall(E[] range) 
    117     { 
    118         Retro result = { range }; 
    119         return result
     116 
     117    this(E[] range) 
     118    { 
     119        forward = range
    120120    } 
    121121} 
    122122 
    123123/** 
    124124Returns a range that iterates $(D r) backwards. 
    125125*/ 
    126126 
    127127Retro!(E[]) retro(E)(E[] r) 
    128128{ 
    129129    return Retro!(E[])(r); 
  • trunk/phobos/std/regex.d

    r1558 r1571  
    247247/** 
    248248Construct a $(D Regex) object. Compile pattern with $(D attributes) 
    249249into an internal form for fast execution. 
    250250 
    251251Params: 
    252252pattern = regular expression 
    253253attributes = The _attributes (g, i, and m accepted) 
    254254 
    255255Throws: $(D Exception) if there are any compilation errors. 
    256256 */ 
    257     public static Regex opCall(String) 
    258     (String pattern, string attributes = null) 
    259     { 
    260         static Tuple!(String, string) lastReq; 
    261         static typeof(return) lastResult; 
    262         if (lastReq.field[0] == pattern && lastReq.field[1] == attributes) 
    263         { 
    264             // cache hit 
    265             return lastResult; 
    266         } 
    267         // cache miss         
    268         Regex result; 
    269         result.initialize(pattern, attributes); 
    270         lastReq.field[0] = cast(String) pattern.dup; 
    271         lastReq.field[1] = cast(string) attributes.dup; 
    272         lastResult = result; 
    273         return result; 
    274         //return new RegexImpl(pattern, attributes); 
     257    this(String)(String pattern, string attributes = null) 
     258    { 
     259        compile(pattern, attributes); 
    275260    } 
    276261 
    277262    unittest 
    278263    { 
    279264        debug(regex) printf("regex.opCall.unittest()\n"); 
    280265        auto r1 = Regex("hello", "m"); 
    281266        string msg; 
    282267        try 
    283268        { 
    284269            auto r2 = Regex("hello", "q"); 
     
    15121497                } 
    15131498            } 
    15141499        } 
    15151500    } 
    15161501} 
    15171502 
    15181503/// Ditto 
    15191504Regex!(Unqual!(typeof(String.init[0]))) regex(String) 
    15201505(String pattern, string flags = null) 
    15211506{ 
    1522     return typeof(return)(pattern, flags); 
     1507    static Tuple!(String, string) lastReq; 
     1508    static typeof(return) lastResult; 
     1509    if (lastReq.field[0] == pattern && lastReq.field[1] == flags) 
     1510    { 
     1511        // cache hit 
     1512        return lastResult; 
     1513    } 
     1514 
     1515    auto result = typeof(return)(pattern, flags); 
     1516 
     1517    lastReq.field[0] = cast(String) pattern.dup; 
     1518    lastReq.field[1] = cast(string) flags.dup; 
     1519    lastResult = result; 
     1520 
     1521    return result; 
    15231522} 
    15241523 
    15251524/** 
    15261525$(D RegexMatch) is the type returned by a call to $(D match). It 
    15271526stores the matching state and can be inspected and iterated. 
    15281527 */ 
    15291528struct RegexMatch(Range = string) 
    15301529{ 
    15311530    alias typeof(Range.init[0]) E; 
    15321531    // Engine 
  • trunk/phobos/std/stdio.d

    r1565 r1571  
    15721572  } 
    15731573---- 
    15741574 
    15751575 In case of an I/O error, an $(D StdioException) is thrown. 
    15761576 */ 
    15771577 
    15781578struct lines 
    15791579{ 
    15801580    private File f; 
    15811581    private dchar terminator = '\n'; 
    1582     private string fileName; 
    1583  
    1584     static lines opCall(File f, dchar terminator = '\n') 
    1585     { 
    1586         lines result; 
    1587         result.f = f; 
    1588         result.terminator = terminator; 
    1589         return result; 
     1582    // private string fileName;  // Curretly, no use 
     1583 
     1584    this(File f, dchar terminator = '\n') 
     1585    { 
     1586        this.f = f; 
     1587        this.terminator = terminator; 
    15901588    } 
    15911589 
    15921590    // Keep these commented lines for later, when Walter fixes the 
    15931591    // exception model. 
    15941592 
    15951593//     static lines opCall(string fName, dchar terminator = '\n') 
    15961594//     { 
    15971595//         auto f = enforce(fopen(fName), 
    15981596//             new StdioException("Cannot open file `"~fName~"' for reading")); 
    15991597//         auto result = lines(f, terminator); 
     
    18221820 except for the last one, in which case $(D buffer.length) may 
    18231821 be less than 4096 (but always greater than zero). 
    18241822 
    18251823 In case of an I/O error, an $(D StdioException) is thrown. 
    18261824*/ 
    18271825 
    18281826struct chunks 
    18291827{ 
    18301828    private File f; 
    18311829    private size_t size; 
    1832     private string fileName; 
    1833  
    1834     static chunks opCall(File f, size_t size) 
    1835     { 
    1836         assert(size); 
    1837         chunks result; 
    1838         result.f = f; 
    1839         result.size = size; 
    1840         return result; 
     1830    // private string fileName; // Currently, no use 
     1831 
     1832    this(File f, size_t size) 
     1833    in 
     1834    { 
     1835        assert(size, "size must be larger than 0"); 
     1836    } 
     1837    body 
     1838    { 
     1839        this.f = f; 
     1840        this.size = size; 
    18411841    } 
    18421842 
    18431843//     static chunks opCall(string fName, size_t size) 
    18441844//     { 
    18451845//         auto f = enforce(fopen(fName), 
    18461846//             new StdioException("Cannot open file `"~fName~"' for reading")); 
    18471847//         auto result = chunks(f, size); 
    18481848//         result.fileName  = fName; 
    18491849//         return result; 
    18501850//     } 
  • trunk/phobos/std/typecons.d

    r1568 r1571  
    724724                stripped = another.stripped; 
    725725            } 
    726726            static if (is(T == const U)) 
    727727            { 
    728728                // safely assign immutable to const 
    729729                void opAssign(Rebindable!(immutable U) another) 
    730730                { 
    731731                    stripped = another.stripped; 
    732732                } 
    733733            } 
    734             static Rebindable opCall(T initializer) 
     734            this(T initializer) 
    735735            { 
    736                 Rebindable result; 
    737                 result = initializer; 
    738                 return result; 
     736                opAssign(initializer); 
    739737            } 
    740738            alias original get; 
    741739            T opDot() { 
    742740                return original; 
    743741            } 
    744742        } 
    745743    } 
    746744} 
    747745 
    748746unittest 
  • trunk/phobos/std/variant.d

    r1519 r1571  
    465465        default: assert(false); 
    466466        } 
    467467        return 0; 
    468468    } 
    469469 
    470470public: 
    471471    /** Constructs a $(D_PARAM VariantN) value given an argument of a 
    472472     * generic type. Statically rejects disallowed types. 
    473473     */ 
    474474 
    475     static VariantN opCall(T)(T value) 
     475    this(T)(T value) 
    476476    { 
    477477        static assert(allowed!(T), "Cannot store a " ~ T.stringof 
    478478            ~ " in a " ~ VariantN.stringof); 
    479         VariantN result; 
    480         result.opAssign(value); 
    481         return result; 
     479        opAssign(value); 
    482480    } 
    483481 
    484482    /** Assigns a $(D_PARAM VariantN) from a generic 
    485483     * argument. Statically rejects disallowed types. */ 
    486484 
    487485    VariantN opAssign(T)(T rhs) 
    488486    { 
    489487        //writeln(typeid(rhs)); 
    490488        static assert(allowed!(T), "Cannot store a " ~ T.stringof 
    491489            ~ " in a " ~ VariantN.stringof ~ ". Valid types are "