[preprocessor] feature request

Hi, Would it be possible to add BOOST_PP_RESET_COUNTER() macro. The effect is to reset BOOST_PP_COUNTER to zero. These lines of code can do the job: #undef BOOST_PP_COUNTER #define BOOST_PP_COUNTER 0 There are several uses of this facility. For example I want to be sure, that the counter starts at zero when I use it first time in my header, regardless of the other inclusions. Implementation can be similar to BOOST_PP_UPDATE_COUNTER(). new file boost/preprocessor/slot/detail/reset_counter.hpp: #undef BOOST_PP_COUNTER #define BOOST_PP_COUNTER 0 new macro in boost/preprocessor/slot/counter.hpp: #define BOOST_PP_RESET_COUNTER \ <boost/preprocessor/slot/detail/reset_counter.hpp> usage: #include <boost/preprocessor/slot/counter.hpp> BOOST_PP_COUNTER // 0 #include BOOST_PP_UPDATE_COUNTER() BOOST_PP_COUNTER // 1 #include BOOST_PP_UPDATE_COUNTER() BOOST_PP_COUNTER // 2 #include BOOST_PP_RESET_COUNTER() BOOST_PP_COUNTER // 0 Regards, Pavol

-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Pavol Droba
Would it be possible to add BOOST_PP_RESET_COUNTER() macro. The effect is to reset BOOST_PP_COUNTER to zero.
The purpose of the counter is to provide a globally unique number--across includes and across libraries. If actually need a variable, you should use the slot mechanism instead. It is a little more wordy, but it gives you more control over what the value actually is. #define BOOST_PP_VALUE 0 #include BOOST_PP_ASSIGN_SLOT(1) BOOST_PP_SLOT(1) // 0 #define BOOST_PP_VALUE BOOST_PP_SLOT(1) + 1 #include BOOST_PP_ASSIGN_SLOT(1) BOOST_PP_SLOT(1) // 1 // etc. We could add a BOOST_PP_SLOT_INC macro to shorten this. Regards, Paul Mensonides

Paul Mensonides wrote:
-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Pavol Droba
Would it be possible to add BOOST_PP_RESET_COUNTER() macro. The effect is to reset BOOST_PP_COUNTER to zero.
The purpose of the counter is to provide a globally unique number--across includes and across libraries. If actually need a variable, you should use the slot mechanism instead. It is a little more wordy, but it gives you more control over what the value actually is.
#define BOOST_PP_VALUE 0 #include BOOST_PP_ASSIGN_SLOT(1)
BOOST_PP_SLOT(1) // 0
#define BOOST_PP_VALUE BOOST_PP_SLOT(1) + 1 #include BOOST_PP_ASSIGN_SLOT(1)
BOOST_PP_SLOT(1) // 1
// etc.
We could add a BOOST_PP_SLOT_INC macro to shorten this.
Thanks for explanation. This is sufficient for my needs, even though I find counter more elegant. BOOST_PP_SLOT_INC would be handy. Best regards, Pavol.
participants (2)
-
Paul Mensonides
-
Pavol Droba