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@lists.isocpp.org> wrote:+ SG10This 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@cmeerw.org> 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@lists.isocpp.org
Subscription: https://lists.isocpp.org/mailman/listinfo.cgi/core
Link to this post: http://lists.isocpp.org/core/2023/06/14395.php
Core mailing list
Core@lists.isocpp.org
Subscription: https://lists.isocpp.org/mailman/listinfo.cgi/core
Link to this post: http://lists.isocpp.org/core/2023/06/14397.php