Re: Calling assumeSorted on const(std.container.Array)

2023-03-26 Thread Olivier Prat via Digitalmars-d-learn
On Sunday, 26 March 2023 at 02:16:15 UTC, Steven Schveighoffer wrote: On 3/25/23 9:45 AM, Olivier Prat wrote: [...] It's because a Range keeps a copy of the array (Array is a reference counted type). Since that is labeled `const`, then editing the Range is forbidden. Inside SortedRange,

Re: Calling assumeSorted on const(std.container.Array)

2023-03-25 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/25/23 9:45 AM, Olivier Prat wrote: Would someone explain the exact nature of this error as I fail to understand as how just telling that an Array ConstRange is assumed to be sorted actually modifies anything?? It's because a Range keeps a copy of the array (Array is a reference counted

Re: Calling assumeSorted on const(std.container.Array)

2023-03-25 Thread Ali Çehreli via Digitalmars-d-learn
On 3/25/23 09:31, Olivier Prat wrote: On Saturday, 25 March 2023 at 13:45:36 UTC, Olivier Prat wrote: I'm trying to call assumeSorted on a const(Array) using this code snippet: [...] In a similar fashion, a number of methods in SortedRange do not compile if called on a const(SortedRange

Re: Calling assumeSorted on const(std.container.Array)

2023-03-25 Thread Olivier Prat via Digitalmars-d-learn
On Saturday, 25 March 2023 at 13:45:36 UTC, Olivier Prat wrote: I'm trying to call assumeSorted on a const(Array) using this code snippet: [...] In a similar fashion, a number of methods in SortedRange do not compile if called on a const(SortedRange) or immutable(SortedRange

Calling assumeSorted on const(std.container.Array)

2023-03-25 Thread Olivier Prat via Digitalmars-d-learn
I'm trying to call assumeSorted on a const(Array) using this code snippet: void test(T)(const ref Array!T a) { auto b = a[].assumeSorted; writeln(b); } void main() { Array!int a = [1, 5, 7, 8, 15, 100]; test(a); } Unfortunately, I keep

assumeSorted can't access private function when compiling with -debug

2016-01-09 Thread FreeSlave via Digitalmars-d-learn
Here's code: private { import std.algorithm; import std.range; import std.typecons; alias Tuple!(int, string) Data; } private bool myCmp(Data a, Data b) { return a[0] < b[0]; } auto bar() { return [Data(1, "one"), Data(2, "two")].assumeSor

assumeSorted?

2010-08-24 Thread Steven Schveighoffer
What happened to assumeSorted in 2.048? When trying to do a find on an assumeSorted range, it fails: dcollections/HashSet.d(28): Error: template std.algorithm.find(alias pred = a == b,R,E) if (isInputRange!(R) is(typeof(binaryFun!(pred)(haystack.front,needle)) : bool)) does not match