|
Boost Users : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-12-08 16:28:58
Memfis wrote:
> Peter Dimov wrote:
>>> I am trying to achieve this with format and bind, but without much
>>> luck. What I came up with is the following:
>>> source.connect(bind(ref(target),
>>> bind(&format::str,
>>> bind(&format::operator%,
>>> format("the value is %1"), _1)));
>>
>> Your format string throws an exception for me. Perhaps you need to
>> use %1%?
>
> Argh. I made a typo while editing the post. I use %1% of course. But
> it still doesn't work.
The following works for me. I had to disambiguate format::operator% because
it's a template, though, it couldn't compile as is. It would've been nice if
format provided operator() as an alias so it could be bound.
#include <iostream>
#include <boost/format.hpp>
#include <boost/bind.hpp>
#include <boost/signal.hpp>
void f( std::string str )
{
std::cout << str << std::endl;
}
int main()
{
using namespace boost;
signal< void( std::string ) > target;
target.connect( &f );
format& (format::*pmf)( int const & ) = &format::operator%;
signal< void( int ) > source;
source.connect(
bind( ref( target ),
bind( &format::str,
bind( pmf, format( "the value is %1%" ), _1 )
)
)
);
source( 12345 );
}
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