www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Multidimension AA's and remove

reply "Prudence" <Pursuit Happyness.All> writes:
Error: template std.algorithm.mutation.remove cannot deduce 
function from argument types !()(bool delegate(void*, uint, uint, 
int)[], void), candidates are:
std.algorithm.mutation.remove(SwapStrategy s = 
SwapStrategy.stable, Range, Offset...)(Range range, Offset 
offset) if (s != SwapStrategy.stable && 
isBidirectionalRange!Range && hasLvalueElements!Range && 
hasLength!Range && Offset.length >= 1)
std.algorithm.mutation.remove(SwapStrategy s = 
SwapStrategy.stable, Range, Offset...)(Range range, Offset 
offset) if (s == SwapStrategy.stable && 
isBidirectionalRange!Range && hasLvalueElements!Range && 
Offset.length >= 1)
std.algorithm.mutation.remove(alias pred, SwapStrategy s = 
SwapStrategy.stable, Range)(Range range) if 
(isBidirectionalRange!Range && hasLvalueElements!Range)


coming from

static TValue[][TKey] s;

(s[key]).remove(c => value == c);

How to disambiguate or do what I'm trying to do:

I'm trying to create an associative array with multiple values 
per key. Hence the AA with an extra dynamic array on it.

I've tried

TValue[TKey][] s;

and other stuff without success(essentially same error about not 
being able to deduce remove)

I would expect (s[key]) to return the normal array.

I've tried this too.
remove!(c => this.Value == c)(store[this.Key], 
SwapStrategy.unstable);



At the very least: Is T[][S] an associative array with keys of 
type S and values of an array of type T or is it backwards? Also, 
how to disabmiguate

Thanks.
Sep 11 2015
parent reply "NX" <nightmarex1337 hotmail.com> writes:
On Saturday, 12 September 2015 at 03:44:50 UTC, Prudence wrote:
 At the very least: Is T[][S] an associative array with keys of 
 type S and values of an array of type T or is it backwards? 
 Also, how to disambiguate

 Thanks.
Indeed. void main() { import std.stdio : writeln, std.algorithm.mutation : remove; int[][string] heh = [ "hah":[ 0, 10, 15, 20 ] ]; heh["hah"][0] = 5; foreach(var; heh["hah"]) writeln(var); writeln(); heh["hah"] = remove!(c => (c == 15))(heh["hah"]); foreach(var; heh["hah"]) writeln(var); } Giving me: 5 10 15 20 5 10 20
Sep 11 2015
parent "NX" <nightmarex1337 hotmail.com> writes:
On Saturday, 12 September 2015 at 05:54:13 UTC, NX wrote:
 import std.stdio : writeln, std.algorithm.mutation : remove;
Ooops, this is so wrong! Corrected version: void main() { import std.stdio : writeln; import std.algorithm.mutation : remove; int[][string] heh = [ "heh":[ 0, 10, 15, 20 ] ]; heh["heh"][0] = 5; writeln(heh); // ["heh":[5, 10, 15, 20]] heh["heh"] = remove!(c => (c == 15))(heh["heh"]); writeln(heh); // ["heh":[5, 10, 20]] }
Sep 11 2015