Avoiding const?
ixid
nuaccount at gmail.com
Tue Feb 21 18:07:38 PST 2012
BLM:
const(char)[][] words = set.keys.sort;
Converting the function's return type to const and doing this did
what I wanted elegantly, I didn't realise I could apply sort to a
const like this.
Trying to use .dup like this:
char[][] words = set.keys.dup;
gives this error message:
Error: cannot implicitly convert expression (_adSort(_adDupT(&
D13TypeInfo_AAxa6__initZ,set.keys()),& D11TypeInfo_Aa6__initZ))
of type const(char)[][] to char[][]
Isn't there any sort of cast(nonconst) equivalent?
char[][] words;
words.length = set.keys.length;
foreach(size_t i, const char[] text; set.keys) {
words[i] = text.dup;
}
This also worked, thank you for the suggestion.
Jonathan M Davies:
>bool[char[]] set;
>doesn't work, because the key isn't immutable. When he tries to
>use it the compiler will scream at him (though ideally, it
>wouldn't even let him declare it - there's a bug report on that).
When I use a key with it I use:
set[cast(immutable) key] = true;
This doesn't generate any compiler errors.
auto words2 = set.keys.sort;
auto words2 = set.keys.dup.sort;
both did what I wanted using string. Thank you, I'll convert
everything to strings. I guess I created my own difficulties by
using char arrays.
More information about the Digitalmars-d-learn
mailing list