Boost logo

Boost :

Subject: Re: [boost] Review Request: Variadic Macro Data library
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2011-02-21 11:27:28


On Sun, Feb 20, 2011 at 7:56 PM, Edward Diener <eldiener_at_[hidden]> wrote:
> On 2/18/2011 7:27 PM, Lorenzo Caminiti wrote:
>>
>> On Thu, Feb 17, 2011 at 5:13 PM, Edward Diener<eldiener_at_[hidden]>
>>  wrote:
>>>
>>> I am requesting that my library, the Variadic Macro Data library, which
>>> is
>>> in the sandbox in the variadic_macro_data directory, be reviewed for
>>> inclusion into Boost.
>>>
>>> The variadic_macro_data library adds support and functionality for
>>> variadic
>>> macros to Boost as well as integrating variadic macros with the Boost PP
>>> library without changing the latter library in any way.
>>>
>>> I believe others have used my library, can attest to its quality and that
>>> it
>>> does what it is supposed to do. and have found it useful when using
>>> variadic
>>> macros with Boost PP. I myself have used its functionality in my own TTI
>>> library in the sandbox. Support for variadic macros is implemented in
>>> nearly
>>> all modern C++ compilers and the syntax is natural for an end-user. The
>>> library is finalized as far as functionality is concerned and I would
>>> like
>>> to see it in Boost and am willing to maintain it as a Boost library.
>>
>> Is it possible to use variadic macros to detect empty parameters?
>>
>> For example:
>>
>> #include<boost/variadic_macro_data/VariadicMacroData.hpp>  // Proposed
>> lib.
>>
>> VMD_DATA_SIZE(1, 2) // 2
>> VMD_DATA_SIZE(1)    // 1
>> VMD_DATA_SIZE()     // 1 not 0 :((
>>
>> But I would like to the last size to expand to 0 (or have a different
>> macro that would expand to 0 in that case).
>>
>> With a real C99 preprocessor (e.g., GCC) I can do the following
>> because empty macro parameters are supported:
>>
>> #include<boost/variadic_macro_data/VariadicMacroData.hpp>  // Proposed
>> lib.
>> #include<boost/preprocessor.hpp>
>> #include<boost/preprocessor/facilities/is_empty.hpp>
>>
>> #define PP_VA_EAT(...) /* must expand to nothing */
>>
>> #define PP_VA_SIZE_1OR0_(x) BOOST_PP_IIF(BOOST_PP_IS_EMPTY(x), 0, 1)
>>
>> #define PP_VA_SIZE_(size, ...) \
>>     BOOST_PP_IIF(BOOST_PP_EQUAL(size, 1), \
>>         PP_VA_SIZE_1OR0_ \
>>     , \
>>         size PP_VA_EAT \
>>     )(__VA_ARGS__)
>>
>> #define PP_VA_SIZE(...) PP_VA_SIZE_(VMD_DATA_SIZE(__VA_ARGS__),

Note that I am using the rev of your lib before you added the BOOST_
prefix (see VMD_... instead of BOOST_VMD_...).

>> __VA_ARGS__)
>>
>> PP_VA_SIZE(1, 2)    // 2
>> PP_VA_SIZE(1)       // 1
>> PP_VA_SIZE()        // 0 :))
>
> This does not work for me under gcc.

It should work if either you add the BOOST_ prefix to your lib macros
of you use the older rev of your lib without such prefixes.

> #include <boost/variadic_macro_data/vmd.hpp>
> #include <boost/preprocessor.hpp>
> #include <boost/preprocessor/facilities/is_empty.hpp>
>
> #if !defined(BOOST_NO_VARIADIC_MACROS)
> #define PP_VA_EAT(...) /* must expand to nothing */
> #define PP_VA_SIZE_1OR0_(x) BOOST_PP_IIF(BOOST_PP_IS_EMPTY(x), 0, 1)
> #define PP_VA_SIZE_(size, ...) \
>    BOOST_PP_IIF(BOOST_PP_EQUAL(size, 1), \
>        PP_VA_SIZE_1OR0_ \
>    , \
>        size PP_VA_EAT \
>    )(__VA_ARGS__)
> #define PP_VA_SIZE(...) PP_VA_SIZE_(VMD_DATA_SIZE(__VA_ARGS__), __VA_ARGS__)
> #endif
>
> int main()
>  {
>  int j = PP_VA_SIZE(2);
>  return 0;
>  }
>
> Gcc:
>
> "...patience...
> ...found 319 targets...
> ...updating 4 targets...
> gcc.compile.c++
> ..\..\..\bin.v2\libs\variadic_macro_data\test\test_data_try.test\gcc-mingw-4.5.2\debug\test_data_try.o
> test_data_try.cpp: In function 'int main()':
> test_data_try.cpp:25:11: error:
> 'BOOST_PP_IIF_BOOST_PP_COMPL_BOOST_PP_NOT_EQUAL_CHECK_BOOST_PP_NOT_EQUAL_VMD_DATA_SIZE'

Again, see the error is that the PP_CAT expanded in the #undefined
symbol ...EQUAL_VMD_DATA_SIZE because VMD_DATA_SIZE did not expand but
BOOST_MVD_DATA_SIZE will expand here.

> was not declared in this scope
> test_data_try.cpp:25:1: error: 'BOOST_PP_NOT_EQUAL_1' was not declared in
> this scope
> test_data_try.cpp:13:9: error: 'PP_VA_SIZE_1OR0_' was not declared in this
> scope
> test_data_try.cpp:25:11: error: 'VMD_DATA_SIZE' was not declared in this
> scope
> test_data_try.cpp:25:7: warning: unused variable 'j'
>
>    "g++"  -ftemplate-depth-128 -O0 -fno-inline -Wall -pedantic -g
> -Wno-variadic-macros   -I"..\..\.." -I"C:\Programming\VersionControl\boost"
> -c -o
> "..\..\..\bin.v2\libs\variadic_macro_data\test\test_data_try.test\gcc-mingw-4.5.2\debug\test_data_try.o"
> "test_data_try.cpp"
>
> ...failed gcc.compile.c++
> ..\..\..\bin.v2\libs\variadic_macro_data\test\test_data_try.test\gcc-mingw-4.5.2\debug\test_data_try.o...
> ...skipped
> <p..\..\..\bin.v2\libs\variadic_macro_data\test\test_data_try.test\gcc-mingw-4.5.2\debug>test_data_try.exe
> for lack of
> <p..\..\..\bin.v2\libs\variadic_macro_data\test\test_data_try.test\gcc-mingw-4.5.2\debug>test_data_try.o...
> ...skipped
> <p..\..\..\bin.v2\libs\variadic_macro_data\test\test_data_try.test\gcc-mingw-4.5.2\debug>test_data_try.run
> for lack of
> <p..\..\..\bin.v2\libs\variadic_macro_data\test\test_data_try.test\gcc-mingw-4.5.2\debug>test_data_try.exe...
> ...failed updating 1 target...
> ...skipped 3 targets..."

-- 
Lorenzo

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk