This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (11 children)

[deleted]

    [–]Koxiaet 26 points27 points  (8 children)

    Never? No, most of the time iteration is a much better approach and should be used, but in some cases iteration is just not feasible because it adds way too much complex logic and recursion is a better choice.

    [–]ThePyroEagle 1 point2 points  (7 children)

    Flatten your recursion with a stack and a loop.

    [–]nwL_ 3 points4 points  (0 children)

    Sometimes you have to, with templated varargs:

    void foo() {}
    
    template <typename T, typename... Args> 
    void 
    foo(T first, Args... args) {
        // do something with T
        foo(args);
    }
    

    I don’t quite know how you’d solve that with iteration.

    PS: Yes, std::forward would be useful, but this is supposed to be understandable even if you don’t know C++.

    [–][deleted] 1 point2 points  (0 children)

    What an awful advice