www.digitalmars.com         C & C++   DMDScript  

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

reply "Algo" <algo nonsense.com> writes:
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
parent reply "monarch_dodra" <monarchdodra gmail.com> writes:
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
parent "Algo" <algo nonsense.com> writes:
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
Oct 12 2014