std::get(std::complex)
来自 cppreference.cn
定义于头文件 <complex> |
||
template< std::size_t I > friend constexpr T& get( std::complex<T>& x ); |
(1) | (C++26 起) |
template< std::size_t I > friend constexpr const T& get( const std::complex<T>& x ); |
(2) | (C++26 起) |
template< std::size_t I > friend constexpr T&& get( std::complex<T>&& x ); |
(3) | (C++26 起) |
template< std::size_t I > friend constexpr const T&& get( const std::complex<T>&& x ); |
(4) | (C++26 起) |
当 I == 0 或 I == 1 时,分别返回 `complex` 的实部或虚部的引用。它主要用于结构化绑定支持。
目录 |
[编辑] 参数
x | - | 一个 `complex` 对象 |
[编辑] 返回值
1-4) 当 I == 0 或 I == 1 时,分别返回存储的实部或虚部的引用。
[编辑] 注意
特性测试宏 | 值 | 标准 | 特性 |
---|---|---|---|
__cpp_lib_tuple_like |
202311L |
(C++26) | 将元组协议添加到std::complex |
[编辑] 示例
运行此代码
#include <complex> static_assert([z = std::complex(1.0, 2.0)] { #if __cpp_lib_tuple_like >= 202311L return std::get<0>(z) == 1.0 and std::get<1>(z) == 2.0; #else return z.real() == 1.0 and z.imag() == 2.0; #endif }()); int main() {}
[编辑] 参阅
结构化绑定 (C++17) | 将指定名称绑定到初始化器的子对象或元组元素 |
(C++11) |
tuple 访问指定的元素 (函数模板) |
(C++11) |
访问 pair 的元素(函数模板) |
(C++11) |
访问 array 的一个元素(函数模板) |