Dominique Devienne <ddevienne <at> gmail.com> writes:
On Wed, Apr 15, 2015 at 1:23 PM, David Hagood <david.hagood <at> gmail.com> wrote:
One problem I see with using a set is that the whole data type is used as the key [...]
Adding to Dominique's answer, here's an example of how the thing could be done with Boost.MultiIndex: #include <boost/multi_index_container.hpp> #include <boost/multi_index/ordered_index.hpp> #include <boost/multi_index/member.hpp> #include <iostream> #include <string> #include <vector> using namespace boost::multi_index; struct Property { std::string name; int payload; }; typedef multi_index_container< Property, indexed_by< ordered_unique<member<Property,std::string,&Property::name>> > > set_t; int main() { std::vector<Property> meta= {{"hello",0},{"bye",1},{"world",3},{"boost",4}}; set_t s{meta.begin(),meta.end()}; std::cout<<s.find("boost")->payload<<"\n"; // prints 4 // change payload of "hello" to 5 auto it=s.find("hello"); s.modify(it,[](Property& x){x.payload=5;}); std::cout<<it->payload<<"\n"; // prints 5 } Joaquín M López Muñoz Telefónica