Boost logo

Boost Users :

Subject: [Boost-users] boost lambda wiht bind to stringstream::str
From: Conoscenza Silente (abruzzoforteegentile_at_[hidden])
Date: 2010-07-15 18:37:44

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
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?

// 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 << "%",
            bl::bind( &std::stringstream::str , boost::ref(outFmt) )() //
this call to bind has some problem
        ) );
    std::cout << outFmt.str() << std::endl;
    return 1;

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at