std::complex<T>::real

Accesses the real part of the complex number.

# Declarations

primary template std::complex<T>
T real() const;

(until C++14)

constexpr T real() const;

(since C++14)

void real( T value );

(until C++20)

constexpr void real( T value );

(since C++20)

specialization std::complex<float>
float real() const;

(until C++11)

constexpr float real() const;

(since C++11)

void real( float value );

(until C++20)

constexpr void real( float value );

(since C++20)

specialization std::complex<double>
double real() const;

(until C++11)

constexpr double real() const;

(since C++11)

void real( double value );

(until C++20)

constexpr void real( double value );

(since C++20)

specialization std::complex<long double>
long double real() const;

(until C++11)

constexpr long double real() const;

(since C++11)

void real( long double value );

(until C++20)

constexpr void real( long double value );

(since C++20)

# Parameters

# Notes

In C++11, overload (1) in std::complex specializations used to be specified without const qualifier. However, in C++11, a constexpr specifier used in a non-static member function implies const, and thus the behavior is as if const is specified.

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 387C++98the real part could not be set directlycan be set directly via a new real overload

# See also