In the below code aim traversing through the map separately and fetching keys and values , Is there a way that i could do it per entry not separately i need to join key and its value (which is a structure here )
#include <boost/algorithm/string.hpp>
#include <boost/range/adaptors.hpp>
#include <vector>
#include <string>
#include <functional>
#include <iostream>
struct valueInfo
{
std::string val1;
std::string val2;
std::string val3;
valueInfo(const std::string A, const std::string B, const std::string C):val1(A),val2(B),val3(C){}
};
typedef std::map<std::string,valueInfo*> AssetMap ;
void foo(const AssetMap& pList)
{
using namespace boost::adaptors;
for (const auto & key : pList | boost::adaptors::map_keys ) {
std::cout << key << " ";
}
for (const auto & key : pList | boost::adaptors::map_values) {
std::cout << key->val1 << key->val2<< key->val3<< "\n";
}
}
int main()
{
AssetMap myMap;
std::string key = "11233";
valueInfo *myvalues = new valueInfo ("Tejas","Male","Employee");
//std::cout<<myvalues;
//myMap.insert(std::make_pair(key, myvalues));
myMap.insert(std::make_pair(key, myvalues));
myMap.insert(std::make_pair("111", myvalues));
myMap.insert(std::make_pair("222", myvalues));
myMap.insert(std::make_pair("333", myvalues));
myMap.insert(std::make_pair("444", myvalues));
foo(myMap);
}
Current Output
111 11233 222 333 444 TejasMaleEmployee
TejasMaleEmployee
TejasMaleEmployee
TejasMaleEmployee
TejasMaleEmployee
Desired output
111{TejasMaleEmployee}
11233{TejasMaleEmployee}
222{TejasMaleEmployee}
Thanks in advance Tejas