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











up vote
19
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
    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















up vote
19
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
    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













up vote
19
down vote

favorite
1









up vote
19
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 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














  • 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












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.






share|improve this answer



















  • 3




    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










  • 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




















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
      yesterday











    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
    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.






    share|improve this answer



















    • 3




      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










    • 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

















    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.






    share|improve this answer



















    • 3




      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










    • 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















    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.






    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 14 hours ago

























    answered yesterday









    gsamaras

    48.6k2396178




    48.6k2396178








    • 3




      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










    • 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




      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










    • 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














    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 yesterday

























        answered yesterday









        Acorn

        4,79711135




        4,79711135






















            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
              yesterday















            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
              yesterday













            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 yesterday









            gsamaras

            48.6k2396178




            48.6k2396178










            answered yesterday









            Sombrero Chicken

            22.7k32873




            22.7k32873












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




            @gsamaras just because you asked nicely
            – Sombrero Chicken
            yesterday


















            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

            Bressuire

            Cabo Verde

            Gyllenstierna