C++17 Fold Expression not Compiling





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















first time posting so sorry if I have poor format. I encountered fold expressions for the first time the other day and am trying to get something up and running with them. However, all of my attempts have failed to compile. I've boiled it down to the following:



//test.cpp

template<typename... types>
auto adder(types&... args){
return (args+...);
}

int main(){return 0;}


And I compiled it with



g++ -std=c++17 test.cpp


And it produces the following errors:



testCode.cpp: In function 'auto adder(types& ...)':
testCode.cpp:5:15: error: expected primary-expression before '...' token
return (args+...);
^
testCode.cpp:5:15: error: expected ')' before '...' token
testCode.cpp:5:18: error: parameter packs not expanded with '...':
return (args+...);
^
testCode.cpp:5:18: note: 'args'


From everything I've seen this should be working, so if someone can tell me what I'm doing wrong I would greatly appreciate it.



I'm working with xenial linux (on a crouton on chrome OS) and a fresh install of g++.










share|improve this question

























  • Which version of g++ are you using? This should work with current versions of all major compilers (try for yourself here). In the case of g++, it seems to work starting with version 6.1, which is already pretty old (latest version is 8.2). I guess you must be using a really ancient version…

    – Michael Kenzel
    Nov 16 '18 at 23:23













  • I think that you edited this code sample. I was trying it out for myself and it broke until I fixed it. And now your code sample works just fine. What did you do?

    – Zan Lynx
    Nov 16 '18 at 23:28











  • Certainly works with GCC 8.1.0. crouron on a chromebook is perhaps not the best C++ development environment - much as I like chromebooks.

    – Neil Butterworth
    Nov 16 '18 at 23:36













  • Hello all, as Kenzel suspected, this was a versioning issue with the g++ compiler. Not sure what my computer was default installing, but a newer version does fix the problem.

    – Bronicki
    Nov 17 '18 at 16:45


















0















first time posting so sorry if I have poor format. I encountered fold expressions for the first time the other day and am trying to get something up and running with them. However, all of my attempts have failed to compile. I've boiled it down to the following:



//test.cpp

template<typename... types>
auto adder(types&... args){
return (args+...);
}

int main(){return 0;}


And I compiled it with



g++ -std=c++17 test.cpp


And it produces the following errors:



testCode.cpp: In function 'auto adder(types& ...)':
testCode.cpp:5:15: error: expected primary-expression before '...' token
return (args+...);
^
testCode.cpp:5:15: error: expected ')' before '...' token
testCode.cpp:5:18: error: parameter packs not expanded with '...':
return (args+...);
^
testCode.cpp:5:18: note: 'args'


From everything I've seen this should be working, so if someone can tell me what I'm doing wrong I would greatly appreciate it.



I'm working with xenial linux (on a crouton on chrome OS) and a fresh install of g++.










share|improve this question

























  • Which version of g++ are you using? This should work with current versions of all major compilers (try for yourself here). In the case of g++, it seems to work starting with version 6.1, which is already pretty old (latest version is 8.2). I guess you must be using a really ancient version…

    – Michael Kenzel
    Nov 16 '18 at 23:23













  • I think that you edited this code sample. I was trying it out for myself and it broke until I fixed it. And now your code sample works just fine. What did you do?

    – Zan Lynx
    Nov 16 '18 at 23:28











  • Certainly works with GCC 8.1.0. crouron on a chromebook is perhaps not the best C++ development environment - much as I like chromebooks.

    – Neil Butterworth
    Nov 16 '18 at 23:36













  • Hello all, as Kenzel suspected, this was a versioning issue with the g++ compiler. Not sure what my computer was default installing, but a newer version does fix the problem.

    – Bronicki
    Nov 17 '18 at 16:45














0












0








0








first time posting so sorry if I have poor format. I encountered fold expressions for the first time the other day and am trying to get something up and running with them. However, all of my attempts have failed to compile. I've boiled it down to the following:



//test.cpp

template<typename... types>
auto adder(types&... args){
return (args+...);
}

int main(){return 0;}


And I compiled it with



g++ -std=c++17 test.cpp


And it produces the following errors:



testCode.cpp: In function 'auto adder(types& ...)':
testCode.cpp:5:15: error: expected primary-expression before '...' token
return (args+...);
^
testCode.cpp:5:15: error: expected ')' before '...' token
testCode.cpp:5:18: error: parameter packs not expanded with '...':
return (args+...);
^
testCode.cpp:5:18: note: 'args'


From everything I've seen this should be working, so if someone can tell me what I'm doing wrong I would greatly appreciate it.



I'm working with xenial linux (on a crouton on chrome OS) and a fresh install of g++.










share|improve this question
















first time posting so sorry if I have poor format. I encountered fold expressions for the first time the other day and am trying to get something up and running with them. However, all of my attempts have failed to compile. I've boiled it down to the following:



//test.cpp

template<typename... types>
auto adder(types&... args){
return (args+...);
}

int main(){return 0;}


And I compiled it with



