[preprocessor] Maybe a improvement of BOOST_PP_IS_EMPTY

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.

On 11/20/2012 7:43 AM, Zhenghui Zhou wrote:
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.
See BOOST_IS_EMPTY in my variadic macros library in the sandbox.

On 11/20/2012 7:36 PM, Edward Diener wrote:
On 11/20/2012 7:43 AM, Zhenghui Zhou wrote:
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.
See BOOST_IS_EMPTY in my variadic macros library in the sandbox.
Sorry that should be BOOST_VMD_IS_EMPTY.

Forgive my ignorant. Thanks very much, though it hasn't resloved all of my problems. 2012/11/22 Edward Diener <eldiener@tropicsoft.com>
On 11/20/2012 7:36 PM, Edward Diener wrote:
On 11/20/2012 7:43 AM, Zhenghui Zhou wrote:
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.
See BOOST_IS_EMPTY in my variadic macros library in the sandbox.
Sorry that should be BOOST_VMD_IS_EMPTY.
______________________________**_________________ Unsubscribe & other changes: http://lists.boost.org/** mailman/listinfo.cgi/boost<http://lists.boost.org/mailman/listinfo.cgi/boost>

On 11/22/2012 3:05 AM, Zhenghui Zhou wrote:
On 11/20/2012 7:36 PM, Edward Diener wrote:
On 11/20/2012 7:43 AM, Zhenghui Zhou wrote:
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.
See BOOST_IS_EMPTY in my variadic macros library in the sandbox.
See also, CHAOS_PP_IS_EMPTY_NON_FUNCTION in Chaos. http://sourceforge.net/projects/chaos-pp/ It is the closest that you can get to a general-purpose emptiness-detection macro. It's only limitation is that the input cannot end in the name of a function-like macro. Regards, Paul Mensonides
participants (3)
-
Edward Diener
-
Paul Mensonides
-
Zhenghui Zhou