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

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


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



--- Comment #2 from Timofei Bolshakov <tbolsh at gmail.com> 2011-01-26 10:50:03 PST ---
And this one does not compile:
__________________________________________________________________________________
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;
    ubyte usb_id;
    // not essential here ...
    string toString(){ return to!string( dev_type ); }
}
UsbDevice [ ubyte ] associate_devices( UsbDevice []devices ){//{{{
    UsbDevice [ubyte] retval; 
    foreach( UsbDevice dev ; devices ) retval[ dev.usb_id ] = dev;  
    return retval;
}//}}}

unittest{
    auto devices  = [ UsbDevice( UsbDevType.gateway, 1 ), UsbDevice(
UsbDevType.indifferent, 2 ), UsbDevice( UsbDevType.hub_dub_7, 3 ) ];
    auto devmap = associate_devices( 
        filter!( delegate bool( UsbDevice a ){ return a.dev_type ==
UsbDevType.gateway; } )( devices ) );
    foreach( UsbDevice dev; gateways ) writeln( dev.toString() );
}

void main(){}
______________________________________________________________________________
Telling:
tbolshakov at owner-laptop:~/projects/D$ dmd -unittest bugs/tbolsh_d2_bug4.d 
bugs/tbolsh_d2_bug4.d(18): Error: function tbolsh_d2_bug4.associate_devices
(UsbDevice[] devices) is not callable using argument types
(Filter!(__dgliteral1,UsbDevice[]))
bugs/tbolsh_d2_bug4.d(19): Error: cannot implicitly convert expression
(filter(devices)) of type Filter!(__dgliteral1,UsbDevice[]) to UsbDevice[]
bugs/tbolsh_d2_bug4.d(20): Error: undefined identifier gateways
bugs/tbolsh_d2_bug4.d(20): Error: foreach: _error_ is not an aggregate type

-- 
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