Dominique Devienne writes:
On Wed, Apr 15, 2015 at 1:23 PM, David Hagood
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
#include
#include
#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>
>
> 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<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