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.
template<class PAIR>
typename PAIR::second_type foo(const PAIR& arg)
{
return (arg.second);
}
class A
{
private:
typedef std::map<int, std::wstring> map_t;
map_t m_map;
public:
void bar()
{
// Attempt to pulled the mapped type from the map into the vector
std::vector<std::wstring>vect(m_map.size());
std::transform(m_map.begin(), m_map.end(), vect.begin(),
&foo<map_t::value_type>); // <-- error here, see below, also
// other attempts that all failed:
// - std::transform(..., boost::bind(foo<map_t::value_type>, _1));
// - std::transform(..., boost::bind(&map_t::value_type::second, _1));
// - also tried casting foo to a specific function type
// - also tried "template<class T> T itself(T arg) { return T; }" applied to all the above functor candidates, a la "std::transform(..., itself(<<functor>>));"
}
};
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.
In the meantime, can anyone explain why g++ can't resolve the type of the functor being provided?