C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Preprocessor macro __COUNTER__

From: Marcin Jaczewski <marcinjaczewski86_at_[hidden]>
Date: Tue, 16 Aug 2022 14:08:49 +0200
wt., 16 sie 2022 o 13:53 Frederick Virchanza Gotham via Std-Proposals
<std-proposals_at_[hidden]> napisaƂ(a):
>
> Every C++ compiler suite I'm aware of supports the preprocessor macro
> __COUNTER__.
>
> So if I do the following:
>
> #include <iostream>
>
> auto main(void) -> int
> {
> std::cout << __COUNTER__ << std::endl;
> std::cout << __COUNTER__ << std::endl;
> std::cout << __COUNTER__ << std::endl;
> std::cout << __COUNTER__ << std::endl;
> }
>
> Then it prints:
> 0
> 1
> 2
> 3
>
> I see that in C++20 we have "std::source_location" which can probably
> take the place of __FILE__, __LINE__, and maybe also __COUNTER__ in
> some scenarios, but I still think __COUNTER__ should be standard C++.

Why exactly do we need it? What is the use case for this and there is
no other way to archive it without macros?
And what exactly is the behavior of this `__COUNTER__ `? Especially
when used in header files.

> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2022-08-16 12:09:01