mercredi 29 avril 2020

class std::set

I used to make a function which stores a json object into a map of strings (key) and a vector of strings (value) using this code :

#include <vector>
#include <map>
using VMap = std::map<std::string, std::vector<std::string> >;

VMap fileMapper (ptree const& config) 

{ 
    VMap mymap ; 
    for (auto& entry : config) {
        std::vector<std::string> val; 
        for (auto& element : boost::make_iterator_range(entry.second.equal_range(""))) {
            val.push_back(element.second.get_value<std::string>()); 
        } 
        mymap.insert(std::pair<std::string, std::vector<std::string>>(entry.first,val));
        } 
    return mymap;
} 

I'm looking to make the same action using a set of strings instead of a vector of strings, I've tried to make a small modification to the code :

#include <map>
#include <set>

using VMap = std::map<std::string, std::set<std::string> >;

VMap fileMapper (ptree const& config) 

{ 
    VMap mymap ; 
    for (auto& entry : config) {
        std::set<std::string> val; 
        for (auto& element : boost::make_iterator_range(entry.second.equal_range(""))) {
            val.push(element.second.get_value<std::string>()); 
        } 
        mymap.insert(std::pair<std::string, std::set<std::string>>(entry.first,val));
        } 
    return mymap;
} 

And I've got this error : class std::set > ' has no member named 'push'

Any idea ?

Aucun commentaire:

Enregistrer un commentaire