Boost logo

Boost :

Subject: Re: [boost] [preprocessor] Get last token
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2011-11-28 07:32:06


On Mon, Nov 28, 2011 at 6:28 AM, Roman Perepelitsa
<roman.perepelitsa_at_[hidden]> wrote:
> 2011/11/28 Lorenzo Caminiti <lorcaminiti_at_[hidden]>
>
>> On Mon, Nov 28, 2011 at 5:18 AM, Roman Perepelitsa
>> <roman.perepelitsa_at_[hidden]> wrote:
>> > Is it possible to extract the last token from a list of space separated
>> > tokens?
>>
>> AFAIK, it depends. If the preceding tokens are known a priory and do
>> not contain non-alphanumeric symbols, yes. Otherwise, no.
>>
>> > LAST_TOKEN(a b)  // expands to b
>> > LAST_TOKEN(blah blah b)  // expands to b
>>
>> Yes but only if you know that `a` and `blah blah` are the only tokens
>> that will ever be in front of b.
>>
>> > LAST_TOKEN(* & b)  // expands to b
>>
>> No because * and & are not alphanumeric.
>>
>> If this is your case, I can reply writing you the macros that can do this.
>
>
> Thanks for the reply, Lorenzo.
>
> Tokens can be anything in my case. I'll change the API of my macro to avoid
> the need for LAST_TOKEN.

Then one option would be to wrap the leading tokens within extra parenthesis:

LAST_TOKEN( (a) b )
LAST_TOKEN( (blah blah) b )
LAST_TOKEN( (* &) b )

Or maybe (but I'm not 100% sure) even:

LAST_TOKEN( (blah) (blah) b )
LAST_TOKEN( (*) (&) b )

This macro can be implemented (but depending on your application
domain there might be better looking options). Let me know if you need
me to send you a draft implementation of the macro above.

HTH,
--Lorenzo


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