Changeset 1942

Show
Ignore:
Timestamp:
08/28/10 20:05:56 (2 years ago)
Author:
dsimcha
Message:

std.traits: Add isAssignable.

Files:

Legend:

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

    r1922 r1942  
    77 
    88    $(WHATSNEW 
    9     $(LI Added FFT to std.numeric.) 
    10     $(LI Added convenience functions for Rebindable.) 
     9    $(LI std.numeric:  Added FFT.) 
    1110    $(LI std.process: Added environment, an AA-like interface for environment variables.) 
    1211    $(LI std.range:  Iota, Stride, Transversal, FrontTransveral now support slicing where possible.) 
    1312    $(LI std.range:  Added Lockstep, hasLvalueElements.) 
    1413    $(LI std.range:  Added virtual function-based wrappers (InputRangeObject, OutputRangeObject) for when a binary interface to a range is required.) 
    15     $(L1 std.traits:  Added isIterable, ForeachType, isSafe, isUnsafe.) 
     14    $(LI std.typecons:  Added convenience functions for Rebindable.) 
     15    $(L1 std.traits:  Added isAssignable, isIterable, ForeachType, isSafe, isUnsafe.) 
    1616    $(LI std.typetuple:  Added anySatisfy.) 
    1717    $(LI $(LINK2 phobos/std_stopwatch.html,std.swopwatch):  Added StopWatch, Ticks, systime, apptime, comparingBenchmark, measureTime.) 
  • trunk/phobos/std/traits.d

    r1925 r1942  
    18841884} 
    18851885 
     1886/** 
     1887Returns $(D true) iff a value of type $(D Rhs) can be assigned to a variable of 
     1888type $(D Lhs). 
     1889 
     1890Examples: 
     1891--- 
     1892static assert(isAssignable!(long, int)); 
     1893static assert(!isAssignable!(int, long)); 
     1894static assert(isAssignable!(const(char)[], string)); 
     1895static assert(!isAssignable!(string, char[])); 
     1896--- 
     1897*/ 
     1898template isAssignable(Lhs, Rhs) { 
     1899    enum bool isAssignable = is(typeof({ 
     1900        Lhs l; 
     1901        Rhs r; 
     1902        l = r; 
     1903        return l; 
     1904    })); 
     1905} 
     1906 
     1907unittest { 
     1908    static assert(isAssignable!(long, int)); 
     1909    static assert(!isAssignable!(int, long)); 
     1910    static assert(isAssignable!(const(char)[], string)); 
     1911    static assert(!isAssignable!(string, char[])); 
     1912} 
     1913 
    18861914 
    18871915/*