Re: [Boost-users] [bind] Template deduction

On Tue, Mar 4, 2008 at 7:16 PM, Marshall Clow
Would this work? std::for_each( myStrings.begin(), myStrings.end(), boost::bind( &DoFoostd::string, 5, _1 ) );
Well, the example I gave was probably overly simple. The real example uses a boost::python::list, which can either take a char* or a std::string. At the time I'm doing the boost::bind, I do not know what type is being passed in.

On Wed, Mar 5, 2008 at 10:36 AM, Robert Dailey
On Tue, Mar 4, 2008 at 7:16 PM, Marshall Clow
wrote: Would this work? std::for_each( myStrings.begin(), myStrings.end(), boost::bind( &DoFoostd::string, 5, _1 ) );
Well, the example I gave was probably overly simple. The real example uses a boost::python::list, which can either take a char* or a std::string. At the time I'm doing the boost::bind, I do not know what type is being passed in.
Below is the real example: //========================================================================================= bool PyInterpreter::SetSystemPath( std::vectorboost::filesystem::path const& pathList ) { bool success = true; try { using namespace boost::python; list newsyspath; std::for_each( pathList.begin(), pathList.end(), boost::bind( &list::insertboost::filesystem::path, newsyspath, 0, _1 ) ); object sys = GetNamespace( "sys" ); sys["path"] = newsyspath; } catch(...) { PyErr_Print(); success = false; assert( 0 ); } return false; } If you examine my std::for_each() above, you'll notice that I'm simply trying to push 'path' objects into boost::python::list, which won't work but it should at least compile. However the MSVC compiler is telling me that boost::bind expects 2 arguments, not 4. What am I doing wrong?

Robert Dailey:
Below is the real example: ...
using namespace boost::python;
list newsyspath;
std::for_each( pathList.begin(), pathList.end(), boost::bind( &list::insertboost::filesystem::path, newsyspath, 0, _1 ) );
Unfortunately, list::insert is overloaded, and boost::bind doesn't handle overloaded functions well. See the section "Binding an overloaded function" in http://svn.boost.org/trac/boost/browser/trunk/libs/bind/bind.html?format=raw

On Wed, Mar 5, 2008 at 11:47 AM, Peter Dimov
Unfortunately, list::insert is overloaded, and boost::bind doesn't handle overloaded functions well. See the section "Binding an overloaded function" in
http://svn.boost.org/trac/boost/browser/trunk/libs/bind/bind.html?format=raw
Ah, that was the problem! I didn't know list::insert was overloaded. Too bad the compiler errors generated by boost::bind aren't very helpful. C++0x will definitely fix that issue later on though! Thanks for the help.

Robert Dailey wrote:
On Wed, Mar 5, 2008 at 10:36 AM, Robert Dailey
mailto:rcdailey@gmail.com> wrote: On Tue, Mar 4, 2008 at 7:16 PM, Marshall Clow
mailto:marshall@idio.com> wrote: Would this work? std::for_each( myStrings.begin(), myStrings.end(), boost::bind( &DoFoostd::string, 5, _1 ) );
Well, the example I gave was probably overly simple. The real example uses a boost::python::list, which can either take a char* or a std::string. At the time I'm doing the boost::bind, I do not know what type is being passed in.
Below is the real example:
//========================================================================================= bool PyInterpreter::SetSystemPath( std::vectorboost::filesystem::path const& pathList ) { bool success = true;
try { using namespace boost::python;
list newsyspath;
std::for_each( pathList.begin(), pathList.end(), boost::bind( &list::insertboost::filesystem::path, newsyspath, 0, _1 ) );
object sys = GetNamespace( "sys" ); sys["path"] = newsyspath; }
catch(...) { PyErr_Print(); success = false; assert( 0 ); }
return false; }
did you try: std::copy( pathList.begin(), pathList.end() , std::back_inserter(list) ); Jeff Flinn

A template is only a pattern not code, DoFoo cannot be bound to because
it doesn't exist so you can't do what you want, for more details have a
look here :
http://www.parashift.com/c++-faq-lite/templates.html#faq-35.15.
Do you really need a template function for this, just overload a
function with one converting the char* into a std::string or visa versa
________________________________
From: boost-users-bounces@lists.boost.org
[mailto:boost-users-bounces@lists.boost.org] On Behalf Of Robert Dailey
Sent: 05 March 2008 16:37
To: boost-users@lists.boost.org
Subject: Re: [Boost-users] [bind] Template deduction
On Tue, Mar 4, 2008 at 7:16 PM, Marshall Clow

On Wed, Mar 5, 2008 at 10:45 AM, Patrick Loney < Patrick.Loney@interactivets.com> wrote:
Do you really need a template function for this, just overload a function with one converting the char* into a std::string or visa versa
Read my posts above.
participants (4)
-
Jeff Flinn
-
Patrick Loney
-
Peter Dimov
-
Robert Dailey