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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*++
Copyright (c) 2011 Microsoft Corporation
Module Name:
map_util.h
Abstract:
Some goodies for managing reference counters
stored in maps.
Author:
Leonardo (leonardo) 2011-06-07
Notes:
--*/
#pragma once
/**
\brief Decrement the reference counter of the keys and values stored in the map,
then reset the map.
*/
template<typename Mng, typename Map>
void dec_ref_key_values(Mng & m, Map & map) {
for (auto& kv : map) {
m.dec_ref(kv.m_key);
m.dec_ref(kv.m_value);
}
map.reset();
}
/**
\brief Decrement the reference counter of the keys stored in the map,
then reset the map.
*/
template<typename Mng, typename Map>
void dec_ref_keys(Mng & m, Map & map) {
for (auto& kv : map) {
m.dec_ref(kv.m_key);
}
map.reset();
}
/**
\brief Decrement the reference counter of the values stored in the map,
then reset the map.
*/
template<typename Mng, typename Map>
void dec_ref_values(Mng & m, Map & map) {
for (auto& kv : map) {
m.dec_ref(kv.m_value);
}
map.reset();
}