[mpl] string to type conversion

Hello, I would like to have a macro which could be used like this: STRING_TO_TYPE( MyType ) which would yield: typedef mpl::string<'M','y','T','y','p','e'> MyType_id_t; Any ideas how to implement something like that? Thanks for any help, bma. -- Bartosz Marcinkiewicz tel. (+48) 516 034 243 e-mail: bma@epcon.pl, bartosz.marcinkiewicz@epcon.pl EPCON Sp. z o.o. www.epcon.pl adres: 53-407 Wrocław, ul. Gajowicka 114/116 tel. (+48) 71 361 75 55 ext.36 fax (+48) 71 361 74 44 NIP PL 899-24-92-498 KRS 0000190187 REGON 932963731 Kapitał zakładowy: 500 000 PLN

The only way I imagine this can be done, is by predefining all known words up to a given length as suffix to a macro (as done with BOOST_PP_ADD), but obviously this does not scale and also limits NAME to variable names. #define BOOST_MPL_STRINGIZE(NAME) BOOST_PP_CAT(BOOST_PP_STRING_TO_TYPE_,NAME); so that BOOST_MPL_STRINGIZE(MyType) is substituted by BOOST_MPL_STRINGIZE_MyType assuming an existing define for the trivial macro #define BOOST_MPL_STRINGIZE_MyType boost::mpl::string<'M','y','T','y','p','e'> you got what you need. But thats nearly useless, as such code needs to be automatically generated by the preprocessor. I think its not worth the effort, but maybe there are highly sophisticated ways to use the preprocessor lib of boost, to do the generation job. Any ideas ? Best regards, Ingo. -----boost-bounces@lists.boost.org wrote: ----- To: boost@lists.boost.org From: Bartosz Marcinkiewicz <bma@epcon.pl> Sent by: boost-bounces@lists.boost.org Date: 05/13/2010 11:09AM Subject: [boost] [mpl] string to type conversion Hello, I would like to have a macro which could be used like this: STRING_TO_TYPE( MyType ) which would yield: typedef mpl::string<'M','y','T','y','p','e'> MyType_id_t; Any ideas how to implement something like that? Thanks for any help, bma. -- Bartosz Marcinkiewicz tel. (+48) 516 034 243 e-mail: bma@epcon.pl, bartosz.marcinkiewicz@epcon.pl EPCON Sp. z o.o. www.epcon.pl adres: 53-407 Wrocław, ul. Gajowicka 114/116 tel. (+48) 71 361 75 55 ext.36 fax (+48) 71 361 74 44 NIP PL 899-24-92-498 KRS 0000190187 REGON 932963731 Kapitał zakładowy: 500 000 PLN _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

2010/5/13 Bartosz Marcinkiewicz <bma@epcon.pl>:
Hello,
I would like to have a macro which could be used like this:
STRING_TO_TYPE( MyType )
which would yield:
typedef mpl::string<'M','y','T','y','p','e'> MyType_id_t;
Any ideas how to implement something like that?
I also researched something similar about 1 year ago and concluded that it is not possible (but I think CHAOS supports a string-type preprocessor data structure which I did not investigate because it is not available for all compilers). This can be done instead if you are willing to wrap the single characters between parenthesis: STRING_TO_TYPE( (M)(y)(T)(y)(p)(e) ) If this would work for your application, I can post the code for this macro (or just look at BOOST_PP_SEQ_FOLD_LEFT() or similar and program it yourself). Let me know. Regards, -- Lorenzo

On Tue, May 18, 2010 at 10:22 PM, Lorenzo Caminiti <lorcaminiti@gmail.com> wrote:
2010/5/13 Bartosz Marcinkiewicz <bma@epcon.pl>:
Hello,
I would like to have a macro which could be used like this:
STRING_TO_TYPE( MyType )
which would yield:
typedef mpl::string<'M','y','T','y','p','e'> MyType_id_t;
Any ideas how to implement something like that?
I also researched something similar about 1 year ago and concluded that it is not possible (but I think CHAOS supports a string-type preprocessor data structure which I did not investigate because it is not available for all compilers).
This can be done instead if you are willing to wrap the single characters between parenthesis:
STRING_TO_TYPE( (M)(y)(T)(y)(p)(e) )
It has been a _long_ while since you posted this... but I just recently find out that also this can be done: STRING_TO_TYPE( M y T y p e ) (Spaces between letters are mandatory.) --Lorenzo
participants (4)
-
Bartosz Marcinkiewicz
-
Ingo Loehken
-
Lorenzo Caminiti
-
Philippe Vaucher