Boost logo

Boost :

Subject: Re: [boost] [preprocessor] pp-strings
From: lcaminiti (lorcaminiti_at_[hidden])
Date: 2011-06-27 09:39:00


Paul Mensonides wrote:
>
> On Sun, 26 Jun 2011 11:00:16 -0400, Lorenzo Caminiti wrote:
>
>> Any comment on "pp comma-separated strings" support (of lack of thereof)
>> in Boost.Preprocessor and/or CHAOS?
>
> Boost.Preprocessor represents the lowest common denominator in what can
> be made portable across most C and C++ compilers. The main roadblock to
> more significant improvement (nowadays) is VC++'s horrible preprocessor.
>
> By "comma-separated strings" I assume you mean something like: a, b, c?
> Boost.Preprocessor doesn't support them, of course. Chaos doesn't
> support them in that form (generally speaking, data structures containing
> open commas = bad design).
>

I am sorry, I meant to say "*space* separated strings" (not commas). These
are tokens like `a b c` where a character can be a-z, A-Z, 0-9, or _ and all
characters must be separated from each other by one or more spaces.
Concatenation can be used to parse these "space separated strings", for
example (leaving aside reentrancy issues, etc):

#include <boost/preprocessor.hpp>

#define PP_STRING_CHAR_PP_STRING_NULL_NEXT() /* nothing */
#define PP_STRING_CHAR_PP_STRING_NULL PP_STRING_CHAR_PP_STRING_NULL_NEXT(

#define PP_STRING_NEXT_c(str) BOOST_PP_CAT(PP_STRING_CHAR_, str) )
#define PP_STRING_CHAR_c (c) PP_STRING_NEXT_c(

#define PP_STRING_NEXT_b(str) BOOST_PP_CAT(PP_STRING_CHAR_, str) )
#define PP_STRING_CHAR_b (b) PP_STRING_NEXT_b(

#define PP_STRING_NEXT_a(str) BOOST_PP_CAT(PP_STRING_CHAR_, str) )
#define PP_STRING_CHAR_a (a) PP_STRING_NEXT_a(

#define PP_STRING_TO_SEQ(str) \
    BOOST_PP_CAT(PP_STRING_CHAR_, str PP_STRING_NULL) )

PP_STRING_TO_SEQ( a b c ) // expand to (a) (b) (c)

Does CHAOS support these spaced-strings? Where these spaced-strings
considered for Boost.Preprocessor?

NOTE: This is more a curiosity than anything else because I don't actually
have a real use case for these spaced-strings. I researched them because
there was a request for a macro like:

STRING_TO_TYPE( MyType ) // expand to: typedef
mpl::string<'M','y','T','y','p','e'> MyType_id_t;
http://boost.2283326.n4.nabble.com/mpl-string-to-type-conversion-td2668494.html#a2668497

As far as I know, such a macro cannot be implemented but both the following
macros can be done (and I'd prefer somewhat (1) over (2)):

SP_STRING_TO_TYPE( M y T y p e ) // (1)
SEQ_STRING_TO_TYPE( (M)(y)(T)(y)(p)(e) ) // (2)

Another example I was looking at is the possibility of removing the
parenthesis around arbitrary function names in the signature below:

CONTRACT_FUNCTION( void (myfunc) ( int x, (int&) y ) ) // (3)

The following could be done (using pp spaced-strings):

CONTRACT_FUNCTION( void m y f u n c ( int x, (int&) y ) ) // (4)

But at the end I find (4) rather ugly and I chose to only support (3)
instead (so no use for spaced-strings here).

Thanks a lot!
--Lorenzo

--
View this message in context: http://boost.2283326.n4.nabble.com/preprocessor-pp-strings-tp3613014p3627742.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

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