forked from boostorg/range
Boost.RangeEx merged into Boost.Range
[SVN r60897]
This commit is contained in:
47
include/boost/range/algorithm_ext/copy_n.hpp
Executable file
47
include/boost/range/algorithm_ext/copy_n.hpp
Executable file
@ -0,0 +1,47 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#ifndef BOOST_RANGE_ALGORITHM_COPY_N_HPP_INCLUDED
|
||||
#define BOOST_RANGE_ALGORITHM_COPY_N_HPP_INCLUDED
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/concept_check.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
#include <boost/range/concepts.hpp>
|
||||
#include <boost/range/distance.hpp>
|
||||
#include <boost/range/iterator.hpp>
|
||||
#include <boost/range/iterator_range.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
/// \brief template function copy
|
||||
///
|
||||
/// range-based version of the copy std algorithm
|
||||
///
|
||||
/// \pre SinglePassRange is a model of the SinglePassRangeConcept
|
||||
/// \pre OutputIterator is a model of the OutputIteratorConcept
|
||||
/// \pre 0 <= n < distance(rng)
|
||||
template< class SinglePassRange, class Size, class OutputIterator >
|
||||
inline OutputIterator copy_n(const SinglePassRange& rng, Size n, OutputIterator out)
|
||||
{
|
||||
boost::function_requires< SinglePassRangeConcept<SinglePassRange> >();
|
||||
BOOST_ASSERT( n < static_cast<Size>(boost::distance(rng)) );
|
||||
BOOST_ASSERT( n >= static_cast<Size>(0) );
|
||||
|
||||
BOOST_DEDUCED_TYPENAME range_const_iterator<SinglePassRange>::type source = boost::begin(rng);
|
||||
|
||||
for (Size i = 0; i < n; ++i, ++out, ++source)
|
||||
*out = *source;
|
||||
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // include guard
|
45
include/boost/range/algorithm_ext/erase.hpp
Executable file
45
include/boost/range/algorithm_ext/erase.hpp
Executable file
@ -0,0 +1,45 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#ifndef BOOST_RANGE_ALGORITHM_EXT_ERASE_HPP_INCLUDED
|
||||
#define BOOST_RANGE_ALGORITHM_EXT_ERASE_HPP_INCLUDED
|
||||
|
||||
#include <boost/range/config.hpp>
|
||||
#include <boost/range/difference_type.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
template< class Container >
|
||||
inline void erase( Container& on,
|
||||
iterator_range<BOOST_DEDUCED_TYPENAME Container::iterator> to_erase )
|
||||
{
|
||||
on.erase( boost::begin(to_erase), boost::end(to_erase) );
|
||||
}
|
||||
|
||||
template< class Container, class T >
|
||||
inline void remove_erase( Container& on, const T& val )
|
||||
{
|
||||
on.erase(
|
||||
std::remove(boost::begin(on), boost::end(on), val),
|
||||
boost::end(on));
|
||||
}
|
||||
|
||||
template< class Container, class Pred >
|
||||
inline void remove_erase_if( Container& on, Pred pred )
|
||||
{
|
||||
on.erase(
|
||||
std::remove_if(boost::begin(on), boost::end(on), pred),
|
||||
boost::end(on));
|
||||
}
|
||||
}
|
||||
|
||||
#endif // include guard
|
65
include/boost/range/algorithm_ext/for_each.hpp
Executable file
65
include/boost/range/algorithm_ext/for_each.hpp
Executable file
@ -0,0 +1,65 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#ifndef BOOST_RANGE_ALGORITHM_EXT_FOR_EACH_HPP_INCLUDED
|
||||
#define BOOST_RANGE_ALGORITHM_EXT_FOR_EACH_HPP_INCLUDED
|
||||
|
||||
#include <boost/range/config.hpp>
|
||||
#include <boost/range/difference_type.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace range_detail
|
||||
{
|
||||
template<class InputIterator1, class InputIterator2, class Fn2>
|
||||
inline Fn2 for_each_impl(InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2,
|
||||
Fn2 fn)
|
||||
{
|
||||
for (; first1 != last1 && first2 != last2; ++first1, ++first2)
|
||||
{
|
||||
fn(*first1, *first2);
|
||||
}
|
||||
return fn;
|
||||
}
|
||||
}
|
||||
|
||||
template<class SinglePassRange1, class SinglePassRange2, class Fn2>
|
||||
inline Fn2 for_each(const SinglePassRange1& rng1, const SinglePassRange2& rng2, Fn2 fn)
|
||||
{
|
||||
return range_detail::for_each_impl(boost::begin(rng1), boost::end(rng1),
|
||||
boost::begin(rng2), boost::end(rng2), fn);
|
||||
}
|
||||
|
||||
template<class SinglePassRange1, class SinglePassRange2, class Fn2>
|
||||
inline Fn2 for_each(const SinglePassRange1& rng1, SinglePassRange2& rng2, Fn2 fn)
|
||||
{
|
||||
return range_detail::for_each_impl(boost::begin(rng1), boost::end(rng1),
|
||||
boost::begin(rng2), boost::end(rng2), fn);
|
||||
}
|
||||
|
||||
template<class SinglePassRange1, class SinglePassRange2, class Fn2>
|
||||
inline Fn2 for_each(SinglePassRange1& rng1, const SinglePassRange2& rng2, Fn2 fn)
|
||||
{
|
||||
return range_detail::for_each_impl(boost::begin(rng1), boost::end(rng1),
|
||||
boost::begin(rng2), boost::end(rng2), fn);
|
||||
}
|
||||
|
||||
template<class SinglePassRange1, class SinglePassRange2, class Fn2>
|
||||
inline Fn2 for_each(SinglePassRange1& rng1, SinglePassRange2& rng2, Fn2 fn)
|
||||
{
|
||||
return range_detail::for_each_impl(boost::begin(rng1), boost::end(rng1),
|
||||
boost::begin(rng2), boost::end(rng2), fn);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // include guard
|
32
include/boost/range/algorithm_ext/insert.hpp
Executable file
32
include/boost/range/algorithm_ext/insert.hpp
Executable file
@ -0,0 +1,32 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#ifndef BOOST_RANGE_ALGORITHM_EXT_INSERT_HPP_INCLUDED
|
||||
#define BOOST_RANGE_ALGORITHM_EXT_INSERT_HPP_INCLUDED
|
||||
|
||||
#include <boost/range/config.hpp>
|
||||
#include <boost/range/difference_type.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
template< class Container, class Range >
|
||||
inline void insert( Container& on,
|
||||
BOOST_DEDUCED_TYPENAME Container::iterator before,
|
||||
const Range& from )
|
||||
{
|
||||
BOOST_ASSERT( (void*)&on != (void*)&from &&
|
||||
"cannot copy from a container to itself" );
|
||||
on.insert( before, boost::begin(from), boost::end(from) );
|
||||
}
|
||||
}
|
||||
|
||||
#endif // include guard
|
65
include/boost/range/algorithm_ext/is_sorted.hpp
Executable file
65
include/boost/range/algorithm_ext/is_sorted.hpp
Executable file
@ -0,0 +1,65 @@
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#ifndef BOOST_RANGE_ALGORITHM_EXT_IS_SORTED_HPP_INCLUDED
|
||||
#define BOOST_RANGE_ALGORITHM_EXT_IS_SORTED_HPP_INCLUDED
|
||||
|
||||
#include <boost/concept_check.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
#include <boost/range/concepts.hpp>
|
||||
#include <boost/range/value_type.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace range_detail
|
||||
{
|
||||
template<typename ForwardIterator>
|
||||
inline bool is_sorted(ForwardIterator first, ForwardIterator last)
|
||||
{
|
||||
for (ForwardIterator next = first; first != last && ++next != last; ++first)
|
||||
if (*next < *first)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename ForwardIterator, typename BinaryPredicate>
|
||||
inline bool is_sorted(ForwardIterator first, ForwardIterator last, BinaryPredicate pred)
|
||||
{
|
||||
for (ForwardIterator next = first; first != last && ++next != last; ++first)
|
||||
if (pred(*next, *first))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// \brief template function count
|
||||
///
|
||||
/// range-based version of the count std algorithm
|
||||
///
|
||||
/// \pre SinglePassRange is a model of the SinglePassRangeConcept
|
||||
template<typename SinglePassRange>
|
||||
inline bool is_sorted(const SinglePassRange& rng)
|
||||
{
|
||||
BOOST_CONCEPT_ASSERT((SinglePassRangeConcept<SinglePassRange>));
|
||||
BOOST_CONCEPT_ASSERT((LessThanComparableConcept<typename range_value<SinglePassRange>::type>));
|
||||
return range_detail::is_sorted(boost::begin(rng), boost::end(rng));
|
||||
}
|
||||
|
||||
/// \overload
|
||||
template<typename SinglePassRange, typename BinaryPredicate>
|
||||
inline bool is_sorted(const SinglePassRange& rng, BinaryPredicate pred)
|
||||
{
|
||||
BOOST_CONCEPT_ASSERT((SinglePassRangeConcept<SinglePassRange>));
|
||||
BOOST_CONCEPT_ASSERT((BinaryPredicateConcept<BinaryPredicate, typename range_value<SinglePassRange>::type, typename range_value<SinglePassRange>::type>));
|
||||
return range_detail::is_sorted(boost::begin(rng), boost::end(rng), pred);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // include guard
|
46
include/boost/range/algorithm_ext/overwrite.hpp
Executable file
46
include/boost/range/algorithm_ext/overwrite.hpp
Executable file
@ -0,0 +1,46 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#ifndef BOOST_RANGE_ALGORITHM_EXT_OVERWRITE_HPP_INCLUDED
|
||||
#define BOOST_RANGE_ALGORITHM_EXT_OVERWRITE_HPP_INCLUDED
|
||||
|
||||
#include <boost/range/config.hpp>
|
||||
#include <boost/range/difference_type.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
template< class SinglePassRange1, class SinglePassRange2 >
|
||||
inline void overwrite( const SinglePassRange1& from, SinglePassRange2& to )
|
||||
{
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange1>::type
|
||||
i = boost::begin(from), e = boost::end(from);
|
||||
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange2>::type
|
||||
out = boost::begin(to);
|
||||
|
||||
#ifndef NDEBUG
|
||||
BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange2>::type
|
||||
last_out = boost::end(to);
|
||||
#endif
|
||||
|
||||
for( ; i != e; ++out, ++i )
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
BOOST_ASSERT( out != last_out
|
||||
&& "out of bounds in boost::overwrite()" );
|
||||
#endif
|
||||
*out = *i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // include guard
|
31
include/boost/range/algorithm_ext/push_back.hpp
Executable file
31
include/boost/range/algorithm_ext/push_back.hpp
Executable file
@ -0,0 +1,31 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#ifndef BOOST_RANGE_ALGORITHM_EXT_PUSH_BACK_HPP_INCLUDED
|
||||
#define BOOST_RANGE_ALGORITHM_EXT_PUSH_BACK_HPP_INCLUDED
|
||||
|
||||
#include <boost/range/config.hpp>
|
||||
#include <boost/range/difference_type.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
template< class Container, class Range >
|
||||
inline void push_back( Container& on, const Range& from )
|
||||
{
|
||||
BOOST_ASSERT( (void*)&on != (void*)&from &&
|
||||
"cannot copy from a container to itself" );
|
||||
on.insert( on.end(), boost::begin(from), boost::end(from) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // include guard
|
30
include/boost/range/algorithm_ext/push_front.hpp
Executable file
30
include/boost/range/algorithm_ext/push_front.hpp
Executable file
@ -0,0 +1,30 @@
|
||||
// Boost.Range library
|
||||
//
|
||||
// Copyright Neil Groves 2009. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// For more information, see http://www.boost.org/libs/range/
|
||||
//
|
||||
#ifndef BOOST_RANGE_ALGORITHM_EXT_PUSH_FRONT_HPP_INCLUDED
|
||||
#define BOOST_RANGE_ALGORITHM_EXT_PUSH_FRONT_HPP_INCLUDED
|
||||
|
||||
#include <boost/range/config.hpp>
|
||||
#include <boost/range/difference_type.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
template< class Container, class Range >
|
||||
inline void push_front( Container& on, const Range& from )
|
||||
{
|
||||
BOOST_ASSERT( (void*)&on != (void*)&from &&
|
||||
"cannot copy from a container to itself" );
|
||||
on.insert( on.begin(), boost::begin(from), boost::end(from) );
|
||||
}
|
||||
}
|
||||
|
||||
#endif // include guard
|
Reference in New Issue
Block a user