This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Q. about GDR's addition of complex-accessor overloads.
- From: Jan van Dijk <jan at etpmod dot phys dot tue dot nl>
- To: libstdc++ at gcc dot gnu dot org
- Date: Thu, 10 Nov 2005 08:35:37 +0100
- Subject: Q. about GDR's addition of complex-accessor overloads.
- Reply-to: jan at etpmod dot phys dot tue dot nl
L.S,
With patch http://gcc.gnu.org/ml/gcc-patches/2004-01/msg00866.html Gabriel Dos
Reis changed the real() and imag() members of std::complex<T>. These were
changed to return const references, while non-const overloads were added to
return unqualified references.
This causes problem with the following (reduced) program:
#include <complex>
#include <functional>
typedef std::complex<double> complex;
void foo()
{
std::mem_fun_ref(&complex::real);
}
which gives me, with today's trunk:
./cmplx_acc_overload.cpp: In function âvoid foo()â:
./cmplx_acc_overload.cpp:10: error: call of overloaded
âmem_fun_ref(<unresolved overloaded function type>)â is ambiguous
/home/jan/local/gcc-head/lib/gcc/i686-pc-linux-gnu/4.1.0/../../../../include/c++/4.1.0/bits/stl_function.h:723:
note: candidates are: std::mem_fun_ref_t<_Ret, _Tp> std::mem_fun_ref(_Ret
(_Tp::*)()) [with _Ret = double&, _Tp = std::complex<double>]
/home/jan/local/gcc-head/lib/gcc/i686-pc-linux-gnu/4.1.0/../../../../include/c++/4.1.0/bits/stl_function.h:728:
note: std::const_mem_fun_ref_t<_Ret, _Tp>
std::mem_fun_ref(_Ret (_Tp::*)()const) [with _Ret = const double&, _Tp =
std::complex<double>]
Translated to English this means: should I create a const_mem_fun_ref_t with
complex::real() const, or a a mem_fun_ref_t with the non-const real()
overload?
Since the standard (26.2.2, or more particular: 26.2.3) mentions only one
real() and imag(), it is my belief that the above test program is correct,
and gcc's libstdc++ is off-specs.
Any thoughts?
In case this issue has already been discussed, I apologize for not googling
well enough and a pointer to the previous discourse would be appreciated.
With kind regards,
Jan van Dijk
--
dr. Jan van Dijk
Department of Applied Physics
Group Elementary Processes in Gas Discharges
Eindhoven University of Technology
The Netherlands
jan@etpmod.phys.tue.nl
+31 40 247 57 65