Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::get(std::complex)

      From cppreference.com
      <cpp‎ |numeric‎ |complex
       
       
       
       
      Defined in header<complex>
      template<std::size_t I>
      friendconstexpr T& get(std::complex<T>& x);
      (1)(since C++26)
      template<std::size_t I>
      friendconstexprconst T& get(conststd::complex<T>& x);
      (2)(since C++26)
      template<std::size_t I>
      friendconstexpr T&& get(std::complex<T>&& x);
      (3)(since C++26)
      template<std::size_t I>
      friendconstexprconst T&& get(conststd::complex<T>&& x);
      (4)(since C++26)

      Returns the reference to real or imaginary part from acomplex whenI==0 orI==1, respectively. It is mainly provided for structured binding support.

      Contents

      [edit]Parameters

      x - acomplex

      [edit]Return value

      1-4) A reference to the real or imaginary part from the stored one whenI==0 orI==1, respectively.

      [edit]Notes

      Feature-test macroValueStdFeature
      __cpp_lib_tuple_like202311L(C++26)Add tuple protocol tostd::complex

      [edit]Example

      Run this code
      #include <complex> static_assert([z=std::complex(1.0,2.0)]{#if __cpp_lib_tuple_like >= 202311Lreturn std::get<0>(z)==1.0 and std::get<1>(z)==2.0;#elsereturn z.real()==1.0 and z.imag()==2.0;#endif}()); int main(){}

      [edit]See also

      Structured binding(C++17) binds the specified names to sub-objects or tuple elements of the initializer[edit]
      tuple accesses specified element
      (function template)[edit]
      accesses an element of apair
      (function template)[edit]
      accesses an element of anarray
      (function template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/numeric/complex/get&oldid=175381"

      [8]ページ先頭

      ©2009-2025 Movatter.jp