[C++-sig] [boost.python] Exposing contants at the module level

Markus Schöpflin markus.schoepflin at comsoft.de
Fri Jul 8 11:31:58 CEST 2005


Ralf W. Grosse-Kunstleve wrote:

> --- Markus Schöpflin <markus.schoepflin at comsoft.de> wrote:
> 
>>I need to do something similar like the errno module from python, namely 
>>exponse a bunch of integer constants at the module level.
> 
> 
> I think you are looking for
> 
> boost::python::scope().attr("name") = code;

Yep, that's exactly what I need. Playing around with boost.pp, I got:

#include <boost/preprocessor/seq/for_each.hpp>
#define DEFINE_CONSTANT(X) scope().attr(#X) = X
#define DEFINE_CONSTANTS_HELPER(R, DATA, X) DEFINE_CONSTANT(X);
#define DEFINE_CONSTANTS(SEQ) \
BOOST_PP_SEQ_FOR_EACH(DEFINE_CONSTANTS_HELPER, , SEQ)

which enables you to write:

DEFINE_CONSTANTS((EPERM)(ENOENT)(ESRCH)(EIO)...)

Maybe someone can make use of it.

Thanks, Markus




More information about the Cplusplus-sig mailing list