|
Boost : |
Subject: Re: [boost] Enum Conversion
From: Roland Bock (rbock_at_[hidden])
Date: 2012-09-03 00:42:13
On 2012-09-02 23:34, Lorenzo Caminiti wrote:
> On Sun, Sep 2, 2012 at 1:17 PM, Lorenzo Caminiti <lorcaminiti_at_[hidden]> wrote:
>> On Sun, Sep 2, 2012 at 12:30 PM, Roland Bock <rbock_at_[hidden]> wrote:
>>> [...]
>>>
>>> Obviously, if I could use the preprocessor to translate
>>>
>>> Alpha = 5 -> (Alpha, 5)
>>>
>>> I'd be done. But I have no idea how to do that. Any suggestions?
>> There's no way you can strip the = symbol with the pp. You can only do:
>>
>> Alpha = 5 -> (Alpha =, 5)
> Actually, I don't think you can't even do this because if you
> concatenate from the back Alpha = 5 ## _SPLIT_NUM then 5_SPLIT_NUM is
> not a valid macro identifier :( Otherwise, the idea would be to:
>
> #define 5_SPLIT_NUM , 5
> ... // #define for all ints [0, 255]
> #define SPLIT(int_assignment) BOOST_PP_CAT(int_assignment, _SPLIT_NUM))
> SPLIT(Alpha = 5)
>
> You could do something different (and more alphanumeric) all
> together... but I'm not sure if I'd advice it:
>
> CREATE_CONVERTER_METHODS(Greek,
> 5 as Alpha,
> 3 as Beta,
> 7 as Gamma,
> 1 as Delta,
> 6 as Epsilon
> )
>
> Now: 5 as Alpha -> (Alpha, 5).
>
>
That certainly looks a bit weird, but thanks for explaining in such
detail to someone who is not really used to preprocessor programming :-)
Regards,
Roland
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk