bug in stl_function.h
Levente Farkas
lfarkas@mindmaker.hu
Wed Apr 5 03:41:00 GMT 2000
hi,
_Identity, _Select1st and _Select2nd should have to patch with the
attachment in order to work with both const AND non-const pair.
the "feature" that operator() is not always return with result_type
is not too nice (although I understand sri's points about the original
version), but it is not correct without the modification.
ps. anyways this const correctness is the biggest weekness of the standard.
-- lfarkas
"The only thing worse than not knowing the truth is
ruining the bliss of ignorance."
*** stl_function.h-ori Wed Apr 05 11:50:52 2000
--- stl_function.h Wed Apr 05 11:51:46 2000
***************
*** 325,330 ****
--- 325,331 ----
// identity is an extensions: it is not part of the standard.
template <class _Tp>
struct _Identity : public unary_function<_Tp,_Tp> {
+ _Tp& operator()(_Tp& __x) const { return __x; }
const _Tp& operator()(const _Tp& __x) const { return __x; }
};
***************
*** 333,338 ****
--- 334,342 ----
// select1st and select2nd are extensions: they are not part of the standard.
template <class _Pair>
struct _Select1st : public unary_function<_Pair, typename _Pair::first_type> {
+ typename _Pair::first_type& operator()(_Pair& __x) const {
+ return __x.first;
+ }
const typename _Pair::first_type& operator()(const _Pair& __x) const {
return __x.first;
}
***************
*** 341,346 ****
--- 345,353 ----
template <class _Pair>
struct _Select2nd : public unary_function<_Pair, typename _Pair::second_type>
{
+ typename _Pair::second_type& operator()(_Pair& __x) const {
+ return __x.second;
+ }
const typename _Pair::second_type& operator()(const _Pair& __x) const {
return __x.second;
}
More information about the Libstdc++
mailing list