C++ Logo

sg10

Advanced search

Re: [isocpp-core] Feature test macro for D2169R4 A nice placeholder with no name

From: Barry Revzin <barry.revzin_at_[hidden]>
Date: Thu, 15 Jun 2023 21:42:44 -0500
While I'm not sure it's a great idea to #define _, I think we should
generally err on the side of providing macros for features than not - since
we've missed a few over the years in ways that have mattered.

Looks like the latest revision of the paper has one already.

Thanks!

Barry

On Thu, Jun 15, 2023 at 12:33 AM Corentin via Core <core_at_[hidden]>
wrote:

> + 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
>>
> _______________________________________________
> Core mailing list
> Core_at_[hidden]
> Subscription: https://lists.isocpp.org/mailman/listinfo.cgi/core
> Link to this post: http://lists.isocpp.org/core/2023/06/14395.php
>

Received on 2023-06-16 02:42:59