История изменений
Исправление xperious, (текущая версия) :
да, готовое есть, boost.preprocessor мощь та еще...
только там нумерация с 0 идет, а не с 1, как вы хотите
#include <boost/preprocessor/repetition/repeat.hpp>
int main (int argc, char[] argv*)
{
struct st {
int attr0;
int attr1;
int attr2;
} a, b;
#define A(z, n, text) (a.text ## n = b.text ## n);
BOOST_PP_REPEAT(3, A, attr)
return 0;
}
в принципе, если чутка подшаманить, то можно и с attr1 сделать начало:
#include <boost/preprocessor/repetition/repeat.hpp>
#include <boost/preprocessor/control/if.hpp>
#include <boost/preprocessor/facilities/empty.hpp>
int main (int argc, char[] argv*)
{
struct st {
int attr1;
int attr2;
int attr3;
} a, b;
#define A(z, n, text) BOOST_PP_IF(n, (a.text ## n = b.text ## n);, BOOST_PP_EMPTY())
BOOST_PP_REPEAT(4, A, attr)
return 0;
}
Исправление xperious, :
да, готовое есть, boost.preprocessor мощь та еще...
только там нумерация с 0 идет, а не с 1, как вы хотите
#include <boost/preprocessor/repetition/repeat.hpp>
int main (int argc, char[] argv*)
{
struct st {
int attr0;
int attr1;
int attr2;
} a, b;
#define A(z, n, text) (a.text ## n = b.text ## n);
BOOST_PP_REPEAT(3, A, attr)
return 0;
}
Исходная версия xperious, :
#include <boost/preprocessor/repetition/repeat.hpp>
int main (int argc, char[] argv*)
{
struct st {
int attr0;
int attr1;
int attr2;
} a, b;
#define A(z, n, text) (a.text ## n = b.text ## n);
BOOST_PP_REPEAT(3, A, attr)
return 0;
}