std::litera...perator""il(3)
std::litera...perator""il(3) π
β¨
okay bestie, welcome to the C++ Standard Libary manual β yes, thatβs the manual name, typo and all, we donβt make the rules π. this page is all about std::litera...perator""il(3) and its little imaginary-number-literal crew. no cap, itβs giving niche but iconic π¦.
π NAME π
std::literals::complex_literals::operator""i,operator""if,operator""il - std::literals::complex_literals::operator""i,operator""if,operator""il
πΈ Synopsis πΈ
Defined in header <complex>
here are the literal operator forms, exactly as written:
- (1) (since C++14)
constexpr complex<double> operator""i( long double arg );constexpr complex<double> operator""i( unsigned long long arg );
- (2) (since C++14)
constexpr complex<float> operator""if( long double arg );constexpr complex<float> operator""if( unsigned long long arg );
- (3) (since C++14)
constexpr complex<long double> operator""il( long double arg );constexpr complex<long double> operator""il( unsigned long long arg );
Forms a std::complex literal representing an imaginary number. literally the whole vibe π.
- Forms a literal
std::complex<double>with the real part zero and imaginary part arg. - Forms a literal
std::complex<float>with the real part zero and imaginary part arg. - Forms a literal
std::complex<long double>with the real part zero and imaginary part arg.
π Parameters π
- arg β the value of the imaginary number
π¦ Return value π¦
The std::complex literal with the real part zero and imaginary part arg. thatβs it, thatβs the whole return π.
β¨ Notes β¨
These operators are declared in the namespace std::literals::complex_literals, where both literals and complex_literals are inline namespaces. Access to these operators can be gained with either:
using namespace std::literals,using namespace std::complex_literals, orusing namespace std::literals::complex_literals.
Even though if is a keyword in C++, it is a ud-suffix of the literal operator of the form operator ""if and in the literal expressions such as 1if or 1.0if because it is not separated by whitespace and is not a standalone token. the way that works is lowkey iconic, periodt π
.
Feature-test macro:
__cpp_lib_complex_udlsβ value201309L; std(C++14); feature: User-Defined Literals forstd::complex
π§ Possible implementation π§
hereβs the reference implementation, copied exactly:
operator""i
constexpr std::complex<double> operator""i(unsigned long long d)
{
return std::complex<double> {0.0, static_cast<double>(d)};
}
constexpr std::complex<double> operator""i(long double d)
{
return std::complex<double> {0.0, static_cast<double>(d)};
}
operator""if
constexpr std::complex<float> operator""if(unsigned long long d)
{
return std::complex<float> {0.0f, static_cast<float>(d)};
}
constexpr std::complex<float> operator""if(long double d)
{
return std::complex<float> {0.0f, static_cast<float>(d)};
}
operator""il
constexpr std::complex<long double> operator""il(unsigned long long d)
{
return std::complex<long double> {0.0L, static_cast<long double>(d)};
}
constexpr std::complex<long double> operator""il(long double d)
{
return std::complex<long double> {0.0L, d};
}
π Example π
// Run this code
#include <complex>
#include <iostream>
int main()
{
using namespace std::complex_literals;
std::complex<double> c = 1.0 + 1i;
std::cout << "abs" << c << " = " << std::abs(c) << '\n';
std::complex<float> z = 3.0f + 4.0if;
std::cout << "abs" << z << " = " << std::abs(z) << '\n';
}
Output:
abs(1,1) = 1.41421
abs(3,4) = 5
π See also π
constructorβ constructs a complex number (public member function)operator=β assigns the contents (public member function)- C documentation for
I
okay bestie, thatβs the whole page π source/version: http://cppreference.com Β· date: 2024.06.10 Β· page: std::litera...perator""il(3) β¨π«Ά
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms