C++ Logo

sg10

Advanced search

Re: Feature test macro for D2169R4 A nice placeholder with no name

From: Corentin <corentin.jabot_at_[hidden]>
Date: Thu, 15 Jun 2023 08:32:52 +0300
+ SG10
This pattern is principally used for global variables, for which
placeholders are not allowed, so I doubt this would be useful.
That being said, I defer to SG10 call, I'm happy to add one if
people think it would have use cases.

Thanks!







On Wed, Jun 14, 2023 at 10:33 PM Christof Meerwald <cmeerw_at_[hidden]>
wrote:

> Not sure how widespread these workarounds are, but there are
> stackoverflow questions related to this:
>
>
> https://stackoverflow.com/questions/10379691/creating-macro-using-line-for-different-variable-names
>
> https://stackoverflow.com/questions/1082192/how-to-generate-random-variable-names-in-c-using-macros
> https://stackoverflow.com/questions/461062/c-anonymous-variables
>
> (and I think I have seen real-world code using these workarounds)
>
> So I think the use case for a feature-test macro would be something
> like this:
>
> #ifndef __unnamed_placeholder
> #define CONCAT2(a, b) a ## b
> #define CONCAT(a, b) CONCAT2(a, b)
> #ifdef __COUNTER__
> #define _ CONCAT(placeholder, __COUNTER__)
> #else
> #define _ CONCAT(placeholder, __LINE__)
> #endif
> #endif
>
> void f()
> {
> int _ = 1;
> int _ = 2;
> }
>
>
> Christof
>
> --
>
> https://cmeerw.org sip:cmeerw at cmeerw.org
> mailto:cmeerw at cmeerw.org xmpp:cmeerw at cmeerw.org
>

Received on 2023-06-15 05:33:06