Q. about GDR's addition of complex-accessor overloads.
Jan van Dijk
jan@etpmod.phys.tue.nl
Thu Nov 10 07:35:00 GMT 2005
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
More information about the Libstdc++
mailing list