I have a vector containing information called ST_ThepInfo.
My problem is when using struct ST_ThepInfo in struct Infovalue_t.
struct ST_ThepInfo
{
int length;
string ex;
int weight;
};
struct Infovalue_t {
ST_ThepInfo s;
int i;
};
struct ST_ThepInfo_tag {};
typedef boost::multi_index_container<
Infovalue_t,
boost::multi_index::indexed_by<
boost::multi_index::random_access<>, // this index represents insertion order
boost::multi_index::hashed_unique<
boost::multi_index::tag<ST_ThepInfo_tag>,
boost::multi_index::member<Infovalue_t, ST_ThepInfo,&Infovalue_t::s>>
>
> myvalues_t;
then i call these code:
myvalues_t s;
ST_ThepInfo k;
....
auto t = count.emplaceback(k, 0);
However I get an error like this:
How do I fix it?

Hashed indexes require the key type to be hashable and equality-comparable.
You need to provide these for the info struct:
Live On Coliru
Prints:
Note that it is very important that equality matches hashing. If they don't agree, there's going to be Undefined Behaviour. This is the main reason why I don't recommend defaulting the equality operator as you can in c++20:
This makes it less explicit that
hash_valueneeds to agree with the members and risks they go out of sync when you e.g. add a member.