std::tuple_sizestd::complex - cppreference.com (original) (raw)

The partial specialization of std::tuple_size for std::complex provides a compile-time way to obtain the number of components of a complex, which is always 2, using tuple-like syntax. It is provided for structured binding support.

[edit] Notes

Feature-test macro Value Std Feature
__cpp_lib_tuple_like 202311L (C++26) Add tuple protocol to std::complex

[edit] Example

#include   static_assert(std::tuple_size_v<std::complex> == 2);   static_assert([] { using namespace std::literals; auto [re, im] = -1.5 + 2.5i; return re == -1.5 && im == 2.5; }());   static_assert([] { using namespace std::literals; auto z = std::complex{}; auto& [re, im] = z; re = 1.0; im = 2.0; return z == 1.0 + 2.0i; }());   int main() {}

[edit] See also