Boost logo

Boost :

Subject: Re: [boost] [local] Simplifying the parenthesized syntax
From: Edward Diener (eldiener_at_[hidden])
Date: 2011-02-07 14:23:34


On 2/7/2011 11:08 AM, Lorenzo Caminiti wrote:
> On Sun, Feb 6, 2011 at 10:26 AM, Vicente Botet<vicente.botet_at_[hidden]> wrote:
>> The fact that you can not use variadic macros at work doesn't means that
>> your library can not provide in addition variadic macros on compilers
>> supporting them. I have no idea the work that this suppose, but if the
>> interface could be more appealing your library will have much more people
>> interested in.
>>
>> Have you an idea of how the interface could be simplified if variadic macros
>> were used?
>
> The purpose of this email if to brainstorm possible ideas to simplify
> the parenthesized syntax. Sorry in advance if not all that I say is
> correct -- I haven't implemented it yet so I might be saying
> inaccurate/unfeasible things here and there. As always, your feedback
> is very welcome :)
>
>
>
> PRELIMINARY IDEAS TO SIMPLIFY THE PARENTHESIZED SYNTAX
>
> Consider the following parenthesized syntax for local functions:
>
> (void) (f)( (int)(x) (double&)(y) (const bind)((a)(&b))
> (bind)((&c)(d)) ) // [0]
>
> The followings are possible ways to simply this syntax.
>
>
>
> 1 MERGING PARAMETER TYPES AND NAMES (C++ preprocessor)
>
> Parameter names can be passed to function types so I can transform
> `int x` into `int` at compile-time:
>
> int x --[make function type]--> void (int x) --[get 1st parm type]--> int
>
> This should allow me to simplify the parenthesized syntax [0] to:
>
> (void) (f)( (int x) (double& y) (const bind)((a)(&b))
> (bind)((&c)(d)) ) // [1]
>
> Note that the (unbound) parameter type and name are merged into a
> single sequence element.
>
> The following should also be possible:
>
> (void) (f)( (int x) (double& y) (const bind a) (const bind& b)
> (bind& c) (bind d) ) // [1a]
>
> Is [1a] simpler than [1]? Maybe it is...
>
>
>
> 2 TOWARD THE NORMAL PARAMETER LIST SYNTAX (C99 preprocessor)
>
> Using variadic macros I _might_ be able to use a variable length tuple
> (can I? I am not very familiar with these yet...) instead of a
> sequence to represent the function parameters:
>
> (void) (f)(int x, double& y, const bind a, const bind& b, bind& c,
> bind d) // [2]
>
> I think, this is a great simplification over [0] because it is the
> exact same syntax used by C++ to declare function parameters!

Please look at my variadic_macro_data library in the sandbox for how you
can use variadic macros with the Boost PP library. And yes, variadic
macros can give you a variable length number of elements. You can also
use my library to get the number of elements of a Boost PP tuple as well
as any element within the Boost PP tuple, and you can use my library to
get the number of elements of variadic data as well as any element of
the variadic data.

The main thing to remember about variadic macros, which is their main
limitation, is that within any variadic macro specified the variadic
data must come at the end of the macro when the macro is defined using
the ... notation.


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