Boost logo

Boost Users :

Subject: Re: [Boost-users] [bind] Possible to use variadic templates with bind?
From: Larry Evans (cppljevans_at_[hidden])
Date: 2010-07-21 14:41:29


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 <boost/bind.hpp>
> #include <boost/function.hpp>
>
> template<int...> struct int_tuple {};
>
> // make indexes impl is a helper for make indexes
> template<int I, typename IntTuple, typename... Types>
> struct make_indexes_impl;
>
> template<int I, int... Indexes, typename T, typename... Types>
> struct make_indexes_impl<I, int_tuple<Indexes...>, T, Types...>
> {
> typedef typename make_indexes_impl<I+1,
> int_tuple<Indexes..., I>,
> Types...>::type type;
> };
>
> template<int I, int... Indexes>
> struct make_indexes_impl<I, int_tuple<Indexes...> >
> {
> typedef int_tuple<Indexes...> type;
> };
>
> template<typename... Types>
> 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_range_c.hpp

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


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