bind2nd, ptr_fun with a function with const refs args.
Steven King
sxking@qwest.net
Mon Jan 19 22:34:00 GMT 2004
I was trying to use bind2nd and ptr_fun with a function that has two const &
args. ie
template < typename T1, typename T2, typename T3 >
std::set < T3 >
bar (std::set < T1 > const &s, T2 const &t, T3 (*f)(T1 const &, T2 const &))
{
std::set < T3 > r;
std::transform (
s.begin (),
s.end (),
std::inserter (r, r.begin ()),
bind2nd(ptr_fun (f), t));
return r;
}
this fails an 'error: forming reference to reference type'.
As I dont have a copy of the standard handy, I wasnt sure if this was
supposed to work; if so, would it be reasonable to add to stl_function.h a
specialization of pointer_to_binary_function like so:
template <class _Arg1, class _Arg2, class _Result>
class pointer_to_binary_function :
public binary_function<const _Arg1&, const _Arg2&,_Result> {
protected:
_Result (*_M_ptr)(const _Arg1&, const _Arg2&);
public:
pointer_to_binary_function() {}
explicit pointer_to_binary_function(_Result (*__x)(const _Arg1&, const
_Arg2&))
: _M_ptr(__x) {}
_Result operator()(const _Arg1& __x, const _Arg2& __y) const {
return _M_ptr(__x, __y);
}
};
More information about the Libstdc++
mailing list