El 20/11/2019 a las 14:12, Christophe B via Boost-users escribió:
Hi,
I have currently
template
std::vector<Key> keys(const std::map &m) { ... } I'd like to write an overload that works also with the indices interface of multi_index_container.
[...]
template< typename Tag,typename Value,typename IndexSpecifierList,typename Allocator > auto keys(const typename multi_index::index< multi_index::multi_index_container
,Tag>::type& m) { typedef decltype(c.key_extractor()(*c.begin())) key_type; // A better definition would be welcome std::vector result; result.reserve(c.size()); for (const auto &elem : c) { result.push_back(c.key_extractor()(elem)); } return result; } But the overload resolution fails.
The second overload is not picked up because Tag, Value, etc. are being
used in a nondeduced context:
https://stackoverflow.com/questions/1268504/why-is-the-template-argument-ded...
So, this approach won't get you anywhere. You have two options:
1. You can use the name of the actual class implementing ordered indices:
template