This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: bind2nd, ptr_fun with a function with const refs args.
- From: Jonathan Wakely <cow at compsoc dot man dot ac dot uk>
- To: Steven King <sxking at qwest dot net>
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Tue, 20 Jan 2004 12:27:26 +0000
- Subject: Re: bind2nd, ptr_fun with a function with const refs args.
- References: <200401191434.39743.sxking@qwest.net>
On Mon, Jan 19, 2004 at 02:34:28PM -0800, Steven King wrote:
> 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'.
The standard forbids forming a reference to a reference, so GCC is right
to issue a diagnostic here.
The Boost libs provide some ways to deal with this,
e.g. http://www.boost.org/libs/utility/call_traits.htm#refs
jon
--
"Any sufficiently advanced bug is indistinguishable from a feature"
- Rich Kulawiec