Home » Community » Newbie corner » Map with unique keys and transfer semantics?
Map with unique keys and transfer semantics? [message #46465] |
Fri, 13 May 2016 05:09  |
Infausto
Messages: 28 Registered: June 2008
|
Promising Member |
|
|
Looking at docs i cannot find any map container that allows only unique keys and have transfer semantics.
ValueMap supports replace of value by key lockup, but it has no transfers semantics.
OTOH VectorMap don't support replacing value by key lockup, but has transfers sematincs.
Any hybrid map that supports this two requirements?
Thanks in advance.
|
|
|
Re: Map with unique keys and transfer semantics? [message #46472 is a reply to message #46465] |
Sat, 14 May 2016 05:28   |
Lance
Messages: 656 Registered: March 2007
|
Contributor |
|
|
If VectorMap otherwise satisfy your need, I would use VectorMap as it appears to be more economic. You have control over the VectorMap object, so you can enforce uniqueness by yourself. If its going to be exposed to somebody else, enclose it in a class and expose Add method that would either replace existing value (value as in key-value pair) or throw or return false...
The fact VectorMap allow multiple record to have the same key (kind of like std::multimap ) should not prevent you from enforcing uniqueness as you have full control over its object.
Just my 2 cents.
[Updated on: Sat, 14 May 2016 05:30] Report message to a moderator
|
|
|
|
|
Re: Map with unique keys and transfer semantics? [message #46486 is a reply to message #46481] |
Sun, 15 May 2016 14:21  |
Lance
Messages: 656 Registered: March 2007
|
Contributor |
|
|
Suppose the document is right, ie. FindAdd returns negative if it added a new entry, you can simply add a call to abs(), or you can even compose a method doing what the current FindAdd is doing. The code and logic is open, the "key, value" are protected memebers of AMap so that inherited classes can access freely. Not much work added really.
|
|
|
Goto Forum:
Current Time: Tue Apr 29 23:15:23 CEST 2025
Total time taken to generate the page: 0.04502 seconds
|