Boost logo

Boost :

Subject: Re: [boost] [Preprocessor] Adding variadic macros support
From: Edward Diener (eldiener_at_[hidden])
Date: 2010-11-24 18:24:16


On 11/24/2010 5:45 PM, Jeffrey Lee Hellrung, Jr. wrote:
> On 11/24/2010 2:14 PM, Edward Diener wrote:
> [...]
>> I am still not sure what you mean by "macro composition" and "argument
>> binding" in a preprocessor library. Boost PP has much support for macro
>> composition within the context of what it offers in the form of
>> repeatable constructs, data types, etc. but I have a feeling you mean
>> something else. As far as "argument binding", in terms of preprocessor
>> macros all arguments are initially in the form of tokens, so I am not
>> sure what you mean by the phrase.
>
> Imagine Boost.MPL without placeholders.
>
> As a simple example, suppose you already have a macro handy:
>
> #define macro( n ) ...insert your favorite expression involving n...
>
> and want to use it in an invocation of BOOST_PP_ENUM. This requires
> defining a forwarding macro:
>
> #define macro2( z, n, data ) macro( n )
> BOOST_PP_ENUM( N, macro2, ~ )
>
> Argument binding refers to the ability to bind the arguments of
> function-style macros to tokens or placeholders for tokens to be
> substituted later. So one would be able to do something like (making up
> the syntax from what I can remember)
>
> BOOST_PP_ENUM( N, BIND( macro, 2 ), ~ )
>
> where BIND( macro, 2 )( z, n, data ) expands (intermediately) to macro(
> n ). The tokens 1, 2, 3, ... are placeholders to be substituted later,
> and to bind literal tokens to macro arguments, you wrap them in
> parentheses, so that BIND( macro, ( foo ) )( z, n, data ) expands to
> macro( foo ).
>
> Using the fictitious BIND macro, you can also compose macros inline,
> similar to how Boost.Bind works.
>
> This, at least, is what I remember from browsing through either the
> Avalanche code or Paul's Chaos/Order code, I don't remember which. But I
> think both basically provide this functionality.
>
> Hopefully that poor and hastily typed explanation helps,

I understand the explanation. It does not have anything to do with
variadic data as I see it so I do not see it being part of what I have
done. Perhaps someone else can come up with an implementation of your
bind idea for macros.


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