Consider the following:
If you take the documentation at face value, that says it results in undefined behavior to add multiple items like so:
That may be valid, but what if, as a developer, you have intimate knowledge of what the actual underlying data structure is?
Pop quiz time:
The documentation above is valid for which data structure:
a. std::map
b. std::vector
c. std::set
The actual underlying in this example above is a vector, so of course it's perfectly fine to add whatever I want and as much as I want. Even if it was another container with a different paradigm, the behavior is still well defined. It overwrites the last value.
Turns out the header was just outdated, some annoying technical debt left over from a previous iteration.
Sometimes you can't trust a header. Go to source if you have it.
class SomeApi {
/*
Add name value pair to the underlying object.
Adding multiple pairs with the same name does not
guarantee which one is added.
*/
void add(std::string& name, std::string& value);
};
If you take the documentation at face value, that says it results in undefined behavior to add multiple items like so:
SomeApi instance;
instance.add("bob", "apple");
instance.add("bob", "banana");
That may be valid, but what if, as a developer, you have intimate knowledge of what the actual underlying data structure is?
Pop quiz time:
The documentation above is valid for which data structure:
a. std::map
b. std::vector
c. std::set
Spoiler
The actual underlying in this example above is a vector, so of course it's perfectly fine to add whatever I want and as much as I want. Even if it was another container with a different paradigm, the behavior is still well defined. It overwrites the last value.
Turns out the header was just outdated, some annoying technical debt left over from a previous iteration.
Sometimes you can't trust a header. Go to source if you have it.
1 Comments On This Entry
Page 1 of 1
Martyr2
12 February 2015 - 02:46 PM
Well that sounds like an epic fail. The goal should be that you should not have to go to source. Hopefully that didn't cause you a headache from banging your head on your keyboard too much. I know it would have done that for me.
Page 1 of 1
← January 2022 →
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 | 31 |
Tags
My Blog Links
Recent Entries
Recent Comments
Search My Blog
4 user(s) viewing
4 Guests
0 member(s)
0 anonymous member(s)
0 member(s)
0 anonymous member(s)



1 Comments









|