|
Boost Users : |
From: Christian Henning (chhenning_at_[hidden])
Date: 2007-03-26 11:24:08
Hi there, I have posted this question last Friday, already. But maybe
my example was too confusing. Here is a more simple example.
Basically, I don't see what the big difference is when using
boost::bind with a pointer vector ( std::vector<info*> ) and a static
array of info.
Please consider the following code:
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <boost/bind.hpp>
using namespace std;
using namespace boost;
struct info
{
int a;
string s;
};
static info table[] =
{
{ 16, "Hello" },
{ 18, "Moin" }
};
string& get_s( info* p )
{
return p->s;
}
int _tmain(int argc, _TCHAR* argv[])
{
{
vector<info*> v;
find_if( v.begin(), v.end()
, bind( equal_to<string>()
, bind( &get_s, _1 )
, "Moin" ));
}
{
find_if( &table[0], &table[0] + 2
, bind( equal_to<string>()
, bind( &get_s, _1 )
, "Moin" ));
}
}
The second find_if wont complie using MSVC 7.1. The errors are:
c:\boost\boost\bind.hpp(219) : error C2664: 'std::string &(info *)' :
cannot convert parameter 1 from 'info' to 'info *'
No user-defined-conversion operator available that can perform
this conversion, or the operator cannot be called
c:\boost\boost\bind\bind_template.hpp(139) : see reference to
function template instantiation 'R boost::_bi::list1<A1>::operator
()<boost::_bi::bind_t<R,F,L>::result_type,std::string&(__cdecl *)(info
*),A>(boost::_bi::type<T>,F & ,A &,long)' being compiled
with
[
R=boost::_bi::bind_t<std::string &,std::string &(__cdecl
*)(info *),boost::_bi::list1<boost::_bi::list_av_1<boost::arg<1>>::B1>>::result_type,
A1=boost::_bi::list_av_1<boost::arg<1>>::B1,
F=std::string &(__cdecl *)(info *),
L=boost::_bi::list1<boost::_bi::list_av_1<boost::arg<1>>::B1>,
A=const boost::_bi::list1<info &>,
T=boost::_bi::bind_t<std::string &,std::string &(__cdecl
*)(info *),boost::_bi::list1<boost::_bi::list_av_1<boost::arg<1>>::B1>>::result_type
]
c:\boost\boost\bind.hpp(213) : see reference to function
template instantiation 'boost::_bi::bind_t<R,F,L>::result_type
boost::_bi::bind_t<R,F,L>::eval<const boost::_bi::list1<A1>>(A &)'
being compiled
with
[
R=std::string &,
F=std::string &(__cdecl *)(info *),
L=boost::_bi::list1<boost::_bi::list_av_1<boost::arg<1>>::B1>,
A1=info &,
A=const boost::_bi::list1<info &>
]
[snip]
Any ideas?
Christian
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