Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » [FEATURE REQUEST] bool AMap::HasKey(K key) ;
[FEATURE REQUEST] bool AMap::HasKey(K key) ; [message #43118] Thu, 08 May 2014 17:41 Go to next message
omari is currently offline  omari
Messages: 264
Registered: March 2010
Experienced Member
Hi,

instead of :

if (map.Find(k) >= 0)


I like to have a function that returns a bool depending on whether it find the key or not:

if(map.HasKey(k))
or
if(map.ContainsKey(k))


regards
omari.
Re: [FEATURE REQUEST] bool AMap::HasKey(K key) ; [message #43138 is a reply to message #43118] Fri, 16 May 2014 09:04 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, I understand that comparing for >= 0 might be confusing at first, but, generally:

- complexity of HasKey is the same as Find

- Find provides more information

- there are many places with similar situation, e.g. String::Find

- less methods in interface are usually better

Mirek
Re: [FEATURE REQUEST] bool AMap::HasKey(K key) ; [message #43139 is a reply to message #43138] Fri, 16 May 2014 11:04 Go to previous message
omari is currently offline  omari
Messages: 264
Registered: March 2010
Experienced Member
Thank you Mirek,

I do not want a replacement of Find ().

usually, i check if the map contains a key or not, in this situation, the position of the key (if exist) does not interest me, then there is a risk of forgetting of (>= 0) (that happened to me twice)

a function (bool Haskey (K k)) seems more natural in this situation.

for example
bool Haskey (K& k){return ++Find(k));}


or

bool Haskey (K& k){return Find (k)>= 0);}




regards
omari.
Previous Topic: [FIXED] String::Replace(empty string,) => Out of memory!
Next Topic: Unterminated processing info in XmlParser
Goto Forum:
  


Current Time: Fri Apr 19 11:10:48 CEST 2024

Total time taken to generate the page: 0.03647 seconds