Boost logo

Boost Users :

Subject: Re: [Boost-users] Bind/Function: use reference arguments in template variadic functions
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2013-04-11 23:26:46


AMDG

On 04/11/2013 01:57 PM, Yannick POTIN wrote:
> <snip>
>
> // A template variadic function...
> template<class ...classes>
> boost::function0<void> call_something(classes... c) {
> // ... here we are:
> return boost::bind(call_a,boost::ref(c...));
> }
>
> <snip>
> ----------------------------------------------
> After compilation, I get this output (watch the memory addresses):
> 0xbfc8f994::operator()(): 1
> 0xbfc8f990::operator()(): 2
> 0xbfc8f984::operator()(): 1
> 0xbfc8f984::operator()(): 2
> I really don't know what happened (even if I can imagine).
> But references are just lost and this is not good.
>
> So, here is my question: How can I make this working ?
>

The arguments of call_something are passed by value.
Try:

template<class ...classes>
boost::function0<void> call_something(classes&... c)

In Christ,
Steven Watanabe


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