C++ Convert a parameter pack of types to parameter pack of indices

戏子无情 提交于 2019-12-04 09:38:55

In C++14 you can use std::index_sequence_for from the <utility> header along with tagged dispatch. This is known as the indices trick:

template <std::size_t... I>
void bar(std::index_sequence<I...>);

template <typename... Types>
void foo() {
    bar(std::index_sequence_for<Types...>{});
}

If you are limited to C++11, you can find many implementations of the above online, such as this one.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!