Last active
April 11, 2021 04:38
-
-
Save elinx/e53fe7c05d7d6d77a665290d17cd4691 to your computer and use it in GitHub Desktop.
traverse variadic template pramater pack in forward and backward mode
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 <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