-----Original Message-----
From: boost-users-bounces@lists.boost.org
[mailto:boost-users-bounces@lists.boost.org] On Behalf Of Arno Schödl
I simply want to increment a macro, like that:
#define VARIABLE 7
FunctionA( VARIABLE ); // VARIABLE expands to 7
#define VARIABLE BOOST_PP_INC(VARIABLE)
FunctionB( VARIABLE ); // VARIABLE expands to 8
#define VARIABLE BOOST_PP_INC(VARIABLE)
FunctionC( VARIABLE ); // VARIABLE expands to 9
#define VARIABLE BOOST_PP_INC(VARIABLE)
...
Of course, as I have written it, it does not work. What's the
right way?
The closest mechanism in the pp-lib is the slot mechanism. E.g.
#include
#define BOOST_PP_VALUE 7
#include BOOST_PP_ASSIGN_SLOT(1)
FunctionA( BOOST_PP_SLOT(1) );
// BOOST_PP_SLOT(1) expands to 7
#define BOOST_PP_VALUE BOOST_PP_SLOT(1) + 1
#include BOOST_PP_ASSIGN_SLOT(1)
FunctionB( BOOST_PP_SLOT(1) );
// BOOST_PP_SLOT(1) expands to 8
#define BOOST_PP_VALUE BOOST_PP_SLOT(1) + 1
#include BOOST_PP_ASSIGN_SLOT(1)
FunctionC( BOOST_PP_SLOT(1) );
// BOOST_PP_SLOT(1) expands to 9
This can be condensed somewhat:
// ----- variable.hpp ----- //
#ifndef VARIABLE_HPP
#define VARIABLE_HPP
#include
#define BOOST_PP_VALUE 7
#include BOOST_PP_ASSIGN_SLOT(1)
#define VARIABLE BOOST_PP_SLOT(1)
#define INC_VARIABLE() "inc_variable.hpp"
#endif
// ----- inc_variable.hpp ----- //
#define BOOST_PP_VALUE VARIABLE + 1
#include BOOST_PP_ASSIGN_SLOT(1)
// ----- client.cpp ----- //
#include "variable.hpp"
FunctionA( VARIABLE );
#include INC_VARIABLE()
FunctionB( VARIABLE );
#include INC_VARIABLE()
FunctionC( VARIABLE );
That is about the best you can do.
Regards,
Paul Mensonides