Boost logo

Boost Users :

Subject: [Boost-users] bind: what am I doing wrong here?
From: Noah Roberts (roberts.noah_at_[hidden])
Date: 2009-04-14 19:45:46


Simply want to grab the keys from a map and assign them to a vector:

#include <iostream>

#include <boost/bind.hpp>
#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<std::string, Test> p = std::make_pair("Test", Test(1,2));

   // works as I expect
   std::cout << boost::bind(&std::pair<std::string, Test>::first, _1)(p)
<< std::endl;

   std::map<std::string,Test> m;
   m["Test"] = Test(3,4);

   std::vector<std::string> keys(m.size());

   // won't compile:
   std::transform(m.begin(), m.end(), keys.begin(),
boost::bind(&std::pair<std::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<R,T>::call<const U>(U &,const void *) const' being compiled
1> with
1> [
1> R=std::string,
1> T=std::pair<std::string,Test>,
1> U=std::pair<const std::string,Test>
1> ]
1> e:\boostvs3\include\boost\bind.hpp(222) : see reference to
function template instantiation 'const R &boost::_mfi::dm<R,T>::operator
()<A1>(const U &) const' being compiled
1> with
1> [
1> R=std::string,
1> T=std::pair<std::string,Test>,
1> A1=std::pair<const std::string,Test>,
1> U=std::pair<const std::string,Test>
1> ]
1> e:\boostvs3\include\boost\bind\bind_template.hpp(32) : see
reference to function template instantiation 'R
boost::_bi::list1<A1>::operator ()<const
std::basic_string<_Elem,_Traits,_Ax>&,F,boost::_bi::list1<std::pair<_Ty1,_Ty2>
&>>(boost::_bi::type<T>,F &,A &,long)' being compiled
1> with
1> [
1> R=const
std::basic_string<char,std::char_traits<char>,std::allocator<char>> &,
1> A1=boost::arg<1>,
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>,
1> F=boost::_mfi::dm<std::string,std::pair<std::string,Test>>,
1> _Ty1=const std::string,
1> _Ty2=Test,
1> T=const
std::basic_string<char,std::char_traits<char>,std::allocator<char>> &,
1> A=boost::_bi::list1<std::pair<const std::string,Test> &>
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<R,F,L>::operator ()<std::pair<_Ty1,_Ty2>>(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<char,std::char_traits<char>,std::allocator<char>> &,
1> F=boost::_mfi::dm<std::string,std::pair<std::string,Test>>,
1> L=boost::_bi::list1<boost::arg<1>>,
1> _Ty1=const std::string,
1> _Ty2=Test,
1> A1=std::pair<const std::string,Test>
1> ]
1> c:\program files\microsoft visual studio
8\vc\include\algorithm(685) : see reference to function template
instantiation '_OutIt
std::_Transform<std::_Tree<_Traits>::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<std::string,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>>,
1>
_Traits=std::_Tmap_traits<std::string,Test,std::less<std::string>,std::allocator<std::pair<const
std::string,Test>>,false>,
1> _Fn1=boost::_bi::bind_t<const
std::basic_string<char,std::char_traits<char>,std::allocator<char>>
&,boost::_mfi::dm<std::string,std::pair<std::string,Test>>,boost::_bi::list1<boost::arg<1>>>,
1>
_Cat1=std::_Tree<std::_Tmap_traits<std::string,Test,std::less<std::string>,std::allocator<std::pair<const
std::string,Test>>,false>>::iterator::iterator_category,
1>
_Cat2=std::_Vector_iterator<std::string,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>>::iterator_category,
1>
_InIt=std::_Tree<std::_Tmap_traits<std::string,Test,std::less<std::string>,std::allocator<std::pair<const
std::string,Test>>,false>>::iterator,
1>
_InOutItCat=std::_Iter_random_helper<std::_Tree<std::_Tmap_traits<std::string,Test,std::less<std::string>,std::allocator<std::pair<const
std::string,Test>>,false>>::iterator::iterator_category,std::_Vector_iterator<std::string,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>>::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<std::_Tree<_Traits>::iterator,std::_Vector_iterator<_Ty,_Alloc>,boost::_bi::bind_t<R,F,L>>(_InIt,_InIt,_OutIt,_Fn1)'
being compiled
1> with
1> [
1>
_OutIt=std::_Vector_iterator<std::string,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>>,
1>
_Traits=std::_Tmap_traits<std::string,Test,std::less<std::string>,std::allocator<std::pair<const
std::string,Test>>,false>,
1> _Ty=std::string,
1>
_Alloc=std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char>>>,
1> R=const
std::basic_string<char,std::char_traits<char>,std::allocator<char>> &,
1> F=boost::_mfi::dm<std::string,std::pair<std::string,Test>>,
1> L=boost::_bi::list1<boost::arg<1>>,
1>
_InIt=std::_Tree<std::_Tmap_traits<std::string,Test,std::less<std::string>,std::allocator<std::pair<const
std::string,Test>>,false>>::iterator,
1> _Fn1=boost::_bi::bind_t<const
std::basic_string<char,std::char_traits<char>,std::allocator<char>>
&,boost::_mfi::dm<std::string,std::pair<std::string,Test>>,boost::_bi::list1<boost::arg<1>>>
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'


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net