Boost logo

Boost Users :

From: Christophe B (boost_at_[hidden])
Date: 2019-11-20 13:12:20


Hi,

I have currently

template <typename Key, typename Value>
std::vector<Key> keys(const std::map<Key, Value> &m) { ... }

I'd like to write an overload that works also with the indices interface of multi_index_container.

Suppose I have a multi_index_container with ordered unique indexes tagged "by_id" and "by_name".

struct by_id {};
struct by_name {};
using BMI = multi_index::multi_index_container<Value,
 Â Â Â  multi_index::indexed_by<
 Â Â Â Â Â Â Â  multi_index::ordered_unique<by_id, multi_index::key<&Value::id>>,
 Â Â Â Â Â Â Â  multi_index::ordered_unique<by_name, multi_index::key<&Value::name>>
>>;

BMI bmi;
auto k = keys(bmi.get<by_name>());

Based on the documentation, I tried

template< typename Tag,typename Value,typename IndexSpecifierList,typename Allocator >
auto keys(const typename multi_index::index< multi_index::multi_index_container<Value,IndexSpecifierList,Allocator>,Tag>::type& m)
{
 Â Â Â  typedef decltype(c.key_extractor()(*c.begin())) key_type; // A better definition would be welcome
 Â Â Â  std::vector<key_type> result;
 Â Â Â  result.reserve(c.size());
 Â Â Â  for (const auto &elem : c) {
 Â Â Â Â Â Â Â  result.push_back(c.key_extractor()(elem));
 Â Â Â  }
 Â Â Â  return result;
}

But the overload resolution fails.
What should be the interface of keys in order to support indices interface of multi_index_container?

Thank you,

Christophe B


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net