Re: [Boost-users] Bind/Function: use reference arguments in template variadic functions

template<class ...classes>
boost::function0<void> call_something(classes&... c)
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 ?
For perfect forwarding use: template<class... T> void call(T&&... t) { foo(std::forward<T>(t)...); } I tried this one too and it works fine thank you. However, I use these functions with boost::bind library and actually references are lost when I use it (and I need to). After some google searches, it seems that boost::bind officially does not support this use (due to internal references). So I tried with std::bind because I read somewhere the problem was fixed with its C++11 version. The problem is the same : with std::bind too, references are lost using std::forward. Does anyone made this duo bind/template variadic functions working together ? And if someone did, how did you do ? Sorry, I lost context with what you're trying to do, but maybe you want to use boost::ref / std::ref in conjunction with boost::bind / std::bind, respectively? I think that should indicate to the binding framework to hold the bound values by reference rather than by value (if that's what you want). - Jeff Actually, I try to use template variadic functions which can contains references, pointers and/or values which must be converted to boost::function0<void>. I tried to use forward() but I lose references with it. I tried ref() to but it make values interpreted as references (so ints are broken). So I'm looking for a magic way to use ref() only when needed by the arguments. Regards, Yannick POTIN

AMDG On 04/12/2013 03:34 PM, Yannick POTIN wrote:
Actually, I try to use template variadic functions which can contains references, pointers and/or values which must be converted to boost::function0<void>.
I tried to use forward() but I lose references with it. I tried ref() to but it make values interpreted as references (so ints are broken). So I'm looking for a magic way to use ref() only when needed by the arguments.
What do you mean by "when needed by the arguments?" How do you specify what should have ref added and what shouldn't? In other words: Given a function f and an argument a, what precisely are the conditions on f and a under which you want to call bind(f, ref(a)) instead of bind(f, a)? It's pretty easy to use ref when a is an lvalue, but this is also dangerous, as it means that apparently innocent refactoring can change the behavior. In Christ, Steven Watanabe
participants (2)
-
Steven Watanabe
-
Yannick POTIN