How do I check for C++20 support? What is the value of __cplusplus for C++20?
up vote
19
down vote
favorite
Related to questions How do I check for C++11 support? and What is the value of __cplusplus for C++17?
How can I inquire whether the compiler can handle / is set up to use C++20? I know that it is in principle possible to inquire the C++ version by:
#if __cplusplus > ???
// C++20 code here
#endif
What should ???
be for C++20?
c++ macros c++20
add a comment |
up vote
19
down vote
favorite
Related to questions How do I check for C++11 support? and What is the value of __cplusplus for C++17?
How can I inquire whether the compiler can handle / is set up to use C++20? I know that it is in principle possible to inquire the C++ version by:
#if __cplusplus > ???
// C++20 code here
#endif
What should ???
be for C++20?
c++ macros c++20
4
Test for greater than 2017 does not work?
– Antoine Morrier
yesterday
2
@AntoineMorrier Of course! Why didn't I think of that? Whatever the value for C++20 will be will be larger than the one for 17.
– user2296653
yesterday
5
In most cases, prefer to test the features you require, rather than the language version.
– Toby Speight
yesterday
add a comment |
up vote
19
down vote
favorite
up vote
19
down vote
favorite
Related to questions How do I check for C++11 support? and What is the value of __cplusplus for C++17?
How can I inquire whether the compiler can handle / is set up to use C++20? I know that it is in principle possible to inquire the C++ version by:
#if __cplusplus > ???
// C++20 code here
#endif
What should ???
be for C++20?
c++ macros c++20
Related to questions How do I check for C++11 support? and What is the value of __cplusplus for C++17?
How can I inquire whether the compiler can handle / is set up to use C++20? I know that it is in principle possible to inquire the C++ version by:
#if __cplusplus > ???
// C++20 code here
#endif
What should ???
be for C++20?
c++ macros c++20
c++ macros c++20
edited yesterday
gsamaras
48.6k2396178
48.6k2396178
asked yesterday
user2296653
303111
303111
4
Test for greater than 2017 does not work?
– Antoine Morrier
yesterday
2
@AntoineMorrier Of course! Why didn't I think of that? Whatever the value for C++20 will be will be larger than the one for 17.
– user2296653
yesterday
5
In most cases, prefer to test the features you require, rather than the language version.
– Toby Speight
yesterday
add a comment |
4
Test for greater than 2017 does not work?
– Antoine Morrier
yesterday
2
@AntoineMorrier Of course! Why didn't I think of that? Whatever the value for C++20 will be will be larger than the one for 17.
– user2296653
yesterday
5
In most cases, prefer to test the features you require, rather than the language version.
– Toby Speight
yesterday
4
4
Test for greater than 2017 does not work?
– Antoine Morrier
yesterday
Test for greater than 2017 does not work?
– Antoine Morrier
yesterday
2
2
@AntoineMorrier Of course! Why didn't I think of that? Whatever the value for C++20 will be will be larger than the one for 17.
– user2296653
yesterday
@AntoineMorrier Of course! Why didn't I think of that? Whatever the value for C++20 will be will be larger than the one for 17.
– user2296653
yesterday
5
5
In most cases, prefer to test the features you require, rather than the language version.
– Toby Speight
yesterday
In most cases, prefer to test the features you require, rather than the language version.
– Toby Speight
yesterday
add a comment |
3 Answers
3
active
oldest
votes
up vote
22
down vote
accepted
It's too early for that.
Until the standard replaces it, use:
#if __cplusplus > 201703L
// C++20 code
#endif
since the predefined macro of C++20 is going to be larger than the one of C++17.
As @SombreroChicken's answer mentions, [cpp.predefined] (1.1) specifies (emphasis mine):
__cplusplus
The integer literal
201703L
. [Note: It is intended that future versions of this International Standard will replace the value
of this macro with a greater value.]
The macros used, as of Nov 2018, are:
- GCC 9.0.0:
201709L
for C++2a. Live demo
- Clang 8.0.0:
201707L
. Live demo
- VC++ 15.9.3:
201704L
(as @Acorn's answer mentions).
PS: If you are interested in specific features, then [cpp.predefined] (1.8) defines corresponding macros, which you could use. Notice though, that they might change in the future.
3
gcc 8.2 uses201709
forc++2a
and clang 7.0 uses201707
– bolov
yesterday
Same for GCC 9 and Clang 8 @bolov, updated my answer, thanks!
– gsamaras
yesterday
It is not nice to copy other answers after you already have the accepted and top-voted answer :-)
– Acorn
yesterday
Yes I agree @Acorn. However, notice how some people are improving their answers in parallel. I see that our answers have a lot in common, just like yours with Sombrero Chicken. If you think, I should modify my answer to improve the gain the future user will have from reading this, then let me know. In any case, if you think yours should be accepted instead, then no problem, your answer is very good :) Also let's clean these up later, for the sake of the future user please.
– gsamaras
yesterday
@Davislor that's not the case, but since all answer have a common backbone and people might think of that, I will partition the commonalities to the one that posted first a relevant section. Hope that clears things up... (please don't forget to delete your comment later, since it's clatter for future readers)
– gsamaras
yesterday
add a comment |
up vote
9
down vote
The new value will be available at some point at [cpp.predefined]p1.1:
__cplusplus
The integer literal
201703L
. [ Note: It is intended that future versions of this International Standard will replace the value of this macro with a greater value. — end note ]
The current values used in the major compilers are, as of 2018-11-30:
gcc:201709L
godbolt
clang:201707L
godbolt
msvc:201704L
godbolt (requires/Zc:__cplusplus
)
icc: unsupported godbolt (for the moment)
Since all of them are already higher than C++17's 201703L
, you can already use:
#if __cplusplus > 201703L
// C++20 code
#endif
add a comment |
up vote
5
down vote
There's no known __cplusplus
version yet because C++20 is still in development. There are only drafts for C++20.
The latest draft N4788 still contains:
__cplusplus
The integer literal
201703L
. [Note: It is intended that future versions of this International Standard will replace the value
of this macro with a greater value. —end note]
As for checking it, I would use @gsamaras answer.
@gsamaras just because you asked nicely
– Sombrero Chicken
yesterday
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
22
down vote
accepted
It's too early for that.
Until the standard replaces it, use:
#if __cplusplus > 201703L
// C++20 code
#endif
since the predefined macro of C++20 is going to be larger than the one of C++17.
As @SombreroChicken's answer mentions, [cpp.predefined] (1.1) specifies (emphasis mine):
__cplusplus
The integer literal
201703L
. [Note: It is intended that future versions of this International Standard will replace the value
of this macro with a greater value.]
The macros used, as of Nov 2018, are:
- GCC 9.0.0:
201709L
for C++2a. Live demo
- Clang 8.0.0:
201707L
. Live demo
- VC++ 15.9.3:
201704L
(as @Acorn's answer mentions).
PS: If you are interested in specific features, then [cpp.predefined] (1.8) defines corresponding macros, which you could use. Notice though, that they might change in the future.
3
gcc 8.2 uses201709
forc++2a
and clang 7.0 uses201707
– bolov
yesterday
Same for GCC 9 and Clang 8 @bolov, updated my answer, thanks!
– gsamaras
yesterday
It is not nice to copy other answers after you already have the accepted and top-voted answer :-)
– Acorn
yesterday
Yes I agree @Acorn. However, notice how some people are improving their answers in parallel. I see that our answers have a lot in common, just like yours with Sombrero Chicken. If you think, I should modify my answer to improve the gain the future user will have from reading this, then let me know. In any case, if you think yours should be accepted instead, then no problem, your answer is very good :) Also let's clean these up later, for the sake of the future user please.
– gsamaras
yesterday
@Davislor that's not the case, but since all answer have a common backbone and people might think of that, I will partition the commonalities to the one that posted first a relevant section. Hope that clears things up... (please don't forget to delete your comment later, since it's clatter for future readers)
– gsamaras
yesterday
add a comment |
up vote
22
down vote
accepted
It's too early for that.
Until the standard replaces it, use:
#if __cplusplus > 201703L
// C++20 code
#endif
since the predefined macro of C++20 is going to be larger than the one of C++17.
As @SombreroChicken's answer mentions, [cpp.predefined] (1.1) specifies (emphasis mine):
__cplusplus
The integer literal
201703L
. [Note: It is intended that future versions of this International Standard will replace the value
of this macro with a greater value.]
The macros used, as of Nov 2018, are:
- GCC 9.0.0:
201709L
for C++2a. Live demo
- Clang 8.0.0:
201707L
. Live demo
- VC++ 15.9.3:
201704L
(as @Acorn's answer mentions).
PS: If you are interested in specific features, then [cpp.predefined] (1.8) defines corresponding macros, which you could use. Notice though, that they might change in the future.
3
gcc 8.2 uses201709
forc++2a
and clang 7.0 uses201707
– bolov
yesterday
Same for GCC 9 and Clang 8 @bolov, updated my answer, thanks!
– gsamaras
yesterday
It is not nice to copy other answers after you already have the accepted and top-voted answer :-)
– Acorn
yesterday
Yes I agree @Acorn. However, notice how some people are improving their answers in parallel. I see that our answers have a lot in common, just like yours with Sombrero Chicken. If you think, I should modify my answer to improve the gain the future user will have from reading this, then let me know. In any case, if you think yours should be accepted instead, then no problem, your answer is very good :) Also let's clean these up later, for the sake of the future user please.
– gsamaras
yesterday
@Davislor that's not the case, but since all answer have a common backbone and people might think of that, I will partition the commonalities to the one that posted first a relevant section. Hope that clears things up... (please don't forget to delete your comment later, since it's clatter for future readers)
– gsamaras
yesterday
add a comment |
up vote
22
down vote
accepted
up vote
22
down vote
accepted
It's too early for that.
Until the standard replaces it, use:
#if __cplusplus > 201703L
// C++20 code
#endif
since the predefined macro of C++20 is going to be larger than the one of C++17.
As @SombreroChicken's answer mentions, [cpp.predefined] (1.1) specifies (emphasis mine):
__cplusplus
The integer literal
201703L
. [Note: It is intended that future versions of this International Standard will replace the value
of this macro with a greater value.]
The macros used, as of Nov 2018, are:
- GCC 9.0.0:
201709L
for C++2a. Live demo
- Clang 8.0.0:
201707L
. Live demo
- VC++ 15.9.3:
201704L
(as @Acorn's answer mentions).
PS: If you are interested in specific features, then [cpp.predefined] (1.8) defines corresponding macros, which you could use. Notice though, that they might change in the future.
It's too early for that.
Until the standard replaces it, use:
#if __cplusplus > 201703L
// C++20 code
#endif
since the predefined macro of C++20 is going to be larger than the one of C++17.
As @SombreroChicken's answer mentions, [cpp.predefined] (1.1) specifies (emphasis mine):
__cplusplus
The integer literal
201703L
. [Note: It is intended that future versions of this International Standard will replace the value
of this macro with a greater value.]
The macros used, as of Nov 2018, are:
- GCC 9.0.0:
201709L
for C++2a. Live demo
- Clang 8.0.0:
201707L
. Live demo
- VC++ 15.9.3:
201704L
(as @Acorn's answer mentions).
PS: If you are interested in specific features, then [cpp.predefined] (1.8) defines corresponding macros, which you could use. Notice though, that they might change in the future.
edited 14 hours ago
answered yesterday
gsamaras
48.6k2396178
48.6k2396178
3
gcc 8.2 uses201709
forc++2a
and clang 7.0 uses201707
– bolov
yesterday
Same for GCC 9 and Clang 8 @bolov, updated my answer, thanks!
– gsamaras
yesterday
It is not nice to copy other answers after you already have the accepted and top-voted answer :-)
– Acorn
yesterday
Yes I agree @Acorn. However, notice how some people are improving their answers in parallel. I see that our answers have a lot in common, just like yours with Sombrero Chicken. If you think, I should modify my answer to improve the gain the future user will have from reading this, then let me know. In any case, if you think yours should be accepted instead, then no problem, your answer is very good :) Also let's clean these up later, for the sake of the future user please.
– gsamaras
yesterday
@Davislor that's not the case, but since all answer have a common backbone and people might think of that, I will partition the commonalities to the one that posted first a relevant section. Hope that clears things up... (please don't forget to delete your comment later, since it's clatter for future readers)
– gsamaras
yesterday
add a comment |
3
gcc 8.2 uses201709
forc++2a
and clang 7.0 uses201707
– bolov
yesterday
Same for GCC 9 and Clang 8 @bolov, updated my answer, thanks!
– gsamaras
yesterday
It is not nice to copy other answers after you already have the accepted and top-voted answer :-)
– Acorn
yesterday
Yes I agree @Acorn. However, notice how some people are improving their answers in parallel. I see that our answers have a lot in common, just like yours with Sombrero Chicken. If you think, I should modify my answer to improve the gain the future user will have from reading this, then let me know. In any case, if you think yours should be accepted instead, then no problem, your answer is very good :) Also let's clean these up later, for the sake of the future user please.
– gsamaras
yesterday
@Davislor that's not the case, but since all answer have a common backbone and people might think of that, I will partition the commonalities to the one that posted first a relevant section. Hope that clears things up... (please don't forget to delete your comment later, since it's clatter for future readers)
– gsamaras
yesterday
3
3
gcc 8.2 uses
201709
for c++2a
and clang 7.0 uses 201707
– bolov
yesterday
gcc 8.2 uses
201709
for c++2a
and clang 7.0 uses 201707
– bolov
yesterday
Same for GCC 9 and Clang 8 @bolov, updated my answer, thanks!
– gsamaras
yesterday
Same for GCC 9 and Clang 8 @bolov, updated my answer, thanks!
– gsamaras
yesterday
It is not nice to copy other answers after you already have the accepted and top-voted answer :-)
– Acorn
yesterday
It is not nice to copy other answers after you already have the accepted and top-voted answer :-)
– Acorn
yesterday
Yes I agree @Acorn. However, notice how some people are improving their answers in parallel. I see that our answers have a lot in common, just like yours with Sombrero Chicken. If you think, I should modify my answer to improve the gain the future user will have from reading this, then let me know. In any case, if you think yours should be accepted instead, then no problem, your answer is very good :) Also let's clean these up later, for the sake of the future user please.
– gsamaras
yesterday
Yes I agree @Acorn. However, notice how some people are improving their answers in parallel. I see that our answers have a lot in common, just like yours with Sombrero Chicken. If you think, I should modify my answer to improve the gain the future user will have from reading this, then let me know. In any case, if you think yours should be accepted instead, then no problem, your answer is very good :) Also let's clean these up later, for the sake of the future user please.
– gsamaras
yesterday
@Davislor that's not the case, but since all answer have a common backbone and people might think of that, I will partition the commonalities to the one that posted first a relevant section. Hope that clears things up... (please don't forget to delete your comment later, since it's clatter for future readers)
– gsamaras
yesterday
@Davislor that's not the case, but since all answer have a common backbone and people might think of that, I will partition the commonalities to the one that posted first a relevant section. Hope that clears things up... (please don't forget to delete your comment later, since it's clatter for future readers)
– gsamaras
yesterday
add a comment |
up vote
9
down vote
The new value will be available at some point at [cpp.predefined]p1.1:
__cplusplus
The integer literal
201703L
. [ Note: It is intended that future versions of this International Standard will replace the value of this macro with a greater value. — end note ]
The current values used in the major compilers are, as of 2018-11-30:
gcc:201709L
godbolt
clang:201707L
godbolt
msvc:201704L
godbolt (requires/Zc:__cplusplus
)
icc: unsupported godbolt (for the moment)
Since all of them are already higher than C++17's 201703L
, you can already use:
#if __cplusplus > 201703L
// C++20 code
#endif
add a comment |
up vote
9
down vote
The new value will be available at some point at [cpp.predefined]p1.1:
__cplusplus
The integer literal
201703L
. [ Note: It is intended that future versions of this International Standard will replace the value of this macro with a greater value. — end note ]
The current values used in the major compilers are, as of 2018-11-30:
gcc:201709L
godbolt
clang:201707L
godbolt
msvc:201704L
godbolt (requires/Zc:__cplusplus
)
icc: unsupported godbolt (for the moment)
Since all of them are already higher than C++17's 201703L
, you can already use:
#if __cplusplus > 201703L
// C++20 code
#endif
add a comment |
up vote
9
down vote
up vote
9
down vote
The new value will be available at some point at [cpp.predefined]p1.1:
__cplusplus
The integer literal
201703L
. [ Note: It is intended that future versions of this International Standard will replace the value of this macro with a greater value. — end note ]
The current values used in the major compilers are, as of 2018-11-30:
gcc:201709L
godbolt
clang:201707L
godbolt
msvc:201704L
godbolt (requires/Zc:__cplusplus
)
icc: unsupported godbolt (for the moment)
Since all of them are already higher than C++17's 201703L
, you can already use:
#if __cplusplus > 201703L
// C++20 code
#endif
The new value will be available at some point at [cpp.predefined]p1.1:
__cplusplus
The integer literal
201703L
. [ Note: It is intended that future versions of this International Standard will replace the value of this macro with a greater value. — end note ]
The current values used in the major compilers are, as of 2018-11-30:
gcc:201709L
godbolt
clang:201707L
godbolt
msvc:201704L
godbolt (requires/Zc:__cplusplus
)
icc: unsupported godbolt (for the moment)
Since all of them are already higher than C++17's 201703L
, you can already use:
#if __cplusplus > 201703L
// C++20 code
#endif
edited yesterday
answered yesterday
Acorn
4,79711135
4,79711135
add a comment |
add a comment |
up vote
5
down vote
There's no known __cplusplus
version yet because C++20 is still in development. There are only drafts for C++20.
The latest draft N4788 still contains:
__cplusplus
The integer literal
201703L
. [Note: It is intended that future versions of this International Standard will replace the value
of this macro with a greater value. —end note]
As for checking it, I would use @gsamaras answer.
@gsamaras just because you asked nicely
– Sombrero Chicken
yesterday
add a comment |
up vote
5
down vote
There's no known __cplusplus
version yet because C++20 is still in development. There are only drafts for C++20.
The latest draft N4788 still contains:
__cplusplus
The integer literal
201703L
. [Note: It is intended that future versions of this International Standard will replace the value
of this macro with a greater value. —end note]
As for checking it, I would use @gsamaras answer.
@gsamaras just because you asked nicely
– Sombrero Chicken
yesterday
add a comment |
up vote
5
down vote
up vote
5
down vote
There's no known __cplusplus
version yet because C++20 is still in development. There are only drafts for C++20.
The latest draft N4788 still contains:
__cplusplus
The integer literal
201703L
. [Note: It is intended that future versions of this International Standard will replace the value
of this macro with a greater value. —end note]
As for checking it, I would use @gsamaras answer.
There's no known __cplusplus
version yet because C++20 is still in development. There are only drafts for C++20.
The latest draft N4788 still contains:
__cplusplus
The integer literal
201703L
. [Note: It is intended that future versions of this International Standard will replace the value
of this macro with a greater value. —end note]
As for checking it, I would use @gsamaras answer.
edited yesterday
gsamaras
48.6k2396178
48.6k2396178
answered yesterday
Sombrero Chicken
22.7k32873
22.7k32873
@gsamaras just because you asked nicely
– Sombrero Chicken
yesterday
add a comment |
@gsamaras just because you asked nicely
– Sombrero Chicken
yesterday
@gsamaras just because you asked nicely
– Sombrero Chicken
yesterday
@gsamaras just because you asked nicely
– Sombrero Chicken
yesterday
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53557649%2fhow-do-i-check-for-c20-support-what-is-the-value-of-cplusplus-for-c20%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
4
Test for greater than 2017 does not work?
– Antoine Morrier
yesterday
2
@AntoineMorrier Of course! Why didn't I think of that? Whatever the value for C++20 will be will be larger than the one for 17.
– user2296653
yesterday
5
In most cases, prefer to test the features you require, rather than the language version.
– Toby Speight
yesterday