Benchmark of D against other languages
bearophile via Digitalmars-d
digitalmars-d at puremagic.com
Thu Apr 2 01:53:58 PDT 2015
weaselcat:
>>> was it a conscious decision to make the AA [] operator not
>>> work like map/etc in C++?
>>
>> What do you mean?
>
> accessing a non-existing element in C++'s map/unordered_map
> inserts the default instead of raising an exception
>
> int main(int argc, char *argv[])
> {
> std::unordered_map<std::string, int> test;
> std::cout << test["hello"] << std::endl;
> return 0;
> }
>
> prints 0
>
> void main()
> {
> int[string] test;
> writeln(test["hello"]);
> }
>
> core.exception.RangeError at source/main.d(9): Range violation
Yes, it was a conscious decision, because here C++ behaves in a
very bug-prone way. Sometimes C++ is a bad example to follow
(like with permutations generations, that currently is not a
Range in Phobos for the wrong reasons).
Bye,
bearophile
More information about the Digitalmars-d
mailing list