[multi_index] Indices interface type for overload resolution
Hi,
I have currently
template
;
BMI bmi;
auto k = keys(bmi.get
On Wed, Nov 20, 2019 at 2:51 PM Christophe B via Boost-users < boost-users@lists.boost.org> wrote:
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
std::vector<Key> keys(const std::map
&m) { ... }
I suspect that you only need to make your template a little more generic, something like (untested): template <typename C> std::vector<typename C::key_type> keys(const C& c) { std::vector<typename C::key_type> result; result.reserve(c.size()); for (const auto& entry : c) { result.emplace_back(entry.first); } return result; }
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
participants (3)
-
Christophe B
-
Dominique Devienne
-
Joaquin M López Muñoz