samedi 18 mai 2019

How to convert std::set to std::array?

I have std::set and I need to convert it to std::array. Order of elements doesn't matter.

The opposite conversion seems to be simple, because I can just do:

std::array<T> array;
std::set<T> set(array.begin(), array.end());

But unfortunately std::array doesn't have constructor like this, so I'm unable to do:

std::set<T> set;
std::array<T> array(set.begin(), set.end());

What's the proper way of such conversion?

Aucun commentaire:

Enregistrer un commentaire