Note that there are some explanatory texts on larger screens.

plurals
  1. POTemplate functor error in g++
    text
    copied!<p>I've got some code where I would like to build a vector of elements using the mapped values in a map. The code below works fine in Visual Studio (and seems legit as far as I can tell), but g++ disagrees.</p> <pre><code>template&lt;class PAIR&gt; typename PAIR::second_type foo(const PAIR&amp; arg) { return (arg.second); } class A { private: typedef std::map&lt;int, std::wstring&gt; map_t; map_t m_map; public: void bar() { // Attempt to pulled the mapped type from the map into the vector std::vector&lt;std::wstring&gt;vect(m_map.size()); std::transform(m_map.begin(), m_map.end(), vect.begin(), &amp;foo&lt;map_t::value_type&gt;); // &lt;-- error here, see below, also // other attempts that all failed: // - std::transform(..., boost::bind(foo&lt;map_t::value_type&gt;, _1)); // - std::transform(..., boost::bind(&amp;map_t::value_type::second, _1)); // - also tried casting foo to a specific function type // - also tried "template&lt;class T&gt; T itself(T arg) { return T; }" applied to all the above functor candidates, a la "std::transform(..., itself(&lt;&lt;functor&gt;&gt;));" } }; </code></pre> <p>Unfortunately, I don't have the exact error text with me (something about not being able to figure out which overloaded function to use) at the moment or the specific version of g++ (the latest being distributed with Ubuntu), but I'll update this post when I get that.</p> <p>In the meantime, can anyone explain why g++ can't resolve the type of the functor being provided?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload