-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCI.cpp
More file actions
94 lines (73 loc) · 2 KB
/
CI.cpp
File metadata and controls
94 lines (73 loc) · 2 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**
* \file CI.cpp
* \brief
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//-------------------------------------------------------------------------------------------------
struct CmpCI
{
bool operator() (
const std::string &key1,
const std::string &key2
) const
{
return ::strcasecmp(key1.c_str(), key2.c_str()) > 0;
}
};
using string_mmap_t = std::multimap<std::string, std::string, ::CmpCI>;
//-------------------------------------------------------------------------------------------------
int main()
{
bool bRv {};
const std::string targetC = "C";
const std::string targetD = "D";
const string_mmap_t values
{
{"a", "0"},
{"b", "1"},
{"c", "2"},
{targetC, "2"}
};
for (const auto &it : values) {
std::cout << it.first << " :: " << it.second << std::endl;
}
std::cout << std::endl << std::endl;
// Total Elements in the range 'c'
{
auto result = values.equal_range(targetC);
int count = std::distance(result.first, result.second);
std::cout << "Total values for key '" << targetC << "' are : " << count << std::endl;
bRv = (values.find(targetC) != values.end());
std::cout << STD_TRACE_VAR2(targetC, bRv) << std::endl << std::endl;
}
// Total Elements in the range 'd'
{
auto result = values.equal_range(targetD);
int count = std::distance(result.first, result.second);
std::cout << "Total values for key '" << targetD << "' are : " << count << std::endl;
bRv = (values.find(targetD) != values.end());
std::cout << STD_TRACE_VAR2(targetD, bRv) << std::endl << std::endl;
}
for (const auto &it : values) {
std::cout << it.first << " :: " << it.second << std::endl;
}
return 0;
}
//-------------------------------------------------------------------------------------------------
#if OUTPUT
c :: 2
C :: 2
b :: 1
a :: 0
********************************************************
Total values for key 'C' are : 2
targetC: C, bRv: 1
Total values for key 'D' are : 0
targetD: D, bRv: 0
c :: 2
C :: 2
b :: 1
a :: 0
#endif