I am using boost::multi-index
container for a collection of tuples, and I would like to create an index on the first element of the tuple. Here is my solution by creating an wrapper function getFirst
and pass it to the template parameter of the multi_index_container
as the global_fun
This solution works, but I am wondering if it is possible to use std::get
directly, without defining another wrapper function.
namespace {
using my_tuple_t = std::tuple<int, double>;
int getFirst(my_tuple_t x) {
return std::get<0>(x);
}
struct first {
};
using my_container = bmi::multi_index_container<
my_tuple_t,
bmi::indexed_by<
bmi::ordered_unique<
bmi::tag<struct first>,
bmi::global_fun<my_tuple_t, int, &getFirst>
>
>
>;
}