|
Boost : |
Subject: [boost] [preprocessor] Maybe a improvement of BOOST_PP_IS_EMPTY
From: Zhenghui Zhou (zhouzhenghui_at_[hidden])
Date: 2012-11-20 07:43:12
As I known, the undocument interface BOOST_PP_IS_EMPTY is not a general
implementation to condider emptiness. There is a undefined behaviours when
token concatenation return a invalid preprocessing token. Particularly, gcc
restriction reports error. For example:
#include <boost/preprocessor/
facilities/is_empty.hpp>
BOOST_PP_IS_EMPTY() /* result: 1 */
BOOST_PP_IS_EMPTY(a) /* result: 0 */
BOOST_PP_IS_EMPTY(+a) /* error report here, for '+' cannot be pasted */
Here is a work around, it hasnot been tested enough, but does do under gcc.
#define MY_IS_EMPTY(a) BOOST_PP_EQUAL(BOOST_PP_SEQ_
SIZE(MY_IS_EMPTY_II(MY_IS_EMPTY_I(a))), 2)
#define MY_IS_EMPTY_I(a) (BOOST_PP_CAT(MY_IS_EMPTY_I_,
BOOST_PP_SEQ_SIZE(a))) )
#define MY_IS_EMPTY_I_0 MY_IS_EMPTY_I_HELPER BOOST_PP_LPAREN()
#define MY_IS_EMPTY_I_HELPER(a) )a( /* when
a is empty, my may get more sequence elements of boost proprocessor */
#define MY_IS_EMPTY_II(a) BOOST_PP_CAT(MY_IS_EMPTY_II_,
BOOST_PP_SEQ_SIZE(a)) )
#define MY_IS_EMPTY_II_1 (
#define MY_IS_EMPTY_II_2 ()(
It uses a intermadiate result of BOOST_PP_SEQ_SIZE with wrong parameters,
as:
BOOST_PP_SEQ_SIZE(a) => 0 a
...
I think it maybe better to allow any concatenation tokens in the language
itselft. It's hard to avoid such thing when taking the preprocessor as a
MPL.
I just reported it on comp.std.c,
https://groups.google.com/forum/#!topic/comp.std.c/7rgt8k6ILMM. There are
more things and problems I did and I met. Hope for more response.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk