C++ループ可変テンプレートパラメータiterate variadic template arguments
895 ワード
template
inline typename std::enable_if_t for_each(std::tuple&, FuncT)
{
}
template
inline typename std::enable_if_t for_each(std::tuple& t, FuncT f)
{
f(std::get(t));
for_each(t, f);
}
template
auto print(Args ...args)
{
auto a = std::forward_as_tuple(args...);
for_each(a, [](auto x)
{
std::cout << typeid(x).name() << ":" << x << std::endl;
});
}
int main()
{
print(10, 'c', "bbb", string("123"));
}
結果は次のとおりです.
int:10
char:c
char const *:bbb
class std::basic_string, class std::allocator >:123