Warning when initializing a vector<pair<>> from a map

This compiles clean, but CLion flags the initializer with an error:

map<string, int> works;
for (string l: {"a", "a", "b", "c"}) {
vector<pair<string, int>> scores{works.begin(), works.end()};

  • Class 'map<std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator>, int>::iterator' is not compatible with class 'pair<string, int>' (at line 13)

Is this a bug, and if so is it a known bug? The value type of a map<K, V> is pair<const K, V>, so it should work as far as I can tell.


1 comment

Hi Guy.

It seems we have the issue in the tracker already: https://youtrack.jetbrains.com/issue/CPP-6220. Please comment or upvote.


Please sign in to leave a comment.