This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Why do gcc's std::real() and std::imag() return references?
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Randalph Phelps <senland at yahoo dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 20 Jun 2011 19:08:43 +0100
- Subject: Re: Why do gcc's std::real() and std::imag() return references?
- References: <100796.26253.qm@web161617.mail.bf1.yahoo.com>
On 17 June 2011 01:27, Randalph Phelps wrote:
> Hi all,
>
> I have noticed that gcc's std::real() and std::imag() return a reference, unless
> "-std=c++0x" is specified. The C++98 standard specifies in section 26.2.7 that
> these two functions have the following prototypes:
>
> template<class T> T real(const complex<T>&);
> template<class T> T imag(const complex<T>&);
>
> In gcc 4.4, for example, it is:
> template<typename _Tp> _Tp& real(complex<_Tp>& __z)
>
> Is there a reason for this deviation from the standard? This breaks for any
> specializations of std::complex that return a value for real() and imag().
I would guess the reason was an attempt to address the problem
discussed in DR 387: that there is no way to set the individual real
and imaginary parts of a complex<T> in C++98.
Someone has now opened a bugzilla report about it and I added some
relevant links in a comment there, see
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49476