Simply want to grab the keys from a map and assign them to a vector:
#include <iostream>
#include
#include <map>
#include <vector>
#include <string>
#include <algorithm>
// some dumb object
struct Test { int x; int y; Test(int a, int b) : x(a), y(b) {} Test() :
x(), y() {}};
int main()
{
std::pair p = std::make_pair("Test", Test(1,2));
// works as I expect
std::cout << boost::bind(&std::pair::first, _1)(p)
<< std::endl;
std::mapstd::string,Test m;
m["Test"] = Test(3,4);
std::vectorstd::string keys(m.size());
// won't compile:
std::transform(m.begin(), m.end(), keys.begin(),
boost::bind(&std::pairstd::string,Test::first, _1));
}
It seems to barf on the transform call because of inability to call
get_pointer on std::pair<>?? From what I understand of transform though
it should be behaving more like the former call (output to stream) that
compiles and works: *out_it = op(*in_it) - in fact a test function
works. Why is it even attempting to call get_pointer()?
Boost version is 1.37.0, compiler is MSVC 8.0
Error output follows:
1>e:\boostvs3\include\boost\mem_fn.hpp(333) : error C2784: 'T
*boost::get_pointer(const std::auto_ptr<_Ty> &)' : could not deduce
template argument for 'const std::auto_ptr<_Ty> &' from 'const
std::pair<_Ty1,_Ty2>'
1> with
1> [
1> _Ty1=const std::string,
1> _Ty2=Test
1> ]
1> e:\boostvs3\include\boost\get_pointer.hpp(21) : see
declaration of 'boost::get_pointer'
1> e:\boostvs3\include\boost\mem_fn.hpp(352) : see reference to
function template instantiation 'const R
&boost::_mfi::dm::call<const U>(U &,const void *) const' being compiled
1> with
1> [
1> R=std::string,
1> T=std::pairstd::string,Test,
1> U=std::pair
1> ]
1> e:\boostvs3\include\boost\bind.hpp(222) : see reference to
function template instantiation 'const R &boost::_mfi::dm::operator
()<A1>(const U &) const' being compiled
1> with
1> [
1> R=std::string,
1> T=std::pairstd::string,Test,
1> A1=std::pair,
1> U=std::pair
1> ]
1> e:\boostvs3\include\boost\bind\bind_template.hpp(32) : see
reference to function template instantiation 'R
boost::_bi::list1<A1>::operator ()&,F,boost::_bi::list1
&>>(boost::_bi::type<T>,F &,A &,long)' being compiled
1> with
1> [
1> R=const
std::basic_string &,
1> A1=boost::arg<1>,
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>,
1> F=boost::_mfi::dmstd::string,Test>,
1> _Ty1=const std::string,
1> _Ty2=Test,
1> T=const
std::basic_string &,
1> A=boost::_bi::list1 &>
1> ]
1> c:\program files\microsoft visual studio
8\vc\include\algorithm(650) : see reference to function template
instantiation 'const std::basic_string<_Elem,_Traits,_Ax>
&boost::_bi::bind_t::operator ()>(A1 &)'
being compiled
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>,
1> R=const
std::basic_string &,
1> F=boost::_mfi::dmstd::string,Test>,
1> L=boost::_bi::list1>,
1> _Ty1=const std::string,
1> _Ty2=Test,
1> A1=std::pair
1> ]
1> c:\program files\microsoft visual studio
8\vc\include\algorithm(685) : see reference to function template
instantiation '_OutIt
std::_Transform::iterator,_OutIt,_Fn1,std::_Iter_random_helper<_Cat1,_Cat2>::_Iter_random_cat>(_InIt,_InIt,_OutIt,_Fn1,_InOutItCat,std::_Range_checked_iterator_tag)'
being compiled
1> with
1> [
1>
_OutIt=std::_Vector_iterator>>,
1>
_Traits=std::_Tmap_traitsstd::string,std::allocator>,false>,
1> _Fn1=boost::_bi::bind_t
&,boost::_mfi::dmstd::string,Test>,boost::_bi::list1>>,
1>
_Cat1=std::_Treestd::string,std::allocator>,false>>::iterator::iterator_category,
1>
_Cat2=std::_Vector_iterator>>::iterator_category,
1>
_InIt=std::_Treestd::string,std::allocator>,false>>::iterator,
1>
_InOutItCat=std::_Iter_random_helperstd::string,std::allocator>,false>>::iterator::iterator_category,std::_Vector_iterator>>::iterator_category>::_Iter_random_cat
1> ]
1> e:\dev_workspace\experimental\scratch\scratch\main.cpp(21) :
see reference to function template instantiation '_OutIt
std::transform::iterator,std::_Vector_iterator<_Ty,_Alloc>,boost::_bi::bind_t>(_InIt,_InIt,_OutIt,_Fn1)'
being compiled
1> with
1> [
1>
_OutIt=std::_Vector_iterator>>,
1>
_Traits=std::_Tmap_traitsstd::string,std::allocator>,false>,
1> _Ty=std::string,
1>
_Alloc=std::allocator>,
1> R=const
std::basic_string &,
1> F=boost::_mfi::dmstd::string,Test>,
1> L=boost::_bi::list1>,
1>
_InIt=std::_Treestd::string,std::allocator>,false>>::iterator,
1> _Fn1=boost::_bi::bind_t
&,boost::_mfi::dmstd::string,Test>,boost::_bi::list1>>
1> ]
1>e:\boostvs3\include\boost\mem_fn.hpp(333) : error C2784: 'T
*boost::get_pointer(T *)' : could not deduce template argument for 'T *'
from 'const std::pair<_Ty1,_Ty2>'
1> with
1> [
1> _Ty1=const std::string,
1> _Ty2=Test
1> ]
1> e:\boostvs3\include\boost\get_pointer.hpp(14) : see
declaration of 'boost::get_pointer'