If boost::preprocessor
and SEQ
representation((a)(b)...
) are allowed,
probably the following code will meet the purpose:
#include <boost/preprocessor/seq/for_each.hpp>
#include <boost/preprocessor/seq/for_each_i.hpp>
#include <boost/preprocessor/punctuation/comma_if.hpp>
#define DEF_MEMBER( r, data, elem ) ref elem;
#define DEF_PARAM( r, data, i, elem ) BOOST_PP_COMMA_IF( i ) ref elem
#define DEF_ASSIGN( r, data, elem ) this->elem = elem;
#define SET_STATE( f, members )
BOOST_PP_SEQ_FOR_EACH( DEF_MEMBER,, members )
f( BOOST_PP_SEQ_FOR_EACH_I( DEF_PARAM,, members ) ) {
BOOST_PP_SEQ_FOR_EACH( DEF_ASSIGN,, members )
}
SET_STATE(FunctorA,(a)(b))
The above code is expanded to
ref a; ref b; FunctorA( ref a , ref b ) { this->a = a; this->b = b; }
in my environment.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…