
I have two signals:
signal

On 12/5/06, Memfis
I have two signals: signal
source; signal target; What want is for every call: source(12345); to have a call: target("the value is 12345");
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)));
Unfortunately the code above treats the parameter to source as if it was empty, i.e. I get calls target("the value is ");
What am I doing wrong and how can this be done correctly?
Why not shirk the complexity you're creating and just use a normal function?

Aaron Griffin wrote:
On 12/5/06, Memfis
wrote: I have two signals: signal
source; signal target; What want is for every call: source(12345); to have a call: target("the value is 12345");
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)));
Unfortunately the code above treats the parameter to source as if it was empty, i.e. I get calls target("the value is ");
What am I doing wrong and how can this be done correctly?
Why not shirk the complexity you're creating and just use a normal function?
Because I have several signals that I want to translate between in such a manner, and avoiding creating lots of one-line functions is what bind was created for, I think. A besides, this is a simplified example. -- Memfis

Memfis wrote:
I have two signals: signal
source; signal target; What want is for every call: source(12345); to have a call: target("the value is 12345");
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%?

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. -- Memfis

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
participants (3)
-
Aaron Griffin
-
Memfis
-
Peter Dimov