Is there any good way for assigning std::vector to std::multiset? Other than iteration of course. I see that in C++11 there is something like initializer list, maybe it can be used somehow?
Asked
Active
Viewed 3,943 times
0
-
What exactly is the problem with iterators here? – Xeo Feb 13 '13 at 09:33
-
@Xeo They are uncomfortable and probably it's not the fastest solution. – user1873947 Feb 13 '13 at 09:34
-
`std::vector
vec(set.begin(), set.end())`? – Jon Feb 13 '13 at 09:35 -
5@user1873947 *you* are uncomfortable with them. FTFY – R. Martinho Fernandes Feb 13 '13 at 09:35
-
1@R. Martinho Fernandes I mean, iteration requires more code than the solution from the answers. You can do it in some lines and you can do it in one line, thats the comfort. – user1873947 Feb 13 '13 at 09:36
-
1@Xeo His problem is not "iterators", it is "iteration". – nurettin Feb 13 '13 at 09:37
-
2If you're not "comfortable" doing the iteration yourself, then let the library do it for you, e.g. with [`std::copy`](http://en.cppreference.com/w/cpp/algorithm/copy). – Some programmer dude Feb 13 '13 at 09:38
-
1@user1873947 The answers use iterators and in a single line do exactly what you want. – Joseph Mansfield Feb 13 '13 at 09:43
2 Answers
4
Use this:
std::vector<SOME_TYPE> a;
....
std::multiset<SOME_TYPE> ms(a.begin(), a.end());

Ivaylo Strandjev
- 69,226
- 18
- 123
- 176