added algorithm_ext insert algorithm for containers without a where iterator.

This commit is contained in:
Neil Groves
2014-03-08 21:42:42 +00:00
parent 7cd8b9ec24
commit 343e74b8e3
2 changed files with 17 additions and 3 deletions

View File

@ -11,10 +11,18 @@
template< template<
class Container, class Container,
class SinglePassRange class SinglePassRange
> >
Container& insert(Container& target, Container& insert(Container& target,
typename Container::iterator before, typename Container::iterator before,
const SinglePassRange& from); const SinglePassRange& from);
// This overload is for target containers that do not require an insertion
// position e.g. set/map
template<
class Container,
class SinglePassRange
>
Container& insert(Container& target, const SinglePassRange& from);
`` ``
[heading Description] [heading Description]

View File

@ -29,12 +29,18 @@ inline Container& insert( Container& on,
{ {
BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<Container> )); BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<Container> ));
BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<Range> )); BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<Range> ));
BOOST_ASSERT( (void*)&on != (void*)&from &&
"cannot copy from a container to itself" );
on.insert( before, boost::begin(from), boost::end(from) ); on.insert( before, boost::begin(from), boost::end(from) );
return on; return on;
} }
template< class Container, class Range >
inline Container& insert( Container& on, const Range& from )
{
BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<Container> ));
BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<Range> ));
on.insert(boost::begin(from), boost::end(from));
}
} // namespace range } // namespace range
using range::insert; using range::insert;
} // namespace boost } // namespace boost