boost lambda wiht bind to stringstream::str

Hi all I am trying to get familiar with boost lambda. Below I am using std::transform algorithm but when I try to call std::stringstream::str() function using lambda::bind I receive the following error message: TestBoost15Jul.cpp:49: error: no matching function for call to ‘bind(<unresolved overloaded function type>, const boost::reference_wrapper<std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> > >)’ Do you also know if is the right way to return the string that must be stored in the second vector used by std::transform? Regards AFG // C++ #include <iostream> #include <algorithm> #include <vector> #include <sstream> #include <string> // boost #include <boost/assign.hpp> #include <boost/assign/list_of.hpp> #include <boost/assign/std/vector.hpp> #include <boost/lambda/core.hpp> #include <boost/lambda/lambda.hpp> #include <boost/lambda/bind.hpp> #include <boost/function.hpp> int main( int argc, char** argv ){ namespace bl = boost::lambda; using namespace boost::assign; std::vector< std::string > vIn = list_of("a")("b")("c")("d"); std::vector< std::string > vOut; std::stringstream outFmt; int nCount = 2; bl::var_type< int >::type _nCount( bl::var(nCount) ); bl::var_type< std::stringstream >::type _outFmt( bl::var(outFmt) ); std::transform( vIn.begin(), vIn.end(), vOut.begin(), ( _outFmt << bl::_1 << "=%" << _nCount << "%", _nCount++, bl::bind( &std::stringstream::str , boost::ref(outFmt) )() // this call to bind has some problem ) ); std::cout << outFmt.str() << std::endl; return 1; }

Below I am using std::transform algorithm but when I try to call std::stringstream::str() function using lambda::bind I receive the following error message:
TestBoost15Jul.cpp:49: error: no matching function for call to ‘bind(<unresolved overloaded function type>, const boost::reference_wrapper<std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> > >)’ <...> bl::bind( &std::stringstream::str , boost::ref(outFmt) )() // this call to bind has some problem ) );
str() member function is overloaded, so you have to type-cast it explicitly to one of the overloads.

Thanks Igor I changed the code into this one and it builds BUT now I have SEGMANTATION FAULT error. Do you know what could be? bl::bind( static_cast<std::string(std::stringstream::*)()const>(&std::stringstream::str), boost::ref(outFmt) )() My intention is to return the call to stringstream::str() into the second vector used by std::transform, but I am not sure if I am achieving this. On Fri, Jul 16, 2010 at 12:45 AM, Igor R <boost.lists@gmail.com> wrote:
Below I am using std::transform algorithm but when I try to call std::stringstream::str() function using lambda::bind I receive the following error message:
TestBoost15Jul.cpp:49: error: no matching function for call to ‘bind(<unresolved overloaded function type>, const boost::reference_wrapper<std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> > >)’ <...> bl::bind( &std::stringstream::str , boost::ref(outFmt) )() // this call to bind has some problem ) );
str() member function is overloaded, so you have to type-cast it explicitly to one of the overloads. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Auch....I realized that vOut is empty..that's the reason for the error. By the way still this std::transform looks like it is is not able to store anything into vOut. I double checked and it seems that the call to bind doesn't return anything. Do you know why? On Fri, Jul 16, 2010 at 1:04 AM, Conoscenza Silente < abruzzoforteegentile@gmail.com> wrote:
Thanks Igor I changed the code into this one and it builds BUT now I have SEGMANTATION FAULT error. Do you know what could be?
bl::bind(
static_cast<std::string(std::stringstream::*)()const>(&std::stringstream::str), boost::ref(outFmt) )()
My intention is to return the call to stringstream::str() into the second vector used by std::transform, but I am not sure if I am achieving this.
On Fri, Jul 16, 2010 at 12:45 AM, Igor R <boost.lists@gmail.com> wrote:
Below I am using std::transform algorithm but when I try to call std::stringstream::str() function using lambda::bind I receive the following error message:
TestBoost15Jul.cpp:49: error: no matching function for call to ‘bind(<unresolved overloaded function type>, const boost::reference_wrapper<std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> > >)’ <...> bl::bind( &std::stringstream::str , boost::ref(outFmt) )() // this call to bind has some problem ) );
str() member function is overloaded, so you have to type-cast it explicitly to one of the overloads. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

P.S. I used this code for my checkings std::string outString; bl::var_type< std::string >::type _outString( bl::var(outString) ); ... _outString = bl::bind( static_cast<std::string(std::stringstream::*)()const>(&std::stringstream::str), boost::ref(_outFmt) )(), std::cout << _outString << '\n', // Here I have always an empty string // so the previous call to bind doesn't really return anything..do you know why? ... On Fri, Jul 16, 2010 at 1:41 AM, Conoscenza Silente < abruzzoforteegentile@gmail.com> wrote:
Auch....I realized that vOut is empty..that's the reason for the error. By the way still this std::transform looks like it is is not able to store anything into vOut.
I double checked and it seems that the call to bind doesn't return anything. Do you know why?
On Fri, Jul 16, 2010 at 1:04 AM, Conoscenza Silente < abruzzoforteegentile@gmail.com> wrote:
Thanks Igor I changed the code into this one and it builds BUT now I have SEGMANTATION FAULT error. Do you know what could be?
bl::bind(
static_cast<std::string(std::stringstream::*)()const>(&std::stringstream::str), boost::ref(outFmt) )()
My intention is to return the call to stringstream::str() into the second vector used by std::transform, but I am not sure if I am achieving this.
On Fri, Jul 16, 2010 at 12:45 AM, Igor R <boost.lists@gmail.com> wrote:
Below I am using std::transform algorithm but when I try to call std::stringstream::str() function using lambda::bind I receive the following error message:
TestBoost15Jul.cpp:49: error: no matching function for call to ‘bind(<unresolved overloaded function type>, const boost::reference_wrapper<std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> > >)’ <...> bl::bind( &std::stringstream::str , boost::ref(outFmt) )() // this call to bind has some problem ) );
str() member function is overloaded, so you have to type-cast it explicitly to one of the overloads. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

P.S. I used this code for my checkings std::string outString; bl::var_type< std::string >::type _outString( bl::var(outString) ); ... _outString = bl::bind(
static_cast<std::string(std::stringstream::*)()const>(&std::stringstream::str), boost::ref(_outFmt) )(), std::cout << _outString << '\n', // Here I have always an empty string // so the previous call to bind doesn't really return anything..do you know why?
Remove "()" after the bind: static_cast<std::string(std::stringstream::*)()const>(&std::stringstream::str), boost::ref(_outFmt) )

It works! Thanks Afg On Fri, Jul 16, 2010 at 2:00 AM, Igor R <boost.lists@gmail.com> wrote:
P.S. I used this code for my checkings std::string outString; bl::var_type< std::string >::type _outString( bl::var(outString) ); ... _outString = bl::bind(
static_cast<std::string(std::stringstream::*)()const>(&std::stringstream::str),
boost::ref(_outFmt) )(), std::cout << _outString << '\n', // Here I have always an empty string // so the previous call to bind doesn't really return anything..do you know why?
Remove "()" after the bind:
static_cast<std::string(std::stringstream::*)()const>(&std::stringstream::str), boost::ref(_outFmt) ) _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Conoscenza Silente
-
Igor R