This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: bind2nd, ptr_fun with a function with const refs args.


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]