How do I check for C++20 support? What is the value of __cplusplus for C++20?
up vote
23
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
23
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
Nov 30 at 12:40
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
Nov 30 at 12:41
5
In most cases, prefer to test the features you require, rather than the language version.
– Toby Speight
Nov 30 at 14:32
add a comment |
up vote
23
down vote
favorite
up vote
23
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 2 days ago
gsamaras
49.2k2398179
49.2k2398179
asked Nov 30 at 12:30
user2296653
323111
323111
4
Test for greater than 2017 does not work?
– Antoine Morrier
Nov 30 at 12:40
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
Nov 30 at 12:41
5
In most cases, prefer to test the features you require, rather than the language version.
– Toby Speight
Nov 30 at 14:32
add a comment |
4
Test for greater than 2017 does not work?
– Antoine Morrier
Nov 30 at 12:40
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
Nov 30 at 12:41
5
In most cases, prefer to test the features you require, rather than the language version.
– Toby Speight
Nov 30 at 14:32
4
4
Test for greater than 2017 does not work?
– Antoine Morrier
Nov 30 at 12:40
Test for greater than 2017 does not work?
– Antoine Morrier
Nov 30 at 12:40
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
Nov 30 at 12:41
@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
Nov 30 at 12:41
5
5
In most cases, prefer to test the features you require, rather than the language version.
– Toby Speight
Nov 30 at 14:32
In most cases, prefer to test the features you require, rather than the language version.
– Toby Speight
Nov 30 at 14:32
add a comment |
3 Answers
3
active
oldest
votes
up vote
26
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
Nov 30 at 12:47
Same for GCC 9 and Clang 8 @bolov, updated my answer, thanks!
– gsamaras
Nov 30 at 12:56
It is not nice to copy other answers after you already have the accepted and top-voted answer :-)
– Acorn
Nov 30 at 17:29
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
Nov 30 at 18:49
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
Nov 30 at 12:53
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
26
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
Nov 30 at 12:47
Same for GCC 9 and Clang 8 @bolov, updated my answer, thanks!
– gsamaras
Nov 30 at 12:56
It is not nice to copy other answers after you already have the accepted and top-voted answer :-)
– Acorn
Nov 30 at 17:29
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
Nov 30 at 18:49
add a comment |
up vote
26
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
Nov 30 at 12:47
Same for GCC 9 and Clang 8 @bolov, updated my answer, thanks!
– gsamaras
Nov 30 at 12:56
It is not nice to copy other answers after you already have the accepted and top-voted answer :-)
– Acorn
Nov 30 at 17:29
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
Nov 30 at 18:49
add a comment |
up vote
26
down vote
accepted
up vote
26
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 Dec 1 at 16:26
answered Nov 30 at 12:43
gsamaras
49.2k2398179
49.2k2398179
3
gcc 8.2 uses201709
forc++2a
and clang 7.0 uses201707
– bolov
Nov 30 at 12:47
Same for GCC 9 and Clang 8 @bolov, updated my answer, thanks!
– gsamaras
Nov 30 at 12:56
It is not nice to copy other answers after you already have the accepted and top-voted answer :-)
– Acorn
Nov 30 at 17:29
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
Nov 30 at 18:49
add a comment |
3
gcc 8.2 uses201709
forc++2a
and clang 7.0 uses201707
– bolov
Nov 30 at 12:47
Same for GCC 9 and Clang 8 @bolov, updated my answer, thanks!
– gsamaras
Nov 30 at 12:56
It is not nice to copy other answers after you already have the accepted and top-voted answer :-)
– Acorn
Nov 30 at 17:29
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
Nov 30 at 18:49
3
3
gcc 8.2 uses
201709
for c++2a
and clang 7.0 uses 201707
– bolov
Nov 30 at 12:47
gcc 8.2 uses
201709
for c++2a
and clang 7.0 uses 201707
– bolov
Nov 30 at 12:47
Same for GCC 9 and Clang 8 @bolov, updated my answer, thanks!
– gsamaras
Nov 30 at 12:56
Same for GCC 9 and Clang 8 @bolov, updated my answer, thanks!
– gsamaras
Nov 30 at 12:56
It is not nice to copy other answers after you already have the accepted and top-voted answer :-)
– Acorn
Nov 30 at 17:29
It is not nice to copy other answers after you already have the accepted and top-voted answer :-)
– Acorn
Nov 30 at 17:29
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
Nov 30 at 18:49
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
Nov 30 at 18:49
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 Nov 30 at 13:04
answered Nov 30 at 12:48
Acorn
4,82711135
4,82711135
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
Nov 30 at 12:53
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
Nov 30 at 12:53
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 Nov 30 at 13:04
gsamaras
49.2k2398179
49.2k2398179
answered Nov 30 at 12:46
Sombrero Chicken
22.9k32975
22.9k32975
@gsamaras just because you asked nicely
– Sombrero Chicken
Nov 30 at 12:53
add a comment |
@gsamaras just because you asked nicely
– Sombrero Chicken
Nov 30 at 12:53
@gsamaras just because you asked nicely
– Sombrero Chicken
Nov 30 at 12:53
@gsamaras just because you asked nicely
– Sombrero Chicken
Nov 30 at 12:53
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
Nov 30 at 12:40
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
Nov 30 at 12:41
5
In most cases, prefer to test the features you require, rather than the language version.
– Toby Speight
Nov 30 at 14:32