g++ -std=c++17 test.cpp


And it produces the following errors:



testCode.cpp: In function 'auto adder(types& ...)':
testCode.cpp:5:15: error: expected primary-expression before '...' token
return (args+...);
^
testCode.cpp:5:15: error: expected ')' before '...' token
testCode.cpp:5:18: error: parameter packs not expanded with '...':
return (args+...);
^
testCode.cpp:5:18: note: 'args'


From everything I've seen this should be working, so if someone can tell me what I'm doing wrong I would greatly appreciate it.



I'm working with xenial linux (on a crouton on chrome OS) and a fresh install of g++.







c++ c++17






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 23:19









Nicol Bolas

293k34483660




293k34483660










asked Nov 16 '18 at 23:11









BronickiBronicki

261




261













  • Which version of g++ are you using? This should work with current versions of all major compilers (try for yourself here). In the case of g++, it seems to work starting with version 6.1, which is already pretty old (latest version is 8.2). I guess you must be using a really ancient version…

    – Michael Kenzel
    Nov 16 '18 at 23:23













  • I think that you edited this code sample. I was trying it out for myself and it broke until I fixed it. And now your code sample works just fine. What did you do?

    – Zan Lynx
    Nov 16 '18 at 23:28











  • Certainly works with GCC 8.1.0. crouron on a chromebook is perhaps not the best C++ development environment - much as I like chromebooks.

    – Neil Butterworth
    Nov 16 '18 at 23:36













  • Hello all, as Kenzel suspected, this was a versioning issue with the g++ compiler. Not sure what my computer was default installing, but a newer version does fix the problem.

    – Bronicki
    Nov 17 '18 at 16:45



















  • Which version of g++ are you using? This should work with current versions of all major compilers (try for yourself here). In the case of g++, it seems to work starting with version 6.1, which is already pretty old (latest version is 8.2). I guess you must be using a really ancient version…

    – Michael Kenzel
    Nov 16 '18 at 23:23













  • I think that you edited this code sample. I was trying it out for myself and it broke until I fixed it. And now your code sample works just fine. What did you do?

    – Zan Lynx
    Nov 16 '18 at 23:28











  • Certainly works with GCC 8.1.0. crouron on a chromebook is perhaps not the best C++ development environment - much as I like chromebooks.

    – Neil Butterworth
    Nov 16 '18 at 23:36













  • Hello all, as Kenzel suspected, this was a versioning issue with the g++ compiler. Not sure what my computer was default installing, but a newer version does fix the problem.

    – Bronicki
    Nov 17 '18 at 16:45

















Which version of g++ are you using? This should work with current versions of all major compilers (try for yourself here). In the case of g++, it seems to work starting with version 6.1, which is already pretty old (latest version is 8.2). I guess you must be using a really ancient version…

– Michael Kenzel
Nov 16 '18 at 23:23







Which version of g++ are you using? This should work with current versions of all major compilers (try for yourself here). In the case of g++, it seems to work starting with version 6.1, which is already pretty old (latest version is 8.2). I guess you must be using a really ancient version…

– Michael Kenzel
Nov 16 '18 at 23:23















I think that you edited this code sample. I was trying it out for myself and it broke until I fixed it. And now your code sample works just fine. What did you do?

– Zan Lynx
Nov 16 '18 at 23:28





I think that you edited this code sample. I was trying it out for myself and it broke until I fixed it. And now your code sample works just fine. What did you do?

– Zan Lynx
Nov 16 '18 at 23:28













Certainly works with GCC 8.1.0. crouron on a chromebook is perhaps not the best C++ development environment - much as I like chromebooks.

– Neil Butterworth
Nov 16 '18 at 23:36







Certainly works with GCC 8.1.0. crouron on a chromebook is perhaps not the best C++ development environment - much as I like chromebooks.

– Neil Butterworth
Nov 16 '18 at 23:36















Hello all, as Kenzel suspected, this was a versioning issue with the g++ compiler. Not sure what my computer was default installing, but a newer version does fix the problem.

– Bronicki
Nov 17 '18 at 16:45





Hello all, as Kenzel suspected, this was a versioning issue with the g++ compiler. Not sure what my computer was default installing, but a newer version does fix the problem.

– Bronicki
Nov 17 '18 at 16:45












2 Answers
2






active

oldest

votes


















0














Maybe like this?



#include <string>
#include <iostream>

using namespace std::literals;

template<typename... T>
auto add(const T&... args) {
return (args + ...);
}

int main() {
std::cout << add(1,2,3,4) << "n";
std::cout << add("a"s, "b"s, "c"s) << "n";
return 0;
}





share|improve this answer
























  • This doesn't really answer why the OP's code doesn't work.

    – NathanOliver
    Nov 16 '18 at 23:42











  • @NathanOliver I suspect the asker edited his question because I copied it, and saw the error. And now I don't. So ... ¯_(ツ)_/¯

    – Zan Lynx
    Nov 17 '18 at 0:50





















0














