Skip to content

New Exercise Idea: Template parameter packs #501

Open
@JC-13

Description

@JC-13

With the new v3 concepts I though it would be good to focus more on C++ specific ideas which aren't currently covered in the exercises. Here's some example solution code for the exercise:

#include <iostream>
#include <sstream>

// Should be able to take in any length/ type of arguements
template <typename... Args> std::string concat(Args... args)
{
    std::stringstream output;
    ((output << std::forward<Args>(args) << ","), ...);
    return output.str();
}

int main() {
    std::cout << concat(123, "test") << std::endl;
    // Prints: "123, test,"
    return 0;
}

Wanted to run this by other people before I went and created a whole exercise around it.

Also FYI the "Please see the contributing guide" in the README is a broken link.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions