[Issue 5491] filter cannot be used in a function?

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jan 26 10:42:24 PST 2011


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



--- Comment #1 from Timofei Bolshakov <tbolsh at gmail.com> 2011-01-26 10:40:17 PST ---
Following variant do not work either:
______________________________________________________________________________
import std.algorithm, std.conv, std.stdio;

enum UsbDevType: uint { indifferent = 0, parent_of_checked = 1, hub_dub_7 =
0x2001f103, spider_hub = 0x05e30608, gateway = 0x11A03232 }
struct UsbDevice { //{{{ 
    UsbDevType dev_type;
    // not essential here ...
    string toString(){ return to!string( dev_type ); }
}

unittest{
    auto devices  = [ UsbDevice( UsbDevType.gateway ), UsbDevice(
UsbDevType.indifferent ), UsbDevice( UsbDevType.hub_dub_7 ) ];
    auto gateways = filter!( "a.dev_type == UsbDevType.gateway" )( devices );
    foreach( UsbDevice dev; gateways ) writeln( dev.toString() );
}
______________________________________________________________________________
compiler tells:
tbolshakov at owner-laptop:~/projects/D$ dmd -unittest bugs/tbolsh_d2_bug3.d 
/usr/include/d/dmd/phobos/std/functional.d(74): Error: static assert  "Bad
unary function: a.dev_type == UsbDevType.gateway for type UsbDevice"
/usr/include/d/dmd/phobos/std/functional.d(87):        instantiated from here:
Body!(UsbDevice)
/usr/include/d/dmd/phobos/std/algorithm.d(857):        instantiated from here:
result!(UsbDevice)
/usr/include/d/dmd/phobos/std/algorithm.d(842):        instantiated from here:
Filter!(result,UsbDevice[])
bugs/tbolsh_d2_bug3.d(12):        instantiated from here: filter!(UsbDevice[])

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


More information about the Digitalmars-d-bugs mailing list