std::tuple_element<std::array>
Von cppreference.com
| Definiert in der Header-Datei <array> |
||
| template< std::size_t I, class T, std::size_t N > struct tuple_element< I, std::array<T, N> >; |
(seit C++11) | |
Bietet zur Kompilierzeit einen indizierten Zugriff auf den Typ der Elemente des Arrays über eine Tupel-ähnliche Schnittstelle.
Inhalt |
[bearbeiten] Member types
| Mitgliedertyp | Definition |
| type | der Typ der Elemente des Arrays |
[bearbeiten] Mögliche Implementierung
template<std::size_t I, class T> struct tuple_element; template<std::size_t I, class T, std::size_t N> struct tuple_element<I, std::array<T,N>> { using type = T; }; |
[bearbeiten] Beispiel
Führen Sie diesen Code aus
#include <array> #include <tuple> #include <type_traits> int main() { // define array and get the type of the element at position 0 std::array<int, 10> data{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; using T = std::tuple_element<0, decltype(data)>::type; // int static_assert(std::is_same_v<T, int>); const auto const_data = data; using CT = std::tuple_element<0, decltype(const_data)>::type; // const int // the result of tuple_element depends on the cv-qualification of the tuple-like type static_assert(!std::is_same_v<T, CT>); static_assert(std::is_same_v<CT, const int>); }
[bearbeiten] Siehe auch
| Strukturierte Bindung (C++17) | bindet die angegebenen Namen an Unterobjekte oder Tuple-Elemente des Initialisierers |
| ermittelt den Typ des spezifizierten Elements (class template specialization) | |
ermittelt den Typ der Elemente von pair(Klassenvorlagenspezialisierung) |