DList!int.remove(range.takeOne) - workarounds?

2014-10-12 Thread Algo via Digitalmars-d-learn

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?


Re: DList!int.remove(range.takeOne) - workarounds?

2014-10-12 Thread monarch_dodra via Digitalmars-d-learn

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).




Re: DList!int.remove(range.takeOne) - workarounds?

2014-10-12 Thread Algo via Digitalmars-d-learn

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:

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).


Thanks, linearRemove is fine, sorry for the misunderstanding