[mpl] integer for_each

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[mpl] integer for_each

Yuval Ronen
Hi.
I have a function which is templated with an integer

template <int N>
void f()
{
    ...
}

Within this function, I wish to use mpl::for_each to call another
integer-templated (say, g()) function, with all numbers from 0 to N-1.

How can I achieve this?

I thought of making a mpl::vector<int_<0>, int_<1>, ..., int_<N-1> >,
and then use mpl::for_each to iterate it, but I don't know how to
generate this mpl::vector. How can I do that? Or maybe there's a better way?

BTW: I first thought of using mpl::vector_c, but it seems that
mpl:for_each doesn't support mpl::vector_c, only mpl::vector. Is this true?

Thanks,
Yuval

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [mpl] integer for_each

David Abrahams
Yuval Ronen wrote:

> Hi.
> I have a function which is templated with an integer
>
> template <int N>
> void f()
> {
>     ...
> }
>
> Within this function, I wish to use mpl::for_each to call another
> integer-templated (say, g()) function, with all numbers from 0 to N-1.
>
> How can I achieve this?
>
> I thought of making a mpl::vector<int_<0>, int_<1>, ..., int_<N-1> >,
> and then use mpl::for_each to iterate it, but I don't know how to
> generate this mpl::vector. How can I do that? Or maybe there's a better way?
>
> BTW: I first thought of using mpl::vector_c, but it seems that
> mpl:for_each doesn't support mpl::vector_c, only mpl::vector. Is this true?

See mpl::range_c

HTH,
Dave

--
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [mpl] integer for_each

Yuval Ronen
David Abrahams wrote:
> See mpl::range_c

Excellent, thanks!

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users