as Kenzel suspected in the comments, this was a versioning issue with the g++ compiler. Not sure what my computer was installing by default, but going to a linux repository and manually installing a newer version of g++ fixed the issue. Thanks for the help everyone!






share|improve this answer
























    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',
    autoActivateHeartbeat: false,
    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%2f53346564%2fc17-fold-expression-not-compiling%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Maybe like this?



    #include <string>
    #include <iostream>

    using namespace std::literals;

    template<typename... T>
    auto add(const T&... args) {
    return (args + ...);
    }

    int main() {
    std::cout << add(1,2,3,4) << "n";
    std::cout << add("a"s, "b"s, "c"s) << "n";
    return 0;
    }





    share|improve this answer
























    • This doesn't really answer why the OP's code doesn't work.

      – NathanOliver
      Nov 16 '18 at 23:42











    • @NathanOliver I suspect the asker edited his question because I copied it, and saw the error. And now I don't. So ... ¯_(ツ)_/¯

      – Zan Lynx
      Nov 17 '18 at 0:50


















    0














    Maybe like this?



    #include <string>
    #include <iostream>

    using namespace std::literals;

    template<typename... T>
    auto add(const T&... args) {
    return (args + ...);
    }

    int main() {
    std::cout << add(1,2,3,4) << "n";
    std::cout << add("a"s, "b"s, "c"s) << "n";
    return 0;
    }





    share|improve this answer
























    • This doesn't really answer why the OP's code doesn't work.

      – NathanOliver
      Nov 16 '18 at 23:42











    • @NathanOliver I suspect the asker edited his question because I copied it, and saw the error. And now I don't. So ... ¯_(ツ)_/¯

      – Zan Lynx
      Nov 17 '18 at 0:50
















    0












    0








    0







    Maybe like this?



    #include <string>
    #include <iostream>

    using namespace std::literals;

    template<typename... T>
    auto add(const T&... args) {
    return (args + ...);
    }

    int main() {
    std::cout << add(1,2,3,4) << "n";
    std::cout << add("a"s, "b"s, "c"s) << "n";
    return 0;
    }





    share|improve this answer













    Maybe like this?



    #include <string>
    #include <iostream>

    using namespace std::literals;

    template<typename... T>
    auto add(const T&... args) {
    return (args + ...);
    }

    int main() {
    std::cout << add(1,2,3,4) << "n";
    std::cout << add("a"s, "b"s, "c"s) << "n";
    return 0;
    }






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 16 '18 at 23:22









    Zan LynxZan Lynx

    41.4k663110




    41.4k663110













    • This doesn't really answer why the OP's code doesn't work.

      – NathanOliver
      Nov 16 '18 at 23:42











    • @NathanOliver I suspect the asker edited his question because I copied it, and saw the error. And now I don't. So ... ¯_(ツ)_/¯

      – Zan Lynx
      Nov 17 '18 at 0:50





















    • This doesn't really answer why the OP's code doesn't work.

      – NathanOliver
      Nov 16 '18 at 23:42











    • @NathanOliver I suspect the asker edited his question because I copied it, and saw the error. And now I don't. So ... ¯_(ツ)_/¯

      – Zan Lynx
      Nov 17 '18 at 0:50



















    This doesn't really answer why the OP's code doesn't work.

    – NathanOliver
    Nov 16 '18 at 23:42





    This doesn't really answer why the OP's code doesn't work.

    – NathanOliver
    Nov 16 '18 at 23:42













    @NathanOliver I suspect the asker edited his question because I copied it, and saw the error. And now I don't. So ... ¯_(ツ)_/¯

    – Zan Lynx
    Nov 17 '18 at 0:50







    @NathanOliver I suspect the asker edited his question because I copied it, and saw the error. And now I don't. So ... ¯_(ツ)_/¯

    – Zan Lynx
    Nov 17 '18 at 0:50















    0














    as Kenzel suspected in the comments, this was a versioning issue with the g++ compiler. Not sure what my computer was installing by default, but going to a linux repository and manually installing a newer version of g++ fixed the issue. Thanks for the help everyone!






    share|improve this answer




























      0














      as Kenzel suspected in the comments, this was a versioning issue with the g++ compiler. Not sure what my computer was installing by default, but going to a linux repository and manually installing a newer version of g++ fixed the issue. Thanks for the help everyone!






      share|improve this answer


























        0












        0








        0







        as Kenzel suspected in the comments, this was a versioning issue with the g++ compiler. Not sure what my computer was installing by default, but going to a linux repository and manually installing a newer version of g++ fixed the issue. Thanks for the help everyone!






        share|improve this answer













        as Kenzel suspected in the comments, this was a versioning issue with the g++ compiler. Not sure what my computer was installing by default, but going to a linux repository and manually installing a newer version of g++ fixed the issue. Thanks for the help everyone!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 17 '18 at 16:51









        BronickiBronicki

        261




        261






























            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53346564%2fc17-fold-expression-not-compiling%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

            Vorschmack

            Quarantine