[bind] Possible to use variadic templates with bind?

Hi
Is it possible to pass variadic template arguments to bind, such that bind
uses them as the placeholder arguments (_1, _2, _3 etc)
I show my use case below.
struct job_queue
{
// copy f into list for asynchronous envocation by another thread
void enqueue(boost::function

Steve Lorimer wrote:
Hi
Is it possible to pass variadic template arguments to bind, such that bind uses them as the placeholder arguments (_1, _2, _3 etc)
I show my use case below. ... template
struct cb { typedef void (T::*type)(Args...); }; ... job_t(typename cb ::type cb, boost::shared_ptr<T> that, boost::shared_ptr q) : arg_func(boost::bind(cb, that, Args...)), queue(q) {} // normally would be _1, _2, _3, etc
An interesting puzzle. I tried to apply the 'Indexes' technique shown in the
bind implementation section of
http://osl.iu.edu/~dgregor/cpp/variadic-templates.pdf
and ended up with the following:
#include

On 07/21/10 11:23, Peter Dimov wrote: [snip]
An interesting puzzle. I tried to apply the 'Indexes' technique shown in the bind implementation section of
http://osl.iu.edu/~dgregor/cpp/variadic-templates.pdf
and ended up with the following:
#include
#include template
struct int_tuple {}; // make indexes impl is a helper for make indexes template
struct make_indexes_impl; template
struct make_indexes_impl, T, Types...> { typedef typename make_indexes_impl, Types...>::type type; }; template
struct make_indexes_impl > { typedef int_tuple type; }; template
struct make_indexes: make_indexes_impl<0, int_tuple<>, Types...> { }; [snip] That make_indexes was the inspiration for:
http://svn.boost.org/svn/boost/sandbox/variadic_templates/boost/mpl/package_... One additional feature of package_range_c is the the order of the indexes can be reversed. Useful if you want to reverse the order of a mpl sequence. -regards, Larry

Thanks for your input Peter and Larry.
Larry, I'm fearful of using unreleased code. Any idea when your
package_range_c could become part of an official boost release?
With that in mind I'm interested in using Peter's approach (which I'm sure
is very similar to the internals of your package_c hey Larry?)
I have 3 questions please.
1. Please can you give an explanation of what the compiler is actually doing
in your make_func_helper() and make_indexes_...() - This goes beyond my
capabilities at the moment, and I'm always looking to improve my knowledge.
2. In attached file "attempt_1.cpp" at Line 44 - I'm getting a compiler
error "expected primary-expression before '...' token" which I don't
understand. How would I bind the variadic template arguments in order to
create a functor of the form boost::function

Ok, I've figured out the answer to question 2: void call(Args... args) { boost::function< void() > bound_fn = boost::bind(f, args...); bound_fn(); // in effect the bound_fn will be stored in a queue for later envocation by a different thread } Interested in your comments on my other 2 questions? Thanks again Steve [snip]
1. Please can you give an explanation of what the compiler is actually doing
in your make_func_helper() and make_indexes_...() - This goes beyond my capabilities at the moment, and I'm always looking to improve my knowledge.
3. In attached file "attempt_2.cpp" at Line 27, there's a struct cb_ with a typedef "type" of the member function pointer of the form T::fn(Args...).
template< class T, class... Args > struct cb_ { typedef void (T::*type)(Args...); };
As far as I can see, this is of the same form as Peter's void (T::*pm)(Args...) member function pointer is it not? How come the compiler can't match &X::f with typename cb_
::type? [/snip]

On 07/22/10 04:20, Steve Lorimer wrote:
Thanks for your input Peter and Larry.
Larry, I'm fearful of using unreleased code. Any idea when your package_range_c could become part of an official boost release?
No idea. I've not gotten much feedback, maybe because there's no documentation??? However, most of the existing mpl docs would apply to the variadic mpl. Also, I'm having trouble getting the code to work with spirit. At present, I'm working on converting mpl:;and_ and mpl::or_ and variant to variadic versions in order to get the code to work with spirit. It's been very tough :(
With that in mind I'm interested in using Peter's approach (which I'm sure is very similar to the internals of your package_c hey Larry?)
Do you mean package_range_c? If so, then yes, it is essentially the same. The only reason for the extra features (arbitrary Value and Start and Finish template params) is that it seemed easy enough to implement.
I have 3 questions please.
[snip]
3. In attached file "attempt_2.cpp" at Line 27, there's a struct cb_ with a typedef "type" of the member function pointer of the form T::fn(Args...).
template< class T, class... Args > struct cb_ { typedef void (T::*type)(Args...); };
As far as I can see, this is of the same form as Peter's void (T::*pm)(Args...) member function pointer is it not? How come the compiler can't match &X::f with typename cb_
::type?
My gcc4.5 gives error:
attempt_2.cpp: In member function 'void func

On 07/22/10 04:20, Steve Lorimer wrote: [snip]
3. In attached file "attempt_2.cpp" at Line 27, there's a struct cb_ with a typedef "type" of the member function pointer of the form T::fn(Args...).
template< class T, class... Args > struct cb_ { typedef void (T::*type)(Args...); };
[snip]
The attached revision of attempt_2.cpp compiles.
The revisions involved adding args to func::call and
rm'ing the struct cb_ and just using the typedef expression
directly in make_function_helper.
I *guess* (emphasis on "guess") the problem is using:
cb_
participants (3)
-
Larry Evans
-
Peter Dimov
-
Steve Lorimer