Boost logo

Boost :

Subject: Re: [boost] Fwd: Re: [move] You can do it better: implementing push_back and handling implicit conversions
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2011-03-10 03:05:51


El 09/03/2011 23:02, Jeffrey Lee Hellrung, Jr. escribió:
> It seems reasonable for priv_push_back to have a common implementation
> between C++03 and C++0x. I believe the C++03 version should probably
> take it's parameter as U& rather than U const &, to preserve constness,
> so you might need to add an additional forwarding reference macro. I
> think I suggested this also in the Boost.Move review discussion. My lack
> of creativity has me using FWD2_REF( U ) expanding to U& in C++03 and
> U&& in C++0x.

So you think we could have a parameter that emulates "perfect
forwarding" (lvalue ref, const lvalue ref or ::boost::rv)? It should be
something that we could ::boost::forward until we finally construct the
value (priv_push_back might not be the place where we call placement new
in some containers, as we need to find the place, allocated, the node,
etc.). Please, since you are more skilled than me in this forwarding
issue, it would be nice if you could provide the code ;-)

> Are you also aiming to use macros to generate the various push_back
> overloads as well? That could be challenging to design a reasonable
> interface for, and I'm not necessarily opposed to the #ifndef
> BOOST_NO_RVALUE_REFERENCES / #else / #endif (as I'm not sure if a macro
> solution would look any better).

I was thinking in something like:

#define BOOST_MOVE_CONVERSION_AWARE_INSERTION_CATCH(TYPE, FWD_FUNCTION,
RETURN_VALUE)

In our test each parameter could be:

TYPE = T
FWD_FUNCTION = priv_push_back
RETURN_VALUE = void

We can have another macro that also takes an additional parameter before
the forwarding, so that container users can implement something like:

#define BOOST_MOVE_CONVERSION_AWARE_INSERTION_CATCH(TYPE, FWD_FUNCTION,
RETURN_VALUE, BEFORE_PARAMETER)

iterator insert(const_iterator, T &&x)
iterator insert(const_iterator, const T &x)

//Generate conversion-aware public insertion function
BOOST_MOVE_CONVERSION_AWARE_INSERTION_CATCH_1(T, priv_insert, iterator,
const_iterator)

//Value will be forwarded here
template<class U>
iterator priv_insert(const_iterator, BOOST_FWD_REF(U) u)
{
    return deeper_function(::boost::forward<U>(u));
}

Best,

Ion


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