Topic: Problem with ptr_fun and not1
Author: "J rgen Weiss" <jw@miro.stuttgart.netsurf.de>
Date: 1998/05/12 Raw View
Hi,
I have a question regarding the ptr_fun function adaptor. I am rather new to the STL
so please be patient with me.
The following sample code produces an error with both STL-Port 3.0 (an port of
the SGI implementation) and the Microsoft STL, using VC++ 5.0:
struct MyStruct { int a; };
bool MyPred(const MyStruct& x)
{
return x.a != 0;
}
void fn()
{
not1(ptr_fun(MyPred));
}
Compiling with the Microsoft STL, I get the following error:
functional(120) : warning C4181: qualifier applied to reference type ignored
functional(120) : error C2529: '_X' : reference to reference is illegal
functional(120) is in the body of unary_negate:
// TEMPLATE CLASS unary_negate
template<class _Ufn>
class unary_negate
: public unary_function<_Ufn::argument_type, bool> {
public:
explicit unary_negate(const _Ufn& _X)
: _Fn(_X) {}
>>>>> bool operator()(const _Ufn::argument_type& _X) const <<<<<
{return (!_Fn(_X)); }
protected:
_Ufn _Fn;
};
The STL-Port delivers similar errors:
stl_function.h(193) : warning C4181: qualifier applied to reference type ignored
stl_function.h(193) : error C2529: 'x' : reference to reference is illegal
emplate <class Predicate>
class unary_negate :
public unary_function<typename __UNARY_ARG(Predicate,argument_type), bool> {
protected:
Predicate pred;
public:
explicit unary_negate(const Predicate& x) : pred(x) {}
>>>> bool operator()(const typename Predicate::argument_type& x) const { return !pred(x); } <<<<
};
--
I am tempted to simply change the operator() into
bool operator()(typename Predicate::argument_type x) const { return !pred(x); }
Works fine if I do this.
So: Did I find a bug in the STL or did I use the function adaptors incorrectly?
Also: Is it acceptible to obmit the reference & in the operator() operator?
Any comments welcome.
Greetings,
-- J rgen
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]