In the following code:
#include <iostream>
#include <utility>
#include <vector>
#include <set>
template <typename... Args>
void f(Args... args) {
std::cout << sizeof...(Args) << " elements.\n";
const std::vector<int> v = {(int)args...};
for (int x : v) std::cout << x << ' '; std::cout << '\n';
}
template <std::size_t... Is>
void fhelper (std::index_sequence<Is...>, const std::set<int>& set) {
f((set.find(Is) == set.end() ? Is : 2*Is)...);
}
int main() {
fhelper (std::make_index_sequence<10>{}, {1,3,7,8});
}
I want f((set.find(Is) == set.end() ? Is : 2*Is)...);
to use Is
if set.find(Is) == set.end()
but NOTHING otherwise (instead of 2*Is
. Thus the number of arguments passes is not fixed. How to achieve that?
Aucun commentaire:
Enregistrer un commentaire