Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::get(std::array)

      From cppreference.com
      <cpp‎ |container‎ |array
       
       
       
       
      Defined in header<array>
      template<std::size_t I,class T,std::size_t N>
      T& get(std::array<T,N>& a)noexcept;
      (1)(since C++11)
      (constexpr since C++14)
      template<std::size_t I,class T,std::size_t N>
      T&& get(std::array<T,N>&& a)noexcept;
      (2)(since C++11)
      (constexpr since C++14)
      template<std::size_t I,class T,std::size_t N>
      const T& get(conststd::array<T,N>& a)noexcept;
      (3)(since C++11)
      (constexpr since C++14)
      template<std::size_t I,class T,std::size_t N>
      const T&& get(conststd::array<T,N>&& a)noexcept;
      (4)(since C++11)
      (constexpr since C++14)

      Extracts theIth element from the array usingtuple-like interface.

      I must be an integer value in range[0N). This is enforced at compile time as opposed toat() oroperator[].

      Contents

      [edit]Parameters

      a - array whose contents to extract

      [edit]Return value

      A reference to theIth element ofa.

      [edit]Complexity

      Constant.

      [edit]Example

      Run this code
      #include <array>#include <iostream> constexprstd::array v{1,2,3};static_assert(get<0>(v)==1&& get<1>(v)==2&& get<2>(v)==3); int main(){std::array<int,3> a; // set values:    get<0>(a)=1, get<1>(a)=2, get<2>(a)=3; // get values:std::cout<<'('<< get<0>(a)<<','<< get<1>(a)<<','<< get<2>(a)<<")\n";}

      Output:

      (1,2,3)

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 2485C++11there are no overloads for const array&&the overloads are added

      [edit]See also

      Structured binding(C++17) binds the specified names to sub-objects or tuple elements of the initializer[edit]
      access specified element
      (public member function)[edit]
      access specified element with bounds checking
      (public member function)[edit]
      tuple accesses specified element
      (function template)[edit]
      accesses an element of apair
      (function template)[edit]
      reads the value of the variant given the index or the type (if the type is unique), throws on error
      (function template)[edit]
      obtains iterator or sentinel from astd::ranges::subrange
      (function template)[edit]
      obtains a reference to real or imaginary part from astd::complex
      (function template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/container/array/get&oldid=175376"

      [8]ページ先頭

      ©2009-2025 Movatter.jp