Created
July 19, 2018 09:32
-
-
Save JPenuchot/995fda1e9a0a762f854a1811dc928858 to your computer and use it in GitHub Desktop.
Example of C++ std::tuple pretty printer using parameter packs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <tuple> | |
#include <iostream> | |
int main() | |
{ | |
// Creates a tuple<float, int, std::string> object | |
auto tup = std::make_tuple(1.f, 10, "Hello !"); | |
// Apply the lambda with the members | |
// of the tuple as arguments | |
std::apply([](auto&... e) | |
{ | |
// Parameter pack expansion | |
( (std::cout << e << '\n') , ... ); | |
}, tup); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment