forked from boostorg/range
push_back: added support for not-copyable but moveable value-types like e.g. unique_ptr
This commit is contained in:
@ -20,9 +20,37 @@
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace range
|
||||
#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
namespace range_detail
|
||||
{
|
||||
|
||||
template < class Container, class Range >
|
||||
inline Container& push_back_impl( Container& on, Range&& from, std::false_type)
|
||||
{
|
||||
BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<Range> ));
|
||||
BOOST_ASSERT_MSG(!range_detail::is_same_object(on, from),
|
||||
"cannot move from a container to itself");
|
||||
on.insert( on.end(),
|
||||
std::make_move_iterator(boost::begin(from)),
|
||||
std::make_move_iterator(boost::end(from)));
|
||||
return on;
|
||||
}
|
||||
|
||||
template < class Container, class Range >
|
||||
inline Container& push_back_impl( Container& on, const Range& from, std::true_type)
|
||||
{
|
||||
BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const Range> ));
|
||||
BOOST_ASSERT_MSG(!range_detail::is_same_object(on, from),
|
||||
"cannot copy from a container to itself");
|
||||
on.insert( on.end(), boost::begin(from), boost::end(from));
|
||||
return on;
|
||||
}
|
||||
|
||||
} //namespace range_detail
|
||||
#endif
|
||||
|
||||
namespace range {
|
||||
#if defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
|
||||
template< class Container, class Range >
|
||||
inline Container& push_back( Container& on, const Range& from )
|
||||
{
|
||||
@ -34,6 +62,19 @@ inline Container& push_back( Container& on, const Range& from )
|
||||
return on;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
template< class Container, class Range >
|
||||
inline Container& push_back( Container& on, Range&& from )
|
||||
{
|
||||
BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<Container> ));
|
||||
range_detail::push_back_impl(on,
|
||||
std::forward<Range>(from),
|
||||
std::is_lvalue_reference<Range>() );
|
||||
return on;
|
||||
}
|
||||
|
||||
#endif
|
||||
} // namespace range
|
||||
using range::push_back;
|
||||
} // namespace boost
|
||||
|
Reference in New Issue
Block a user