flattening a std::map to a set via std::transform
<p>I need to flatten a container from <code>std::map&lt;int, std::set&lt;std::string&gt;&gt;</code> to <code>std::set&lt;std::string&gt;</code> and I am running to difficulties with the syntax.  When I say flatten, I basically want to make a single <code>std::set&lt;string&gt;</code> with all the sets stitched together - (the <code>set</code> will prevent duplicates entries which is what I need) I was trying something based on the answer in this <a href="https://stackoverflow.com/questions/10916728/copy-stdmap-to-stdset-in-c"><strong>question</strong></a> but my value type is a container which makes the problem harder to solve.  The output from the compiler is very difficult to understand, here the source is shown below.</p>

<p>I have a live coliru of my code <a href="http://coliru.stacked-crooked.com/a/f790451888140b8d" rel="nofollow noreferrer"><strong>here</strong></a> </p>

<pre><code>int main()
{
    std::set&lt;std::string&gt; outputSet;

    std::map&lt;int, std::set&lt;std::string&gt;&gt; inputMap = {
        {1, {"a", "b", "c"}},
        {2, {"b", "c", "d"}}
    };

    std::transform(inputMap.cbegin(), inputMap.cend(), 
        std::inserter(outputSet, outputSet.end()), 
        [](const std::map&lt;int, std::set&lt;std::string&gt;&gt;::value_type&amp; rNext) {
            return rNext.second;
        });        
}
</code></pre>

<p>The errors are shown below:</p>

<pre><code>In file included from /usr/local/include/c++/6.2.0/algorithm:62:0,
                 from main.cpp:4:
/usr/local/include/c++/6.2.0/bits/stl_algo.h: In instantiation of '_OIter std::transform(_IIter, _IIter, _OIter, _UnaryOperation) [with _IIter = std::_Rb_tree_const_iterator&lt;std::pair&lt;const int, std::set&lt;std::__cxx11::basic_string&lt;char&gt; &gt; &gt; &gt;; _OIter = std::insert_iterator&lt;std::set&lt;std::__cxx11::basic_string&lt;char&gt; &gt; &gt;; _UnaryOperation = main()::&lt;lambda(const value_type&amp;)&gt;]':
main.cpp:19:10:   required from here
/usr/local/include/c++/6.2.0/bits/stl_algo.h:4177:12: error: no match for 'operator=' (operand types are 'std::insert_iterator&lt;std::set&lt;std::__cxx11::basic_string&lt;char&gt; &gt; &gt;' and 'std::set&lt;std::__cxx11::basic_string&lt;char&gt; &gt;')
  *__result = __unary_op(*__first);
  ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/local/include/c++/6.2.0/bits/stl_algobase.h:67:0,
                 from /usr/local/include/c++/6.2.0/bits/stl_tree.h:63,
                 from /usr/local/include/c++/6.2.0/set:60,
                 from main.cpp:1:
/usr/local/include/c++/6.2.0/bits/stl_iterator.h:680:7: note: candidate: std::insert_iterator&lt;_Container&gt;&amp; std::insert_iterator&lt;_Container&gt;::operator=(const typename _Container::value_type&amp;) [with _Container = std::set&lt;std::__cxx11::basic_string&lt;char&gt; &gt;; typename _Container::value_type = std::__cxx11::basic_string&lt;char&gt;]
       operator=(const typename _Container::value_type&amp; __value)
       ^~~~~~~~
/usr/local/include/c++/6.2.0/bits/stl_iterator.h:680:7: note:   no known conversion for argument 1 from 'std::set&lt;std::__cxx11::basic_string&lt;char&gt; &gt;' to 'const value_type&amp; {aka const std::__cxx11::basic_string&lt;char&gt;&amp;}'
/usr/local/include/c++/6.2.0/bits/stl_iterator.h:688:7: note: candidate: std::insert_iterator&lt;_Container&gt;&amp; std::insert_iterator&lt;_Container&gt;::operator=(typename _Container::value_type&amp;&amp;) [with _Container = std::set&lt;std::__cxx11::basic_string&lt;char&gt; &gt;; typename _Container::value_type = std::__cxx11::basic_string&lt;char&gt;]
       operator=(typename _Container::value_type&amp;&amp; __value)
       ^~~~~~~~
/usr/local/include/c++/6.2.0/bits/stl_iterator.h:688:7: note:   no known conversion for argument 1 from 'std::set&lt;std::__cxx11::basic_string&lt;char&gt; &gt;' to 'std::set&lt;std::__cxx11::basic_string&lt;char&gt; &gt;::value_type&amp;&amp; {aka std::__cxx11::basic_string&lt;char&gt;&amp;&amp;}'
/usr/local/include/c++/6.2.0/bits/stl_iterator.h:629:11: note: candidate: constexpr std::insert_iterator&lt;std::set&lt;std::__cxx11::basic_string&lt;char&gt; &gt; &gt;&amp; std::insert_iterator&lt;std::set&lt;std::__cxx11::basic_string&lt;char&gt; &gt; &gt;::operator=(const std::insert_iterator&lt;std::set&lt;std::__cxx11::basic_string&lt;char&gt; &gt; &gt;&amp;)
     class insert_iterator
           ^~~~~~~~~~~~~~~
/usr/local/include/c++/6.2.0/bits/stl_iterator.h:629:11: note:   no known conversion for argument 1 from 'std::set&lt;std::__cxx11::basic_string&lt;char&gt; &gt;' to 'const std::insert_iterator&lt;std::set&lt;std::__cxx11::basic_string&lt;char&gt; &gt; &gt;&amp;'
/usr/local/include/c++/6.2.0/bits/stl_iterator.h:629:11: note: candidate: constexpr std::insert_iterator&lt;std::set&lt;std::__cxx11::basic_string&lt;char&gt; &gt; &gt;&amp; std::insert_iterator&lt;std::set&lt;std::__cxx11::basic_string&lt;char&gt; &gt; &gt;::operator=(std::insert_iterator&lt;std::set&lt;std::__cxx11::basic_string&lt;char&gt; &gt; &gt;&amp;&amp;)
/usr/local/include/c++/6.2.0/bits/stl_iterator.h:629:11: note:   no known conversion for argument 1 from 'std::set&lt;std::__cxx11::basic_string&lt;char&gt; &gt;' to 'std::insert_iterator&lt;std::set&lt;std::__cxx11::basic_string&lt;char&gt; &gt; &gt;&amp;&amp;'
</code></pre>