September 04, 2007 stlsoft::frequency_map: semantic change | ||||
---|---|---|---|---|
| ||||
I'm considering changing the semantics of operator[] in stlsoft::frequency_map to return 0, rather than throwing std::out_of_range, if a given key does not exist in the map. stlsoft::frequency_map<std::string> fm; fm.push("abc"); fm.push("abc"); fm.push("def"); assert(2 == fm["abc"]); assert(1 == fm["def"]); assert(0 == fm["ghi"]); // ** Currently, statement ** will throw an instance of std::bad_alloc Does anyone have a problem with / an opinion about this projected change? Cheers Matt |
September 05, 2007 Re: stlsoft::frequency_map: semantic change | ||||
---|---|---|---|---|
| ||||
Posted in reply to Matthew Wilson | Matthew Wilson Wrote:
> I'm considering changing the semantics of operator[] in stlsoft::frequency_map to return 0, rather than throwing std::out_of_range, if a given key does not exist in the map.
>
> stlsoft::frequency_map<std::string> fm;
>
> fm.push("abc");
> fm.push("abc");
> fm.push("def");
>
> assert(2 == fm["abc"]);
> assert(1 == fm["def"]);
> assert(0 == fm["ghi"]); // **
>
> Currently, statement ** will throw an instance of std::bad_alloc
>
> Does anyone have a problem with / an opinion about this projected change?
imo it is an improvement to the semantics. 0 is never going to be valid for an element in the fm, so there's no problem.
Jim
|
Copyright © 1999-2021 by the D Language Foundation