|
Boost Users : |
From: Dominique Devienne (ddevienne_at_[hidden])
Date: 2019-11-20 14:06:52
On Wed, Nov 20, 2019 at 2:51 PM Christophe B via Boost-users <
boost-users_at_[hidden]> wrote:
> 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.
>
template <typename Key, typename Value>
> std::vector<Key> keys(const std::map<Key, Value> &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;
}
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