You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
post (@kyllingstad) commented on 2016-02-10T21:20:57Z
I think these are problems with the design of 'inout' rather than with Phobos. Perhaps it could be worked around with careful use of std.typecons.Unqual, but that seems unfeasible to do, as there are *a lot* of types that have this problem. (Almost all ranges, for example, at least the ones that have internal caching.)
Therefore, I'm recategorising this as a DMD/spec issue. Here's a test case that doesn't involve Phobos:
struct Ptr(T){ T* ptr; alias ptr this;}Ptr!T takePtr(T)(ref T obj){ return Ptr!T(&obj);}inout(int[]) fun(inout int[] arr){ auto p = takePtr(arr); return *p;}
I wonder if we could invent a rule by which inout gets converted to const in some places.
David Watkins reported this on 2014-06-11T21:51:39Z
Transferred from https://issues.dlang.org/show_bug.cgi?id=12893
CC List
Description
import std.algorithm; import std.array; import std.range; struct Data { string name; alias name this; } inout(Data) findData(inout(Data)[] arr, string name) { auto sorted = assumeSorted(arr); auto found = sorted.equalRange(name); return found.empty ? Data.init : found.front; } void main() { Data[] arr; arr ~= Data("Alice"); arr ~= Data("Carol"); arr ~= Data("Bob"); sort(arr); auto data = findData("Bob"); } Fails with: \src\phobos\std\range.d(8340): Error: variable std.range.SortedRange!(inout(Data)[], "a < b").SortedRange._input only parameters or stack based variables can be inout \src\phobos\std\range.d(8839): Error: template instance std.range.SortedRange!(inout(Data)[], "a < b") error instantiating instantiated from here: assumeSorted!("a < b", inout(Data)[])The text was updated successfully, but these errors were encountered: