Boost logo

Boost Users :

Subject: Re: [Boost-users] reference_wrapper 101
From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2011-06-15 08:40:43

On Mon, Jun 13, 2011 at 9:55 AM, Robert Jones <robertgbjones_at_[hidden]>wrote:

> I thought understood what boost::reference_wrapper was all about, and in
> the context
> of, say Boost.Bind, it seems pretty clear.
> But why would you define a function to RETURN a reference_wrapper? eg
> template <class T> struct X
> {
> std::pair<boost::reference_wrapper<T>, unsigned> getSomething(....)
> const;
> };
> I suspect I'm having a 'doh' moment here!
> Thx,

In this particular case: it is possible to access first_type::type
parameter. It depends what the caller expects from the static interface.
Maybe there other types having getSomething(...) or other
getSomething-overloads, which return std::pair template instantiations and
all provide first_type::type. In such a case you don't have to apply
additional meta-functions to grab the underlying type from the first_type.
But there should be more info about the callers... On the other hand,
callers can make specialized compile time dispatching for
boost::reference_wrapper<T> but not T&.

With Kind Regards,

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at