ctor for shared and immutable structs

Oleg B antidote32 at mail.ru
Tue Mar 4 15:53:51 PST 2014


why this code get errors?

[code]
/*  1 */struct PData
/*  2 */{
/*  3 */    immutable(ubyte)[] data; // ???
/*  4 */    pure this(T)( in T val ) { }
/*  5 */}
/*  6 */
/*  7 */unittest
/*  8 */{
/*  9 */    immutable(ubyte)[] data_a = [1,2,3];
/* 10 */    ubyte[] data_b = [1,2,3];
/* 11 */    auto a = PData( data_a );
/* 12 */    auto ca = const PData( data_a );
/* 13 */    auto ia = immutable PData( data_a );
/* 14 */    auto sa = shared PData( data_a );
/* 15 */    auto sca = shared const PData( data_a );
/* 16 */
/* 17 */    auto b = PData( data_b.idup );
/* 18 */    auto cb = const PData( data_b.idup );
/* 19 */    auto ib = immutable PData( data_b );
/* 20 */    auto sb = shared PData( data_b );
/* 21 */    auto scb = shared const PData( data_b );
/* 22 */}
[/code]

$ dmd -unittest -main -run purector.d
purector.d(13): Error: template purector.PData.__ctor cannot 
deduce function from argument types !()(immutable(ubyte)[]) 
immutable, candidates are:
purector.d(4):        purector.PData.__ctor(T)(in T val)
purector.d(14): Error: template purector.PData.__ctor cannot 
deduce function from argument types !()(immutable(ubyte)[]) 
shared, candidates are:
purector.d(4):        purector.PData.__ctor(T)(in T val)
purector.d(15): Error: template purector.PData.__ctor cannot 
deduce function from argument types !()(immutable(ubyte)[]) 
shared const, candidates are:
purector.d(4):        purector.PData.__ctor(T)(in T val)

why cannot deduce pure ctor?

if i change line 3
/*  3 */    immutable(ubyte)[] data; // ???
to
/*  3 */    ubyte[] data; // ???
all works

why i can't use immutable data in this case?


More information about the Digitalmars-d-learn mailing list