美文网首页
Array和Tuple转换

Array和Tuple转换

作者: Aska偶阵雨 | 来源:发表于2021-07-08 11:20 被阅读0次
    //#include <tuple>
    
    template <typename Array, std::size_t... N>
    decltype(auto) array2tuple_impl(const Array &a, std::index_sequence<N...>)
    {
        return std::make_tuple(a[N]...);
    }
    
    template <typename T, std::size_t N>
    decltype(auto) array2tuple(const std::array<T, N> &a)
    {
        return array2tuple_impl(a, std::make_index_sequence<N>{});
    }
    
    template <typename T, typename... U, unsigned... N>
    decltype(auto) tuple2array_impl(std::tuple<U...> &t, std::index_sequence<N...>)
    {
        return std::array<T, sizeof...(U)>{{std::get<N>(t)...}};
    }
    
    template <typename T, typename... U>
    decltype(auto) tuple2array(std::tuple<U...> t)
    {
        return tuple2array_impl<T>(t, std::make_index_sequence<sizeof...(U)>{});
    }

    相关文章

      网友评论

          本文标题:Array和Tuple转换

          本文链接:https://www.haomeiwen.com/subject/oonzultx.html