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

David Abrahams dave at boost-consulting.com
Fri Jul 8 17:17:09 CEST 2005


Markus Schöpflin <markus.schoepflin at comsoft.de> writes:

> 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)
                                                
Empty macro arguments aren't legal in C++.  Just pass a dummy token
like '~'.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com




More information about the Cplusplus-sig mailing list