I have a map in a multi-threaded application matching a class called uuid with a pointer. What I want to know if the insert operation failed.
eg.
_mymap.insert(hint, MyMap::value_type(entry.uuid, itemptr));
Does this raise an exception or something if it doesn't work?
insert, , , . , , - . , (.. ). , , , . , , ( bool), . , , , ++ .
.
... pair::first, , , , . pair::second true, false, .
pair::first
pair::second
:
if(mp.insert(make_pair(key, value)).second == false) { cout << "Insertion failed. Key was present" }
typedef std::map<std::string, int> map; map m; std::pair<map::iterator,bool> result = m.insert(std::make_pair("hi", 42));
result.second ,
, .
std:: map:: insert , .
std:: map:: insert , , std:: bad_alloc.
, , STL, . . .
, ?
- , bool true, false, , .pr, , pr.first , * (pr.first). bool pr -, pr.second.The second insertion member function, hint, returns an iterator that indicates where the element was inserted into the map.
- , bool true, false, , .
pr, , pr.first , * (pr.first). bool pr -, pr.second.
The second insertion member function, hint, returns an iterator that indicates where the element was inserted into the map.
Source: http://msdn.microsoft.com/en-us/library/81ac0zkz(v=vs.80).aspx
Using the help method, insert a pair from the same first and second that you are sure not on the map (for example, (size_t) -1 for a size map, for example). If the returned iterator has this invalid value, it was inserted if it was not found on the map. Then the iterator returns. Example: insert the pair p (2,4) into the map m ((0, 1), (2, 3), (4, 5)).
std::map<size_t, size_t>::iterator ihint (map.begin ()), k (ihint); ihint++; std::pair<size_t, size_t> pfoo (2, (size_t) -1); k = m.insert (ihint, pfoo); if (k->second == (size_t) -1) { //the pair was inserted } else { //the pair was in the map } //you set the good second : k->second = 4
Source: https://habr.com/ru/post/1794462/More articles:General settings - androidVB.NET - Continue for Alternative for Visual Studio 2003 - vb.netredefinition of Devise :: Mailer - ruby-on-railsIE browser for browser - internet-explorerVirtualization Wrap Panel WPF - a free solution? - virtualizationEncrypting a Field Value in a Linq-to-Sql Object - .nethttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1794464/restrict-access-to-page-for-anonymous-users-in-drupal&usg=ALkJrhj7oOdxcBfY1B3OJD38bnHhLd_yMwAndroid scan subnet - javaHow to implement a category newsletter - drupalАлгоритм сортировки чисел, суммируемых на общий и соблюдающий критерии в python - pythonAll Articles