How do I check for C++20 support? What is the value of __cplusplus for C++20?











up vote
20
down vote

favorite
1












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?










share|improve this question




















  • 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















up vote
20
down vote

favorite
1












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?










share|improve this question




















  • 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













up vote
20
down vote

favorite
1









up vote
20
down vote

favorite
1






1





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?










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 30 at 12:45









gsamaras

48.9k2397179




48.9k2397179










asked Nov 30 at 12:30









user2296653

308111




308111








  • 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




    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












3 Answers
3






active

oldest

votes

















up vote
25
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.






share|improve this answer



















  • 3




    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










  • 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


















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





share|improve this answer






























    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.






    share|improve this answer























    • @gsamaras just because you asked nicely
      – Sombrero Chicken
      Nov 30 at 12:53











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    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

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    25
    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.






    share|improve this answer



















    • 3




      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










    • 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















    up vote
    25
    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.






    share|improve this answer



















    • 3




      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










    • 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













    up vote
    25
    down vote



    accepted







    up vote
    25
    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.






    share|improve this answer














    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.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Dec 1 at 16:26

























    answered Nov 30 at 12:43









    gsamaras

    48.9k2397179




    48.9k2397179








    • 3




      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










    • 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




      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










    • 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












    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





    share|improve this answer



























      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





      share|improve this answer

























        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





        share|improve this answer














        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






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 30 at 13:04

























        answered Nov 30 at 12:48









        Acorn

        4,81711135




        4,81711135






















            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.






            share|improve this answer























            • @gsamaras just because you asked nicely
              – Sombrero Chicken
              Nov 30 at 12:53















            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.






            share|improve this answer























            • @gsamaras just because you asked nicely
              – Sombrero Chicken
              Nov 30 at 12:53













            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.






            share|improve this 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.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 30 at 13:04









            gsamaras

            48.9k2397179




            48.9k2397179










            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


















            • @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


















            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            サソリ

            広島県道265号伴広島線

            Accessing regular linux commands in Huawei's Dopra Linux