How to access n-th value of an integer_sequence? [duplicate]

独自空忆成欢 提交于 2019-12-05 18:03:04

There is no such built-in method as far as I'm aware but you can implement it itself in a few neat lines without any iterations:

template<class T, T... Ints>
constexpr T get(std::integer_sequence<T, Ints...>, std::size_t i) {
    constexpr T arr[] = {Ints...};
    return arr[i];
}

See how it works here: https://godbolt.org/z/yAfMeg

Arguments can be lifted into template parameters (to match your example) with a bit more code.

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