Boost logo

Boost :

From: Jeff Paquette (paquette_at_[hidden])
Date: 2000-10-19 16:49:30


doh*! You are correct, sir :) I can only plead for mercy on the basis that
it was the end of a long day.

Thank you.

* As I explained to a coworker today,
ah - "I understand"
duh - "I should have understood"
doh! - "I can't believe I didn't understand that!"

--
Jeff Paquette
paquette at mediaone.net
http://www.atnetsend.net
> -----Original Message-----
> From: scleary_at_[hidden] [mailto:scleary_at_[hidden]]
> Sent: Wednesday, October 18, 2000 8:23 AM
> To: boost_at_[hidden]
> Subject: RE: [boost] template argument deduction
>
>
> As several others have posted, there's been some work on the subject.
> There's also a "deref-iterator" of some kind floating around
> (that just adds
> an extra dereference when dereferenced); that's what I use to solve this
> kind of problem.  Any of the already-mentioned solutions remove
> the need for
> adapters for function objects.
>
> But to answer your original question:
>
> > What I'm not wild about is having to explicitly provide the type to the
> > template (what happened to template-argument deduction? Does it
> not apply
> > here?).
>
> You need a function for template argument deduction; the constructor isn't
> enough:
>
> > template<typename _Pred> struct pointer_proxy2 :
> > std::binary_function<typename _Pred::result_type, typename
> > _Pred::first_argument_type, typename _Pred::second_argument_type>
> > {
> >   _Pred Pr;
> >   pointer_proxy2(_Pred pr) : Pr(pr) {}
> >   inline typename _Pred::result_type operator()(const typename
> > _Pred::first_argument_type *f, const typename
> _Pred::second_argument_type
> > *s) const {
> >     return Pr(*f, *s);
> >   }
> > };
>
> Add this "constructor function":
>
> template <typename _Pred> pointer_proxy2<_Pred> make_proxy2(const _Pred &
> pr)
> { return pointer_proxy2<_Pred>(pr); }
>
> Then,
>   std::sort(v.begin(), v.end(),
>       pointer_proxy2<std::less<int> >(std::less<int>()));
> becomes:
>   std::sort(v.begin(), v.end(),
>       make_proxy2(std::less<int>()) );
>
>
> Also see std::pair/make_pair, unary_negate/not1,
> binder1st/bind1st, etc. for
> more examples of the same pattern in the Standard.  All of the function
> object/pointer adapters in the Standard use a similar pairing.
>
> 	-Steve
>
>
>

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk