Boost logo

Boost Users :

Subject: Re: [Boost-users] Bind/Function: use reference arguments in template variadic functions
From: Yannick POTIN (yannp63_at_[hidden])
Date: 2013-04-12 06:41:40


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

Thank you, It actually allows me to use references in these functions.
I just tried and g++ is waiting for only references but I need to use pointers and/or values too.
There is a way to use mixed types in template variadic functions ?

Regards,

Yannick POTIN



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