久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

獲取元組元素類型的索引?

Get index of a tuple element#39;s type?(獲取元組元素類型的索引?)
本文介紹了獲取元組元素類型的索引?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

如果我有一個具有不同元素類型的元組,例如

If I have a tuple with different element types like

std::tuple<T0, T1, T2, ...>

以及如何獲取元素類型的索引?

And how to get the index of a element type?

template<class T, class Tuple>
struct Index
{
    enum {value = ?;}
};

謝謝.

推薦答案

template <class T, class Tuple>
struct Index;

template <class T, class... Types>
struct Index<T, std::tuple<T, Types...>> {
    static const std::size_t value = 0;
};

template <class T, class U, class... Types>
struct Index<T, std::tuple<U, Types...>> {
    static const std::size_t value = 1 + Index<T, std::tuple<Types...>>::value;
};

在 Coli 現場觀看.

See it live at Coliru.

此實現返回給定類型第一次出現的索引.請求不在元組中的類型的索引會導致編譯錯誤(并且相當難看).

This implementation returns the index of the first occurrence of a given type. Asking for the index of a type that is not in the tuple results in a compile error (and a fairly ugly one at that).

這篇關于獲取元組元素類型的索引?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Difference between std::reference_wrapper and simple pointer?(std::reference_wrapper 和簡單指針的區別?)
Difference between const. pointer and reference?(常量之間的區別.指針和引用?)
How to access the contents of a vector from a pointer to the vector in C++?(c++ - 如何從指向向量的指針訪問向量的內容?)
Meaning of *amp; and **amp; in C++(*amp; 的含義和**amp;在 C++ 中)
Why can#39;t I do polymorphism with normal variables?(為什么我不能對普通變量進行多態?)
Dereferencing deleted pointers always result in an Access Violation?(取消引用已刪除的指針總是會導致訪問沖突?)
主站蜘蛛池模板: 久久久精品视频免费看 | 天天天插 | 精品国产99| 日韩欧美三区 | 日韩欧美网 | 玖操| 国产精品九九九 | 精品久久久久一区二区国产 | 81精品国产乱码久久久久久 | 国产丝袜一区二区三区免费视频 | 日韩中文字幕在线 | 久久精品a| 亚洲欧美日韩国产综合 | 一区二区三区视频在线 | 日韩精品一区二区三区在线观看 | 男女激情网站免费 | 亚洲精品久久久久久国产精华液 | 中文字幕精品视频 | 国产在线网站 | 欧美日韩网站 | 亚洲精品免费看 | 一区二区三区中文字幕 | 色www精品视频在线观看 | 久久久99国产精品免费 | 国产精品免费在线 | 欧美综合久久 | 国产精品久久久久无码av | 日韩一区二区在线观看视频 | 中文字幕一区二区三区四区五区 | 国产视频亚洲视频 | 中文字幕不卡视频在线观看 | wwwxxx日本在线观看 | 日韩欧美一二三区 | 精品一区二区三区在线播放 | 日韩欧美在线观看 | 亚洲精品一区二区三区四区高清 | 亚洲aⅴ一区二区 | 亚洲国产精品99久久久久久久久 | 成年人网站在线观看视频 | 久草在线中文888 | 亚洲国产精品一区在线观看 |