www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - contains method on immutable sorted array

reply Andrey <saasecondbox yandex.ru> writes:
Hello,
I have got a global constant immutable array:
 immutable globalvalues = sort(cast(wstring[])["й", "ц", "ук", 
 "н"]);
Somewhere in program I want to check an existance:
 globalvalues.contains("ук"w).writeln;
But get an error:
 Error: template std.range.SortedRange!(wstring[], "a < 
 b").SortedRange.contains cannot deduce function from argument 
 types !()(wstring) immutable, candidates are:
 /dlang/ldc-1.17.0/bin/../import/std/range/package.d(10993):
 std.range.SortedRange!(wstring[], "a < 
 b").SortedRange.contains(V)(V value) if 
 (isRandomAccessRange!Range)
Why I can't check?
Oct 21 2019
parent reply Nicholas Wilson <iamthewilsonator hotmail.com> writes:
On Monday, 21 October 2019 at 10:14:54 UTC, Andrey wrote:
 Hello,
 I have got a global constant immutable array:
 immutable globalvalues = sort(cast(wstring[])["й", "ц", "ук", 
 "н"]);
Somewhere in program I want to check an existance:
 globalvalues.contains("ук"w).writeln;
But get an error:
 Error: template std.range.SortedRange!(wstring[], "a < 
 b").SortedRange.contains cannot deduce function from argument 
 types !()(wstring) immutable, candidates are:
 /dlang/ldc-1.17.0/bin/../import/std/range/package.d(10993):
 std.range.SortedRange!(wstring[], "a < 
 b").SortedRange.contains(V)(V value) if 
 (isRandomAccessRange!Range)
Why I can't check?
pragma(msg,typeof(globalvalues)); gives immutable(SortedRange!(wstring[], "a < b")) and (cast(SortedRange!(wstring[], "a < b"))globalvalues).contains("ук"w).writeln; works, so I guess contains doesn't work with immutable? If you can do some more research into this and confirm it then, please file a bug report.
Oct 21 2019
parent Andrey <saasecondbox yandex.ru> writes:
On Monday, 21 October 2019 at 20:44:29 UTC, Nicholas Wilson wrote:
 works, so I guess contains doesn't work with immutable?
 If you can do some more research into this and confirm it then, 
 please file a bug report.
As I understand - yes. It doesn't work with immutable object. Also I see the same problem with 'const' and 'shared' object:
 shared values = sort(cast(wstring[])["й", "ц", "ук", "н"]);
 const values = sort(cast(wstring[])["й", "ц", "ук", "н"]);
 values.contains("ук"w).writeln; // error
So you think it is a bug in compiler?
Oct 21 2019