Skip to content

Instantly share code, notes, and snippets.

@elinx
Last active April 11, 2021 04:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elinx/e53fe7c05d7d6d77a665290d17cd4691 to your computer and use it in GitHub Desktop.
Save elinx/e53fe7c05d7d6d77a665290d17cd4691 to your computer and use it in GitHub Desktop.
traverse variadic template pramater pack in forward and backward mode
#include <vector>
#include <list>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <set>
#include <optional>
#include <tuple>
template <typename T>
class type_identity {
public:
using type = T;
};
template <typename... Ts>
void print(Ts... ts) {
auto _print = [] (auto t) {
std::cout << t << std::endl;
return type_identity<void>{};
};
(_print(ts) = ...);
(_print(ts) , ...);
}
int main()
{
print(1, 3.14, "abc");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment