digitalmars.D.learn - DList!int.remove(range.takeOne) - workarounds?
- Algo (17/17) Oct 12 2014 DList seems to have an issue with remove:
- monarch_dodra (6/23) Oct 12 2014 There is (unfortunatly) no support for takeOne in DList.
- Algo (2/27) Oct 12 2014 Thanks, linearRemove is fine, sorry for the misunderstanding
DList seems to have an issue with remove: void main() { import std.container, std.range, std.algorithm; auto list = DList!int([1, 2, 4, 6]); auto res = find(list[], 2); list.remove(res); //ok /* list.remove(res.takeOne); Error: function std.container.dlist.DList!int.DList.remove (Range r) is not callable using argument types (Result) list.remove(res.take(1)); Error: function std.container.dlist.DList!int.DList.remove (Range r) is not callable using argument types (Take!(Range)) */ } Are there any known workarounds besides linearRemove?
Oct 12 2014
On Sunday, 12 October 2014 at 09:45:22 UTC, Algo wrote:DList seems to have an issue with remove: void main() { import std.container, std.range, std.algorithm; auto list = DList!int([1, 2, 4, 6]); auto res = find(list[], 2); list.remove(res); //ok /* list.remove(res.takeOne); Error: function std.container.dlist.DList!int.DList.remove (Range r) is not callable using argument types (Result) list.remove(res.take(1)); Error: function std.container.dlist.DList!int.DList.remove (Range r) is not callable using argument types (Take!(Range)) */ } Are there any known workarounds besides linearRemove?There is (unfortunatly) no support for takeOne in DList. However, "linearRemove" is not a workaround or worst than remove. It is just that it accepts a wider range of input, when O(1) cannot be guaranteed. If you are operating with a range of length 1, then linearRemove is still O(1).
Oct 12 2014
On Sunday, 12 October 2014 at 10:35:19 UTC, monarch_dodra wrote:On Sunday, 12 October 2014 at 09:45:22 UTC, Algo wrote:Thanks, linearRemove is fine, sorry for the misunderstandingDList seems to have an issue with remove: void main() { import std.container, std.range, std.algorithm; auto list = DList!int([1, 2, 4, 6]); auto res = find(list[], 2); list.remove(res); //ok /* list.remove(res.takeOne); Error: function std.container.dlist.DList!int.DList.remove (Range r) is not callable using argument types (Result) list.remove(res.take(1)); Error: function std.container.dlist.DList!int.DList.remove (Range r) is not callable using argument types (Take!(Range)) */ } Are there any known workarounds besides linearRemove?There is (unfortunatly) no support for takeOne in DList. However, "linearRemove" is not a workaround or worst than remove. It is just that it accepts a wider range of input, when O(1) cannot be guaranteed. If you are operating with a range of length 1, then linearRemove is still O(1).
Oct 12 2014