|
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