boost.pp : generate a const size_t array initializer

Hello, I have const size_t MaxNumber = 16; Can I generate this: const size_t elts[MaxNumber] = {0, 1, ..., 15}; with Boost.PP? I suppose I need to #define MaxNumber for PP? Regards,

2009/8/12 Hicham Mouline <hicham@mouline.org>
Hello,
I have const size_t MaxNumber = 16;
Can I generate this: const size_t elts[MaxNumber] = {0, 1, ..., 15};
with Boost.PP?
I suppose I need to #define MaxNumber for PP?
#include <iostream> #include <iterator> #include <boost/preprocessor.hpp> #define N 16 int main() { const int elts[] = { BOOST_PP_ENUM_PARAMS(N, BOOST_PP_EMPTY()) }; std::copy(elts, elts + N, std::ostream_iterator<int>(std::cout, "\n")); } Roman Perepelitsa.

From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Roman Perepelitsa Sent: 12 August 2009 12:26 To: boost-users@lists.boost.org Subject: Re: [Boost-users] boost.pp : generate a const size_t array initializer 2009/8/12 Hicham Mouline <hicham@mouline.org> Hello, I have const size_t MaxNumber = 16; Can I generate this: const size_t elts[MaxNumber] = {0, 1, ..., 15}; with Boost.PP? I suppose I need to #define MaxNumber for PP? ---------------------------------------------------------------------------- -- #include <iostream> #include <iterator> #include <boost/preprocessor.hpp> #define N 16 int main() { const int elts[] = { BOOST_PP_ENUM_PARAMS(N, BOOST_PP_EMPTY()) }; std::copy(elts, elts + N, std::ostream_iterator<int>(std::cout, "\n")); } Roman Perepelitsa. ---------------------------------------------------------------------------- -- Thanks very much. How about generating const int elts[] = { other_array[0], .... other_array[N-1] }; Basically I wished to initialize at compile time 1 const array based on another, I don't see any metaprogramming that allows this. Regards,

2009/8/21 Hicham Mouline <hicham@mouline.org>
Thanks very much. How about generating const int elts[] = { other_array[0], .... other_array[N-1] };
Basically I wished to initialize at compile time 1 const array based on another, I don't see any metaprogramming that allows this.
#include <iostream> #include <iterator> #include <boost/preprocessor.hpp> #define N 10 int main() { const int other_array[N] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; const int elts[] = { #define BOOST_PP_LOCAL_MACRO(I) BOOST_PP_COMMA_IF(I) other_array[I] #define BOOST_PP_LOCAL_LIMITS (0, N) #include BOOST_PP_LOCAL_ITERATE() }; std::copy(elts, elts + N, std::ostream_iterator<int>(std::cout, "\n")); } Roman Perepelitsa.
participants (2)
-
Hicham Mouline
-
Roman Perepelitsa