Boost.RangeEx merged into Boost.Range

[SVN r60897]
This commit is contained in:
Neil Groves
2010-03-28 16:08:35 +00:00
parent 1461479a17
commit b0d1db7c2e
471 changed files with 48610 additions and 2065 deletions

View File

@ -0,0 +1,255 @@
// Boost.Range library
//
// Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. 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_ADAPTOR_ADJACENT_FILTER_IMPL_HPP
#define BOOST_RANGE_ADAPTOR_ADJACENT_FILTER_IMPL_HPP
#include <boost/config.hpp>
#ifdef BOOST_MSVC
#pragma warning( push )
#pragma warning( disable : 4355 )
#endif
#include <boost/range/adaptor/argument_fwd.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/iterator/iterator_adaptor.hpp>
#include <boost/next_prior.hpp>
namespace boost
{
namespace range_detail
{
template< class Iter, class R >
class skip_iterator
: public boost::iterator_adaptor< skip_iterator<Iter,R>, Iter >
{
private:
typedef boost::iterator_adaptor< skip_iterator<Iter,R>, Iter >
base_t;
R* range;
public:
typedef Iter wrapped_iter_t;
//
// The iterators are bound to the lifetime of the
// range and may not exist on their own. Hence it makes no
// sense to e.g. wrap them in reverse_iterators
// (that can OTOH be done in advance).
//
typedef std::input_iterator_tag iterator_category;
explicit skip_iterator( R* r, Iter i )
: base_t(i), range(r) {}
template< class OtherIter, class R2>
skip_iterator( const skip_iterator<OtherIter,R2>& other )
: base_t( other.base() ) {}
R* get_range() const { return range; }
private:
friend class boost::iterator_core_access;
void increment()
{
BOOST_ASSERT( range != 0 );
range->increment_impl( this->base_reference() );
}
//
// Not needed ... just apply a reverse_iterator
//
void decrement()
{
BOOST_ASSERT( false && "you can't decrement an adjacent_filter_iterator" );
}
template< class D >
void advance( D n )
{
BOOST_ASSERT( false );
}
};
template< class P, class R >
struct adjacent_filter_range
: iterator_range< skip_iterator<
BOOST_DEDUCED_TYPENAME range_iterator<R>::type,
adjacent_filter_range<P,R>
>
>
{
private:
typedef skip_iterator<
BOOST_DEDUCED_TYPENAME range_iterator<R>::type,
adjacent_filter_range<P,R>
>
skip_iter;
typedef iterator_range<skip_iter>
base_range;
typedef BOOST_DEDUCED_TYPENAME range_iterator<R>::type raw_iterator;
P bi_pred;
// Get the first element in the half-open range that
// passes the filter predicate.
// The adjacent_filter_range must only contain values that pass
// through the filter.
static raw_iterator to_valid(raw_iterator it, raw_iterator last, const P& bi_pred, bool default_pass)
{
if (it != last)
{
if (default_pass)
{
raw_iterator nxt = next(it);
while (nxt != last && !bi_pred(*it, *nxt))
{
++it;
++nxt;
}
}
else
{
raw_iterator nxt = next(it);
for(; nxt != last; ++it, ++nxt)
{
if (bi_pred(*it, *nxt))
{
break;
}
}
if (nxt == last)
{
it = last;
}
}
}
return it;
}
public:
adjacent_filter_range( const P& p, R& r, bool default_pass )
: base_range( skip_iter( this, to_valid(boost::begin(r), boost::end(r), p, default_pass)),
skip_iter( this, boost::end(r) ) ),
bi_pred( p ),
_default_pass(default_pass)
{
}
void increment_impl( raw_iterator& current )
{
BOOST_ASSERT( current != this->end().base() );
current = to_valid(next(current), this->end().base(), bi_pred, _default_pass);
}
private:
bool _default_pass;
};
template< class T >
struct adjacent_holder : holder<T>
{
adjacent_holder( T r ) : holder<T>(r)
{ }
};
template< class T >
struct adjacent_excl_holder : holder<T>
{
adjacent_excl_holder( T r ) : holder<T>(r)
{ }
};
template< class ForwardRng, class BinPredicate >
inline adjacent_filter_range<BinPredicate, ForwardRng>
operator|( ForwardRng& r,
const adjacent_holder<BinPredicate>& f )
{
return adjacent_filter_range<BinPredicate, ForwardRng>( f.val, r, true );
}
template< class ForwardRng, class BinPredicate >
inline adjacent_filter_range<BinPredicate, const ForwardRng>
operator|( const ForwardRng& r,
const adjacent_holder<BinPredicate>& f )
{
return adjacent_filter_range<BinPredicate,
const ForwardRng>( f.val, r, true );
}
template< class ForwardRng, class BinPredicate >
inline adjacent_filter_range<BinPredicate, ForwardRng>
operator|( ForwardRng& r,
const adjacent_excl_holder<BinPredicate>& f )
{
return adjacent_filter_range<BinPredicate, ForwardRng>( f.val, r, false );
}
template< class ForwardRng, class BinPredicate >
inline adjacent_filter_range<BinPredicate, ForwardRng>
operator|( const ForwardRng& r,
const adjacent_excl_holder<BinPredicate>& f )
{
return adjacent_filter_range<BinPredicate,
const ForwardRng>( f.val, r, false );
}
} // 'range_detail'
// Bring adjacent_filter_range into the boost namespace so that users of
// this library may specify the return type of the '|' operator and
// make_adjacent_filtered_range()
using range_detail::adjacent_filter_range;
namespace adaptors
{
namespace
{
const range_detail::forwarder<range_detail::adjacent_holder>
adjacent_filtered =
range_detail::forwarder<range_detail::adjacent_holder>();
const range_detail::forwarder<range_detail::adjacent_excl_holder>
adjacent_filtered_excl =
range_detail::forwarder<range_detail::adjacent_excl_holder>();
}
template<class ForwardRng, class BinPredicate>
inline adjacent_filter_range<BinPredicate, ForwardRng>
adjacent_filter(ForwardRng& rng, BinPredicate filter_pred, bool default_pass = true)
{
return adjacent_filter_range<BinPredicate, ForwardRng>(filter_pred, rng, default_pass);
}
template<class ForwardRng, class BinPredicate>
inline adjacent_filter_range<BinPredicate, const ForwardRng>
adjacent_filter(const ForwardRng& rng, BinPredicate filter_pred, bool default_pass = true)
{
return adjacent_filter_range<BinPredicate, const ForwardRng>(filter_pred, rng, default_pass);
}
} // 'adaptors'
}
#ifdef BOOST_MSVC
#pragma warning( pop )
#endif
#endif

View File

@ -0,0 +1,80 @@
// Boost.Range library
//
// Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. 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_ADAPTOR_ARGUMENT_FWD_HPP
#define BOOST_RANGE_ADAPTOR_ARGUMENT_FWD_HPP
#include <boost/config.hpp>
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable : 4512) // assignment operator could not be generated
#endif
namespace boost
{
namespace range_detail
{
template< class T >
struct holder
{
T val;
holder( T t ) : val(t)
{ }
};
template< class T >
struct holder2
{
T val1, val2;
holder2( T t, T u ) : val1(t), val2(u)
{ }
};
template< template<class> class Holder >
struct forwarder
{
template< class T >
Holder<T> operator()( T t ) const
{
return Holder<T>(t);
}
};
template< template<class> class Holder >
struct forwarder2
{
template< class T >
Holder<T> operator()( T t, T u ) const
{
return Holder<T>(t,u);
}
};
template< template<class,class> class Holder >
struct forwarder2TU
{
template< class T, class U >
Holder<T, U> operator()( T t, U u ) const
{
return Holder<T, U>(t, u);
}
};
}
}
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#endif

View File

@ -0,0 +1,68 @@
// Boost.Range library
//
// Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. 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_ADAPTOR_COPIED_HPP
#define BOOST_RANGE_ADAPTOR_COPIED_HPP
#include <boost/range/adaptor/argument_fwd.hpp>
#include <boost/range/adaptor/sliced.hpp>
#include <boost/range/size_type.hpp>
#include <boost/range/iterator_range.hpp>
namespace boost
{
namespace range_detail
{
template< class T >
struct copy_holder
: holder2<std::size_t>
{
copy_holder( std::size_t t, std::size_t u )
: holder2<std::size_t>(t,u)
{ }
};
template< class CopyableRandomAccessRng, class Int >
inline CopyableRandomAccessRng
operator|( const CopyableRandomAccessRng& r, const copy_holder<Int>& f )
{
iterator_range<
BOOST_DEDUCED_TYPENAME range_iterator<const
CopyableRandomAccessRng>::type >
temp( sliced_impl( r, f ) );
return CopyableRandomAccessRng( temp.begin(), temp.end() );
}
} // 'range_detail'
namespace adaptors
{
namespace
{
const range_detail::forwarder2<range_detail::copy_holder>
copied = range_detail::forwarder2<range_detail::copy_holder>();
}
template<class CopyableRandomAccessRange>
inline CopyableRandomAccessRange
copy(const CopyableRandomAccessRange& rng, std::size_t t, std::size_t u)
{
iterator_range<
BOOST_DEDUCED_TYPENAME range_iterator<const
CopyableRandomAccessRange>::type> temp(
adaptors::slice(rng, t, u));
return CopyableRandomAccessRange( temp.begin(), temp.end() );
}
} // 'adaptors'
}
#endif

View File

@ -0,0 +1,117 @@
#ifndef BOOST_RANGE_DEFINE_ADAPTOR_HPP_INCLUDED
#define BOOST_RANGE_DEFINE_ADAPTOR_HPP_INCLUDED
#include <boost/tuple/tuple.hpp>
#define BOOST_DEFINE_RANGE_ADAPTOR( adaptor_name, range_adaptor ) \
struct adaptor_name##_forwarder {}; \
\
template<typename Range> range_adaptor <Range> \
operator|(Range& rng, adaptor_name##_forwarder) \
{ \
return range_adaptor <Range>( rng ); \
} \
\
template<typename Range> range_adaptor <const Range> \
operator|(const Range& rng, adaptor_name##_forwarder) \
{ \
return range_adaptor <const Range>( rng ); \
} \
\
static adaptor_name##_forwarder adaptor_name = adaptor_name##_forwarder(); \
\
template<typename Range> \
range_adaptor <Range> \
make_##adaptor_name(Range& rng) \
{ \
return range_adaptor <Range>(rng); \
} \
\
template<typename Range> \
range_adaptor <const Range> \
make_##adaptor_name(const Range& rng) \
{ \
return range_adaptor <const Range>(rng); \
}
#define BOOST_DEFINE_RANGE_ADAPTOR_1( adaptor_name, range_adaptor, adaptor_class ) \
template<typename Range> range_adaptor <Range> \
operator|(Range& rng, const adaptor_name & args) \
{ \
return range_adaptor <Range>(rng, args.arg1); \
} \
template<typename Range> range_adaptor <const Range> \
operator|(const Range& rng, const adaptor_name & args) \
{ \
return range_adaptor <Range>(rng, args.arg1); \
} \
template<typename Range, typename Arg1> \
range_adaptor<Range> \
make_##adaptor_name(Range& rng, Arg1 arg1) \
{ \
return range_adaptor<Range>(rng, arg1); \
}
#define BOOST_DEFINE_RANGE_ADAPTOR_1( adaptor_name, range_adaptor, arg1_type ) \
struct adaptor_name \
{ \
explicit adaptor_name (arg1_type arg1_) \
: arg1(arg1_) {} \
arg1_type arg1; \
}; \
\
template<typename Range> range_adaptor <Range> \
operator|(Range& rng, adaptor_name args) \
{ \
return range_adaptor <Range>(rng, args.arg1); \
} \
\
template<typename Range> range_adaptor <const Range> \
operator|(const Range& rng, adaptor_name args) \
{ \
return range_adaptor <const Range>(rng, args.arg1); \
} \
\
template<typename Range> \
range_adaptor <Range> \
make_##adaptor_name(Range& rng, arg1_type arg1) \
{ \
return range_adaptor <Range>(rng, arg1); \
} \
\
template<typename Range> \
range_adaptor <const Range> \
make_##adaptor_name(const Range& rng, arg1_type arg1) \
{ \
return range_adaptor <const Range>(rng, arg1); \
}
#define BOOST_RANGE_ADAPTOR_2( adaptor_name, range_adaptor, arg1_type, arg2_type ) \
struct adaptor_name \
{ \
explicit adaptor_name (arg1_type arg1_, arg2_type arg2_) \
: arg1(arg1_), arg2(arg2_) {} \
arg1_type arg1; \
arg2_type arg2; \
}; \
\
template<typename Range> range_adaptor <Range> \
operator|(Range& rng, adaptor_name args) \
{ \
return range_adaptor <Range>(rng, args.arg1, args.arg2); \
} \
template<typename Range> \
range_adaptor <Range> \
make_##adaptor_name(Range& rng, arg1_type arg1, arg2_type arg2) \
{ \
return range_adaptor <Range>(rng, arg1, arg2); \
} \
template<typename Range> \
range_adaptor <const Range> \
make_##adaptor_name(const Range& rng, arg1_type arg1, arg2_type arg2) \
{ \
return range_adaptor <const Range>(rng, arg1, arg2); \
}
#endif // include guard

View File

@ -0,0 +1,102 @@
// Boost.Range library
//
// Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. 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_ADAPTOR_FILTERED_HPP
#define BOOST_RANGE_ADAPTOR_FILTERED_HPP
#include <boost/range/adaptor/argument_fwd.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/iterator/filter_iterator.hpp>
namespace boost
{
namespace range_detail
{
template< class P, class R >
struct filter_range :
boost::iterator_range<
boost::filter_iterator< P,
BOOST_DEDUCED_TYPENAME range_iterator<R>::type
>
>
{
private:
typedef boost::iterator_range<
boost::filter_iterator< P,
BOOST_DEDUCED_TYPENAME range_iterator<R>::type
>
>
base;
public:
filter_range( P p, R& r )
: base( make_filter_iterator( p, boost::begin(r), boost::end(r) ),
make_filter_iterator( p, boost::end(r), boost::end(r) ) )
{ }
};
template< class T >
struct filter_holder : holder<T>
{
filter_holder( T r ) : holder<T>(r)
{ }
};
template< class InputRng, class Predicate >
inline filter_range<Predicate, InputRng>
operator|( InputRng& r,
const filter_holder<Predicate>& f )
{
return filter_range<Predicate, InputRng>( f.val, r );
}
template< class InputRng, class Predicate >
inline filter_range<Predicate, const InputRng>
operator|( const InputRng& r,
const filter_holder<Predicate>& f )
{
return filter_range<Predicate, const InputRng>( f.val, r );
}
} // 'range_detail'
// Unusual use of 'using' is intended to bring filter_range into the boost namespace
// while leaving the mechanics of the '|' operator in range_detail and maintain
// argument dependent lookup.
// filter_range logically needs to be in the boost namespace to allow user of
// the library to define the return type for make_filtered_range()
using range_detail::filter_range;
namespace adaptors
{
namespace
{
const range_detail::forwarder<range_detail::filter_holder>
filtered =
range_detail::forwarder<range_detail::filter_holder>();
}
template<class InputRange, class Predicate>
inline filter_range<Predicate, InputRange>
filter(InputRange& rng, Predicate filter_pred)
{
return range_detail::filter_range<Predicate, InputRange>( filter_pred, rng );
}
template<class InputRange, class Predicate>
inline filter_range<Predicate, const InputRange>
filter(const InputRange& rng, Predicate filter_pred)
{
return range_detail::filter_range<Predicate, const InputRange>( filter_pred, rng );
}
} // 'adaptors'
}
#endif

View File

@ -0,0 +1,173 @@
// Boost.Range library
//
// Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. 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_ADAPTOR_INDEXED_IMPL_HPP
#define BOOST_RANGE_ADAPTOR_INDEXED_IMPL_HPP
#include <boost/config.hpp>
#ifdef BOOST_MSVC
#pragma warning( push )
#pragma warning( disable : 4355 )
#endif
#include <boost/range/adaptor/argument_fwd.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/iterator/iterator_adaptor.hpp>
namespace boost
{
namespace range_detail
{
template< class Iter >
class indexed_iterator
: public boost::iterator_adaptor< indexed_iterator<Iter>, Iter >
{
private:
typedef boost::iterator_adaptor< indexed_iterator<Iter>, Iter >
base;
typedef BOOST_DEDUCED_TYPENAME base::difference_type index_type;
index_type index_;
public:
explicit indexed_iterator( Iter i, index_type index )
: base(i), index_(index)
{
BOOST_ASSERT( index_ >= 0 && "Indexed Iterator out of bounds" );
}
index_type index() const
{
return index_;
}
private:
friend class boost::iterator_core_access;
void increment()
{
++index_;
++(this->base_reference());
}
void decrement()
{
BOOST_ASSERT( index_ > 0 && "Indexed Iterator out of bounds" );
--index_;
--(this->base_reference());
}
void advance( index_type n )
{
index_ += n;
BOOST_ASSERT( index_ >= 0 && "Indexed Iterator out of bounds" );
this->base_reference() += n;
}
};
template< class Rng >
struct indexed_range :
iterator_range< indexed_iterator<BOOST_DEDUCED_TYPENAME range_iterator<Rng>::type> >
{
private:
typedef indexed_iterator<BOOST_DEDUCED_TYPENAME range_iterator<Rng>::type>
iter_type;
typedef iterator_range<iter_type>
base;
public:
template< class Index >
indexed_range( Index i, Rng& r )
: base( iter_type(boost::begin(r), i), iter_type(boost::end(r),i) )
{ }
};
template< class T >
struct index_holder : holder<T>
{
index_holder( T r ) : holder<T>(r)
{ }
};
struct index_forwarder
{
template< class T >
index_holder<T> operator()( T r ) const
{
return r;
}
index_holder<int> operator()( int r = 0 ) const
{
return r;
}
};
template< class SinglePassRange >
inline indexed_range<SinglePassRange>
operator|( SinglePassRange& r,
const index_holder<typename range_difference<SinglePassRange>::type>& f )
{
return indexed_range<SinglePassRange>( f.val, r );
}
template< class SinglePassRange >
inline indexed_range<const SinglePassRange>
operator|( const SinglePassRange& r,
const index_holder<typename range_difference<SinglePassRange>::type>& f )
{
return indexed_range<const SinglePassRange>( f.val, r );
}
} // 'range_detail'
// Make this available to users of this library. It will sometimes be
// required since it is the return type of operator '|' and
// make_indexed_range().
using range_detail::indexed_range;
namespace adaptors
{
namespace
{
const range_detail::forwarder<range_detail::index_holder>
indexed =
range_detail::forwarder<range_detail::index_holder>();
}
template<class SinglePassRange, class Index>
inline indexed_range<SinglePassRange>
index(SinglePassRange& rng, Index index)
{
return indexed_range<SinglePassRange>(index, rng);
}
template<class SinglePassRange, class Index>
inline indexed_range<const SinglePassRange>
index(const SinglePassRange& rng, Index index)
{
return indexed_range<const SinglePassRange>(index, rng);
}
} // 'adaptors'
}
#ifdef BOOST_MSVC
#pragma warning( pop )
#endif
#endif

View File

@ -0,0 +1,88 @@
// Boost.Range library
//
// Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. 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_ADAPTOR_INDIRECTED_HPP
#define BOOST_RANGE_ADAPTOR_INDIRECTED_HPP
#include <boost/range/iterator_range.hpp>
#include <boost/iterator/indirect_iterator.hpp>
namespace boost
{
namespace range_detail
{
template< class R >
struct indirect_range :
public boost::iterator_range<
boost::indirect_iterator<
BOOST_DEDUCED_TYPENAME range_iterator<R>::type
>
>
{
private:
typedef boost::iterator_range<
boost::indirect_iterator<
BOOST_DEDUCED_TYPENAME range_iterator<R>::type
>
>
base;
public:
indirect_range( R& r )
: base( r )
{ }
};
struct indirect_forwarder {};
template< class InputRng >
inline indirect_range<InputRng>
operator|( InputRng& r, indirect_forwarder )
{
return indirect_range<InputRng>( r );
}
template< class InputRng >
inline indirect_range<const InputRng>
operator|( const InputRng& r, indirect_forwarder )
{
return indirect_range<const InputRng>( r );
}
} // 'range_detail'
using range_detail::indirect_range;
namespace adaptors
{
namespace
{
const range_detail::indirect_forwarder indirected =
range_detail::indirect_forwarder();
}
template<class InputRange>
inline indirect_range<InputRange>
indirect(InputRange& rng)
{
return indirect_range<InputRange>(rng);
}
template<class InputRange>
inline indirect_range<const InputRange>
indirect(const InputRange& rng)
{
return indirect_range<const InputRange>(rng);
}
} // 'adaptors'
}
#endif

View File

@ -0,0 +1,188 @@
// Boost.Range library
//
// Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. 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_ADAPTOR_MAP_HPP
#define BOOST_RANGE_ADAPTOR_MAP_HPP
#include <boost/range/adaptor/transformed.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/range/value_type.hpp>
namespace boost
{
namespace range_detail
{
struct map_keys_forwarder {};
struct map_values_forwarder {};
template< class Map >
struct select_first
{
typedef BOOST_DEDUCED_TYPENAME Map::value_type pair_t;
typedef const BOOST_DEDUCED_TYPENAME pair_t::first_type&
result_type;
result_type operator()( const pair_t& r ) const
{
return r.first;
}
};
template< class Map >
struct select_second_mutable
{
typedef BOOST_DEDUCED_TYPENAME Map::value_type pair_t;
typedef BOOST_DEDUCED_TYPENAME pair_t::second_type& result_type;
result_type operator()( pair_t& r ) const
{
return r.second;
}
};
template< class Map >
struct select_second_const
{
typedef BOOST_DEDUCED_TYPENAME Map::value_type pair_t;
typedef const BOOST_DEDUCED_TYPENAME pair_t::second_type&
result_type;
result_type operator()( const pair_t& r ) const
{
return r.second;
}
};
template<class StdPairRng>
class select_first_range
: public transform_range<
select_first<StdPairRng>,
const StdPairRng>
{
typedef transform_range<select_first<StdPairRng>, const StdPairRng> base;
public:
typedef select_first<StdPairRng> transform_fn_type;
typedef const StdPairRng source_range_type;
select_first_range(transform_fn_type fn, source_range_type& rng)
: base(fn, rng)
{
}
select_first_range(const base& other) : base(other) {}
};
template<class StdPairRng>
class select_second_mutable_range
: public transform_range<
select_second_mutable<StdPairRng>,
StdPairRng>
{
typedef transform_range<select_second_mutable<StdPairRng>, StdPairRng> base;
public:
typedef select_second_mutable<StdPairRng> transform_fn_type;
typedef StdPairRng source_range_type;
select_second_mutable_range(transform_fn_type fn, source_range_type& rng)
: base(fn, rng)
{
}
select_second_mutable_range(const base& other) : base(other) {}
};
template<class StdPairRng>
class select_second_const_range
: public transform_range<
select_second_const<StdPairRng>,
const StdPairRng>
{
typedef transform_range<select_second_const<StdPairRng>, const StdPairRng> base;
public:
typedef select_second_const<StdPairRng> transform_fn_type;
typedef const StdPairRng source_range_type;
select_second_const_range(transform_fn_type fn, source_range_type& rng)
: base(fn, rng)
{
}
select_second_const_range(const base& other) : base(other) {}
};
template< class StdPairRng >
inline select_first_range<StdPairRng>
operator|( const StdPairRng& r, map_keys_forwarder )
{
return operator|( r,
boost::adaptors::transformed( select_first<StdPairRng>() ) );
}
template< class StdPairRng >
inline select_second_mutable_range<StdPairRng>
operator|( StdPairRng& r, map_values_forwarder )
{
return operator|( r,
boost::adaptors::transformed( select_second_mutable<StdPairRng>() ) );
}
template< class StdPairRng >
inline select_second_const_range<StdPairRng>
operator|( const StdPairRng& r, map_values_forwarder )
{
return operator|( r,
boost::adaptors::transformed( select_second_const<StdPairRng>() ) );
}
} // 'range_detail'
using range_detail::select_first_range;
using range_detail::select_second_mutable_range;
using range_detail::select_second_const_range;
namespace adaptors
{
namespace
{
const range_detail::map_keys_forwarder map_keys =
range_detail::map_keys_forwarder();
const range_detail::map_values_forwarder map_values =
range_detail::map_values_forwarder();
}
template<class StdPairRange>
inline select_first_range<StdPairRange>
keys(const StdPairRange& rng)
{
return select_first_range<StdPairRange>(
range_detail::select_first<StdPairRange>(), rng );
}
template<class StdPairRange>
inline select_second_const_range<StdPairRange>
values(const StdPairRange& rng)
{
return select_second_const_range<StdPairRange>(
range_detail::select_second_const<StdPairRange>(), rng );
}
template<class StdPairRange>
inline select_second_mutable_range<StdPairRange>
values(StdPairRange& rng)
{
return select_second_mutable_range<StdPairRange>(
range_detail::select_second_mutable<StdPairRange>(), rng );
}
} // 'adaptors'
}
#endif

View File

@ -0,0 +1,134 @@
// Boost.Range library
//
// Copyright Neil Groves 2007. 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_ADAPTOR_REPLACED_IMPL_HPP_INCLUDED
#define BOOST_RANGE_ADAPTOR_REPLACED_IMPL_HPP_INCLUDED
#include <boost/config.hpp>
#include <boost/range/adaptor/argument_fwd.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/value_type.hpp>
#include <boost/iterator/iterator_adaptor.hpp>
#include <boost/iterator/transform_iterator.hpp>
namespace boost
{
namespace range_detail
{
template< class Value >
class replace_value
{
public:
typedef const Value& result_type;
typedef const Value& first_argument_type;
replace_value(const Value& from, const Value& to)
: _from(from), _to(to)
{
}
const Value& operator()(const Value& x) const
{
return (x == _from) ? _to : x;
}
private:
Value _from;
Value _to;
};
template< class R >
class replace_range :
public boost::iterator_range<
boost::transform_iterator<
replace_value< BOOST_DEDUCED_TYPENAME range_value<R>::type >,
BOOST_DEDUCED_TYPENAME range_iterator<R>::type > >
{
private:
typedef replace_value< BOOST_DEDUCED_TYPENAME range_value<R>::type > Fn;
typedef boost::iterator_range<
boost::transform_iterator<
replace_value< BOOST_DEDUCED_TYPENAME range_value<R>::type >,
BOOST_DEDUCED_TYPENAME range_iterator<R>::type > > base_t;
public:
typedef BOOST_DEDUCED_TYPENAME range_value<R>::type value_type;
replace_range( R& r, value_type from, value_type to )
: base_t( make_transform_iterator( boost::begin(r), Fn(from, to) ),
make_transform_iterator( boost::end(r), Fn(from, to) ) )
{ }
};
template< class T >
class replace_holder : public holder2<T>
{
public:
replace_holder( const T& from, const T& to )
: holder2<T>(from, to)
{ }
private:
// not assignable
void operator=(const replace_holder&);
};
template< class InputRng >
inline replace_range<InputRng>
operator|( InputRng& r,
const replace_holder<BOOST_DEDUCED_TYPENAME range_value<InputRng>::type>& f )
{
return replace_range<InputRng>(r, f.val1, f.val2);
}
template< class InputRng >
inline replace_range<const InputRng>
operator|( const InputRng& r,
const replace_holder<BOOST_DEDUCED_TYPENAME range_value<InputRng>::type>& f )
{
return replace_range<const InputRng>(r, f.val1, f.val2);
}
} // 'range_detail'
using range_detail::replace_range;
namespace adaptors
{
namespace
{
const range_detail::forwarder2<range_detail::replace_holder>
replaced =
range_detail::forwarder2<range_detail::replace_holder>();
}
template<class InputRange>
inline replace_range<InputRange>
replace(InputRange& rng,
BOOST_DEDUCED_TYPENAME range_value<InputRange>::type from,
BOOST_DEDUCED_TYPENAME range_value<InputRange>::type to)
{
return replace_range<InputRange>(rng, from, to);
}
template<class InputRange>
inline replace_range<const InputRange>
replace(const InputRange& rng,
BOOST_DEDUCED_TYPENAME range_value<const InputRange>::type from,
BOOST_DEDUCED_TYPENAME range_value<const InputRange>::type to)
{
return replace_range<const InputRange>(rng, from ,to);
}
} // 'adaptors'
} // 'boost'
#endif // include guard

View File

@ -0,0 +1,136 @@
// Boost.Range library
//
// Copyright Neil Groves 2007. 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_ADAPTOR_REPLACED_IF_IMPL_HPP_INCLUDED
#define BOOST_RANGE_ADAPTOR_REPLACED_IF_IMPL_HPP_INCLUDED
#include <boost/config.hpp>
#include <boost/range/adaptor/argument_fwd.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/value_type.hpp>
#include <boost/iterator/iterator_adaptor.hpp>
#include <boost/iterator/transform_iterator.hpp>
namespace boost
{
namespace range_detail
{
template< class Pred, class Value >
class replace_value_if
{
public:
typedef const Value& result_type;
typedef const Value& first_argument_type;
replace_value_if(const Pred& pred, const Value& to)
: m_pred(pred), m_to(to)
{
}
const Value& operator()(const Value& x) const
{
return m_pred(x) ? m_to : x;
}
private:
Pred m_pred;
Value m_to;
};
template< class Pred, class R >
class replace_if_range :
public boost::iterator_range<
boost::transform_iterator<
replace_value_if< Pred, BOOST_DEDUCED_TYPENAME range_value<R>::type >,
BOOST_DEDUCED_TYPENAME range_iterator<R>::type > >
{
private:
typedef replace_value_if< Pred, BOOST_DEDUCED_TYPENAME range_value<R>::type > Fn;
typedef boost::iterator_range<
boost::transform_iterator<
replace_value_if< Pred, BOOST_DEDUCED_TYPENAME range_value<R>::type >,
BOOST_DEDUCED_TYPENAME range_iterator<R>::type > > base_t;
public:
typedef BOOST_DEDUCED_TYPENAME range_value<R>::type value_type;
replace_if_range( R& r, const Pred& pred, value_type to )
: base_t( make_transform_iterator( boost::begin(r), Fn(pred, to) ),
make_transform_iterator( boost::end(r), Fn(pred, to) ) )
{ }
};
template< class Pred, class T >
class replace_if_holder
{
public:
replace_if_holder( const Pred& pred, const T& to )
: m_pred(pred), m_to(to)
{ }
const Pred& pred() const { return m_pred; }
const T& to() const { return m_to; }
private:
Pred m_pred;
T m_to;
};
template< class Pred, class InputRng >
inline replace_if_range<Pred, InputRng>
operator|( InputRng& r,
const replace_if_holder<Pred, BOOST_DEDUCED_TYPENAME range_value<InputRng>::type>& f )
{
return replace_if_range<Pred, InputRng>(r, f.pred(), f.to());
}
template< class Pred, class InputRng >
inline replace_if_range<Pred, const InputRng>
operator|( const InputRng& r,
const replace_if_holder<Pred, BOOST_DEDUCED_TYPENAME range_value<InputRng>::type>& f )
{
return replace_if_range<Pred, const InputRng>(r, f.pred(), f.to());
}
} // 'range_detail'
using range_detail::replace_if_range;
namespace adaptors
{
namespace
{
const range_detail::forwarder2TU<range_detail::replace_if_holder>
replaced_if =
range_detail::forwarder2TU<range_detail::replace_if_holder>();
}
template<class Pred, class InputRange>
inline replace_if_range<Pred, InputRange>
replace_if(InputRange& rng, Pred pred,
BOOST_DEDUCED_TYPENAME range_value<InputRange>::type to)
{
return range_detail::replace_if_range<Pred, InputRange>(rng, pred, to);
}
template<class Pred, class InputRange>
inline replace_if_range<Pred, const InputRange>
replace_if(const InputRange& rng, Pred pred,
BOOST_DEDUCED_TYPENAME range_value<const InputRange>::type to)
{
return range_detail::replace_if_range<Pred, const InputRange>(rng, pred, to);
}
} // 'adaptors'
} // 'boost'
#endif // include guard

View File

@ -0,0 +1,90 @@
// Boost.Range library
//
// Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. 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_ADAPTOR_REVERSED_HPP
#define BOOST_RANGE_ADAPTOR_REVERSED_HPP
#include <boost/range/iterator_range.hpp>
#include <boost/iterator/reverse_iterator.hpp>
namespace boost
{
namespace range_detail
{
template< class R >
struct reverse_range :
public boost::iterator_range<
boost::reverse_iterator<
BOOST_DEDUCED_TYPENAME range_iterator<R>::type
>
>
{
private:
typedef boost::iterator_range<
boost::reverse_iterator<
BOOST_DEDUCED_TYPENAME range_iterator<R>::type
>
>
base;
public:
typedef boost::reverse_iterator<BOOST_DEDUCED_TYPENAME range_iterator<R>::type> iterator;
reverse_range( R& r )
: base( iterator(boost::end(r)), iterator(boost::begin(r)) )
{ }
};
struct reverse_forwarder {};
template< class BidirectionalRng >
inline reverse_range<BidirectionalRng>
operator|( BidirectionalRng& r, reverse_forwarder )
{
return reverse_range<BidirectionalRng>( r );
}
template< class BidirectionalRng >
inline reverse_range<const BidirectionalRng>
operator|( const BidirectionalRng& r, reverse_forwarder )
{
return reverse_range<const BidirectionalRng>( r );
}
} // 'range_detail'
using range_detail::reverse_range;
namespace adaptors
{
namespace
{
const range_detail::reverse_forwarder reversed =
range_detail::reverse_forwarder();
}
template<class BidirectionalRange>
inline reverse_range<BidirectionalRange>
reverse(BidirectionalRange& rng)
{
return reverse_range<BidirectionalRange>(rng);
}
template<class BidirectionalRange>
inline reverse_range<const BidirectionalRange>
reverse(const BidirectionalRange& rng)
{
return reverse_range<const BidirectionalRange>(rng);
}
} // 'adaptors'
} // 'boost'
#endif

View File

@ -0,0 +1,92 @@
// Boost.Range library
//
// Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. 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_ADAPTOR_SLICED_HPP
#define BOOST_RANGE_ADAPTOR_SLICED_HPP
#include <boost/range/adaptor/argument_fwd.hpp>
#include <boost/range/size_type.hpp>
#include <boost/range/iterator_range.hpp>
namespace boost
{
namespace adaptors
{
template< class RandomAccessRange >
inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<RandomAccessRange>::type >
slice( RandomAccessRange& rng, std::size_t t, std::size_t u )
{
BOOST_ASSERT( t <= u && "error in slice indices" );
BOOST_ASSERT( static_cast<std::size_t>(boost::size(rng)) >= u &&
"second slice index out of bounds" );
return make_iterator_range( rng, t, u - boost::size(rng) );
}
template< class RandomAccessRange >
inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<const RandomAccessRange>::type >
slice( const RandomAccessRange& rng, std::size_t t, std::size_t u )
{
BOOST_ASSERT( t <= u && "error in slice indices" );
BOOST_ASSERT( static_cast<std::size_t>(boost::size(rng)) >= u &&
"second slice index out of bounds" );
return make_iterator_range( rng, t, u - boost::size(rng) );
}
} // 'adaptors'
namespace range_detail
{
template< class T >
struct slice_holder
: holder2<std::size_t>
{
slice_holder( std::size_t t, std::size_t u )
: holder2<std::size_t>(t,u)
{ }
};
template<class R, class H>
inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<R>::type >
sliced_impl( R& r, const H& f)
{
return adaptors::slice(r, f.val1, f.val2);
}
template< class RandomAccessRange, class Int >
inline iterator_range<
BOOST_DEDUCED_TYPENAME range_iterator<RandomAccessRange>::type >
operator|( RandomAccessRange& r, const slice_holder<Int>& f )
{
return sliced_impl( r, f );
}
template< class RandomAccessRange, class Int >
inline iterator_range<
BOOST_DEDUCED_TYPENAME range_iterator<const RandomAccessRange>::type >
operator|( const RandomAccessRange& r, const slice_holder<Int>& f )
{
return sliced_impl( r, f );
}
} // 'range_detail'
namespace adaptors
{
namespace
{
const range_detail::forwarder2<range_detail::slice_holder>
sliced = range_detail::forwarder2<range_detail::slice_holder>();
}
}
}
#endif

View File

@ -0,0 +1,149 @@
// Boost.Range library
//
// Copyright Neil Groves 2007. 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_ADAPTOR_STRIDED_HPP_INCLUDED
#define BOOST_RANGE_ADAPTOR_STRIDED_HPP_INCLUDED
#include <boost/range/adaptor/argument_fwd.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/iterator/iterator_adaptor.hpp>
#include <iterator>
namespace boost
{
namespace range_detail
{
template<typename BaseIterator>
class strided_iterator
: public iterator_adaptor<
strided_iterator<BaseIterator>,
BaseIterator>
{
friend class iterator_core_access;
typedef iterator_adaptor<strided_iterator<BaseIterator>, BaseIterator> super_t;
public:
typedef BOOST_DEDUCED_TYPENAME std::iterator_traits<BaseIterator>::difference_type difference_type;
strided_iterator() : m_stride() { }
strided_iterator(const strided_iterator& other)
: super_t(other), m_stride(other.m_stride) { }
explicit strided_iterator(BaseIterator base_it, difference_type stride)
: super_t(base_it), m_stride(stride) { }
strided_iterator&
operator=(const strided_iterator& other)
{
super_t::operator=(other);
// Is the interoperation of the stride safe?
m_stride = other.m_stride;
return *this;
}
void increment() { std::advance(this->base_reference(), m_stride); }
void decrement() { std::advance(this->base_reference(), -m_stride); }
void advance(difference_type n) { std::advance(this->base_reference(), n * m_stride); }
difference_type
distance_to(const strided_iterator& other) const
{
return std::distance(this->base_reference(), other.base_reference()) / m_stride;
}
// Using the compiler generated copy constructor and
// and assignment operator
private:
difference_type m_stride;
};
template<class BaseIterator> inline
strided_iterator<BaseIterator>
make_strided_iterator(
const BaseIterator& first,
BOOST_DEDUCED_TYPENAME std::iterator_traits<BaseIterator>::difference_type stride)
{
return strided_iterator<BaseIterator>(first, stride);
}
template< class Rng >
class strided_range
: public iterator_range<range_detail::strided_iterator<BOOST_DEDUCED_TYPENAME range_iterator<Rng>::type> >
{
typedef range_detail::strided_iterator<BOOST_DEDUCED_TYPENAME range_iterator<Rng>::type> iter_type;
typedef iterator_range<iter_type> super_t;
public:
template< typename Difference >
strided_range(Difference stride, Rng& rng)
: super_t(make_strided_iterator(boost::begin(rng), stride),
make_strided_iterator(boost::end(rng), stride))
{
}
};
template<class Difference>
class strided_holder : public holder<Difference>
{
public:
strided_holder(Difference value) : holder<Difference>(value) {}
};
template<class Rng, class Difference>
inline strided_range<Rng>
operator|(Rng& rng, const strided_holder<Difference>& stride)
{
return strided_range<Rng>(stride.val, rng);
}
template<class Rng, class Difference>
inline strided_range<const Rng>
operator|(const Rng& rng, const strided_holder<Difference>& stride)
{
return strided_range<const Rng>(stride.val, rng);
}
} // namespace range_detail
using range_detail::strided_range;
namespace adaptors
{
namespace
{
const range_detail::forwarder<range_detail::strided_holder>
strided = range_detail::forwarder<range_detail::strided_holder>();
}
template<class Range, class Difference>
inline strided_range<Range>
stride(Range& rng, Difference step)
{
return strided_range<Range>(step, rng);
}
template<class Range, class Difference>
inline strided_range<const Range>
stride(const Range& rng, Difference step)
{
return strided_range<const Range>(step, rng);
}
} // namespace 'adaptors'
} // namespace 'boost'
#endif

View File

@ -0,0 +1,137 @@
// Boost.Range library
//
// Copyright Thorsten Ottosen, Neil Groves 2006. 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_ADAPTOR_TOKENIZED_HPP
#define BOOST_RANGE_ADAPTOR_TOKENIZED_HPP
#include <boost/regex.hpp>
#include <boost/range/iterator_range.hpp>
namespace boost
{
namespace range_detail
{
template< class R >
struct token_range :
public boost::iterator_range<
boost::regex_token_iterator<
BOOST_DEDUCED_TYPENAME range_iterator<R>::type
>
>
{
private:
typedef
boost::regex_token_iterator<
BOOST_DEDUCED_TYPENAME range_iterator<R>::type
>
regex_iter;
typedef BOOST_DEDUCED_TYPENAME regex_iter::regex_type
regex_type;
typedef boost::iterator_range<regex_iter>
base;
public:
template< class Regex, class Submatch, class Flag >
token_range( R& r, const Regex& re, const Submatch& sub, Flag f )
: base( regex_iter( boost::begin(r), boost::end(r),
regex_type(re), sub, f ),
regex_iter() )
{ }
};
template< class T, class U, class V >
struct regex_holder
{
const T& re;
const U& sub;
V f;
regex_holder( const T& rex, const U& subm, V flag ) :
re(rex), sub(subm), f(flag)
{ }
private:
// Not assignable
void operator=(const regex_holder&);
};
struct regex_forwarder
{
template< class Regex >
regex_holder<Regex,int,regex_constants::match_flag_type>
operator()( const Regex& re,
int submatch = 0,
regex_constants::match_flag_type f =
regex_constants::match_default ) const
{
return regex_holder<Regex,int,
regex_constants::match_flag_type>( re, submatch, f );
}
template< class Regex, class Submatch >
regex_holder<Regex,Submatch,regex_constants::match_flag_type>
operator()( const Regex& re,
const Submatch& sub,
regex_constants::match_flag_type f =
regex_constants::match_default ) const
{
return regex_holder<Regex,Submatch,
regex_constants::match_flag_type>( re, sub, f );
}
};
template< class BidirectionalRng, class R, class S, class F >
inline token_range<BidirectionalRng>
operator|( BidirectionalRng& r,
const regex_holder<R,S,F>& f )
{
return token_range<BidirectionalRng>( r, f.re, f.sub, f.f );
}
template< class BidirectionalRng, class R, class S, class F >
inline token_range<const BidirectionalRng>
operator|( const BidirectionalRng& r,
const regex_holder<R,S,F>& f )
{
return token_range<const BidirectionalRng>( r, f.re, f.sub, f.f );
}
} // 'range_detail'
using range_detail::token_range;
namespace adaptors
{
namespace
{
const range_detail::regex_forwarder tokenized =
range_detail::regex_forwarder();
}
template<class BidirectionalRange, class Regex, class Submatch, class Flag>
inline token_range<BidirectionalRange>
tokenize(BidirectionalRange& rng, const Regex& reg, const Submatch& sub, Flag f)
{
return token_range<BidirectionalRange>(rng, reg, sub, f);
}
template<class BidirectionalRange, class Regex, class Submatch, class Flag>
inline token_range<const BidirectionalRange>
tokenize(const BidirectionalRange& rng, const Regex& reg, const Submatch& sub, Flag f)
{
return token_range<const BidirectionalRange>(rng, reg, sub, f);
}
} // 'adaptors'
}
#endif

View File

@ -0,0 +1,103 @@
// Boost.Range library
//
// Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. 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_ADAPTOR_TRANSFORMED_HPP
#define BOOST_RANGE_ADAPTOR_TRANSFORMED_HPP
#include <boost/range/adaptor/argument_fwd.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/iterator/transform_iterator.hpp>
namespace boost
{
namespace range_detail
{
template< class F, class R >
struct transform_range :
public boost::iterator_range<
boost::transform_iterator< F,
BOOST_DEDUCED_TYPENAME range_iterator<R>::type
>
>
{
private:
typedef boost::iterator_range<
boost::transform_iterator< F,
BOOST_DEDUCED_TYPENAME range_iterator<R>::type
>
>
base;
public:
typedef F transform_fn_type;
typedef R source_range_type;
transform_range( F f, R& r )
: base( make_transform_iterator( boost::begin(r), f ),
make_transform_iterator( boost::end(r), f ) )
{ }
};
template< class T >
struct transform_holder : holder<T>
{
transform_holder( T r ) : holder<T>(r)
{ }
};
template< class InputRng, class UnaryFunction >
inline transform_range<UnaryFunction,InputRng>
operator|( InputRng& r,
const transform_holder<UnaryFunction>& f )
{
return transform_range<UnaryFunction,InputRng>( f.val, r );
}
template< class InputRng, class UnaryFunction >
inline transform_range<UnaryFunction, const InputRng>
operator|( const InputRng& r,
const transform_holder<UnaryFunction>& f )
{
return transform_range<UnaryFunction, const InputRng>( f.val, r );
}
} // 'range_detail'
using range_detail::transform_range;
namespace adaptors
{
namespace
{
const range_detail::forwarder<range_detail::transform_holder>
transformed =
range_detail::forwarder<range_detail::transform_holder>();
}
template<class UnaryFunction, class InputRange>
inline transform_range<UnaryFunction, InputRange>
transform(InputRange& rng, UnaryFunction fn)
{
return transform_range<UnaryFunction, InputRange>(fn, rng);
}
template<class UnaryFunction, class InputRange>
inline transform_range<UnaryFunction, const InputRange>
transform(const InputRange& rng, UnaryFunction fn)
{
return transform_range<UnaryFunction, const InputRange>(fn, rng);
}
} // 'adaptors'
}
#endif

View File

@ -0,0 +1,90 @@
// Boost.Range library
//
// Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. 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_ADAPTOR_UNIQUED_IMPL_HPP
#define BOOST_RANGE_ADAPTOR_UNIQUED_IMPL_HPP
#include <boost/range/adaptor/adjacent_filtered.hpp>
namespace boost
{
namespace range_detail
{
struct unique_forwarder { };
struct unique_not_equal_to
{
typedef bool result_type;
template< class T >
bool operator()( const T& l, const T& r ) const
{
return !(l == r);
}
};
template<class ForwardRng>
class unique_range : public adjacent_filter_range<unique_not_equal_to, ForwardRng>
{
typedef adjacent_filter_range<unique_not_equal_to, ForwardRng> base;
public:
explicit unique_range(ForwardRng& rng)
: base(unique_not_equal_to(), rng, true)
{
}
};
template< class ForwardRng >
inline unique_range<ForwardRng>
operator|( ForwardRng& r,
unique_forwarder )
{
return unique_range<ForwardRng>(r);
}
template< class ForwardRng >
inline unique_range<const ForwardRng>
operator|( const ForwardRng& r,
unique_forwarder )
{
return unique_range<const ForwardRng>(r);
}
} // 'range_detail'
using range_detail::unique_range;
namespace adaptors
{
namespace
{
const range_detail::unique_forwarder uniqued =
range_detail::unique_forwarder();
}
template<class ForwardRange>
inline unique_range<ForwardRange>
unique(ForwardRange& rng)
{
return unique_range<ForwardRange>(rng);
}
template<class ForwardRange>
inline unique_range<const ForwardRange>
unique(const ForwardRange& rng)
{
return unique_range<const ForwardRange>(rng);
}
} // 'adaptors'
}
#endif

View File

@ -0,0 +1,29 @@
// Boost.Range library
//
// Copyright Neil Groves 2007.
// Copyright Thorsten Ottosen 2006.
// 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_ADAPTORS_HPP
#define BOOST_RANGE_ADAPTORS_HPP
#include <boost/range/adaptor/adjacent_filtered.hpp>
#include <boost/range/adaptor/copied.hpp>
#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/adaptor/indexed.hpp>
#include <boost/range/adaptor/indirected.hpp>
#include <boost/range/adaptor/map.hpp>
#include <boost/range/adaptor/replaced.hpp>
#include <boost/range/adaptor/replaced_if.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/adaptor/sliced.hpp>
#include <boost/range/adaptor/tokenized.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <boost/range/adaptor/uniqued.hpp>
#endif

104
include/boost/range/algorithm.hpp Executable file
View File

@ -0,0 +1,104 @@
///////////////////////////////////////////////////////////////////////////////
/// \file algorithm.hpp
/// Includes the range-based versions of the algorithms in the
/// C++ standard header file <algorithm>
//
/////////////////////////////////////////////////////////////////////////////
// Copyright 2009 Neil Groves.
// Distributed under 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)
//
// Acknowledgements:
// This code uses combinations of ideas, techniques and code snippets
// from: Thorsten Ottosen, Eric Niebler, Jeremy Siek,
// and Vladimir Prus'
//
// The original mutating algorithms that served as the first version
// were originally written by Vladimir Prus'
// <ghost@cs.msu.su> code from Boost Wiki
#if defined(_MSC_VER) && _MSC_VER >= 1000
#pragma once
#endif
#ifndef BOOST_RANGE_ALGORITHM_HPP_INCLUDED_01012009
#define BOOST_RANGE_ALGORITHM_HPP_INCLUDED_01012009
#include <boost/range/concepts.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/range/difference_type.hpp>
#include <boost/range/detail/range_return.hpp>
#include <boost/iterator/iterator_traits.hpp>
#include <boost/next_prior.hpp>
#include <algorithm>
// Non-mutating algorithms
#include <boost/range/algorithm/adjacent_find.hpp>
#include <boost/range/algorithm/count.hpp>
#include <boost/range/algorithm/count_if.hpp>
#include <boost/range/algorithm/equal.hpp>
#include <boost/range/algorithm/for_each.hpp>
#include <boost/range/algorithm/find.hpp>
#include <boost/range/algorithm/find_end.hpp>
#include <boost/range/algorithm/find_first_of.hpp>
#include <boost/range/algorithm/find_if.hpp>
#include <boost/range/algorithm/lexicographical_compare.hpp>
#include <boost/range/algorithm/mismatch.hpp>
#include <boost/range/algorithm/search.hpp>
#include <boost/range/algorithm/search_n.hpp>
// Mutating algorithms
#include <boost/range/algorithm/copy.hpp>
#include <boost/range/algorithm/copy_backward.hpp>
#include <boost/range/algorithm/fill.hpp>
#include <boost/range/algorithm/fill_n.hpp>
#include <boost/range/algorithm/generate.hpp>
#include <boost/range/algorithm/inplace_merge.hpp>
#include <boost/range/algorithm/merge.hpp>
#include <boost/range/algorithm/nth_element.hpp>
#include <boost/range/algorithm/partial_sort.hpp>
#include <boost/range/algorithm/partial_sort_copy.hpp>
#include <boost/range/algorithm/partition.hpp>
#include <boost/range/algorithm/random_shuffle.hpp>
#include <boost/range/algorithm/remove.hpp>
#include <boost/range/algorithm/remove_copy.hpp>
#include <boost/range/algorithm/remove_copy_if.hpp>
#include <boost/range/algorithm/remove_if.hpp>
#include <boost/range/algorithm/replace.hpp>
#include <boost/range/algorithm/replace_copy.hpp>
#include <boost/range/algorithm/replace_copy_if.hpp>
#include <boost/range/algorithm/replace_if.hpp>
#include <boost/range/algorithm/reverse.hpp>
#include <boost/range/algorithm/reverse_copy.hpp>
#include <boost/range/algorithm/rotate.hpp>
#include <boost/range/algorithm/rotate_copy.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/algorithm/stable_partition.hpp>
#include <boost/range/algorithm/stable_sort.hpp>
#include <boost/range/algorithm/transform.hpp>
#include <boost/range/algorithm/unique.hpp>
#include <boost/range/algorithm/unique_copy.hpp>
// Binary search
#include <boost/range/algorithm/binary_search.hpp>
#include <boost/range/algorithm/equal_range.hpp>
#include <boost/range/algorithm/lower_bound.hpp>
#include <boost/range/algorithm/upper_bound.hpp>
// Set operations of sorted ranges
#include <boost/range/algorithm/set_algorithm.hpp>
// Heap operations
#include <boost/range/algorithm/heap_algorithm.hpp>
// Minimum and Maximum
#include <boost/range/algorithm/max_element.hpp>
#include <boost/range/algorithm/min_element.hpp>
// Permutations
#include <boost/range/algorithm/permutation.hpp>
#endif // include guard

View File

@ -0,0 +1,119 @@
// 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_ADJACENT_FIND_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_ADJACENT_FIND_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 <boost/range/detail/range_return.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function adjacent_find
///
/// range-based version of the adjacent_find std algorithm
///
/// \pre ForwardRange is a model of the ForwardRangeConcept
/// \pre BinaryPredicate is a model of the BinaryPredicateConcept
template< typename ForwardRange >
inline typename range_iterator<ForwardRange>::type
adjacent_find(ForwardRange & rng)
{
BOOST_CONCEPT_ASSERT((ForwardRangeConcept<ForwardRange>));
return std::adjacent_find(boost::begin(rng),boost::end(rng));
}
/// \overload
template< typename ForwardRange >
inline typename range_iterator<const ForwardRange>::type
adjacent_find(const ForwardRange& rng)
{
BOOST_CONCEPT_ASSERT((ForwardRangeConcept<ForwardRange>));
return std::adjacent_find(boost::begin(rng),boost::end(rng));
}
/// \overload
template< typename ForwardRange, typename BinaryPredicate >
inline typename range_iterator<ForwardRange>::type
adjacent_find(ForwardRange & rng, BinaryPredicate pred)
{
BOOST_CONCEPT_ASSERT((ForwardRangeConcept<ForwardRange>));
BOOST_CONCEPT_ASSERT((BinaryPredicateConcept<BinaryPredicate,
typename range_value<ForwardRange>::type,
typename range_value<ForwardRange>::type>));
return std::adjacent_find(boost::begin(rng),boost::end(rng),pred);
}
/// \overload
template< typename ForwardRange, typename BinaryPredicate >
inline typename range_iterator<const ForwardRange>::type
adjacent_find(const ForwardRange& rng, BinaryPredicate pred)
{
BOOST_CONCEPT_ASSERT((ForwardRangeConcept<ForwardRange>));
BOOST_CONCEPT_ASSERT((BinaryPredicateConcept<BinaryPredicate,
typename range_value<const ForwardRange>::type,
typename range_value<const ForwardRange>::type>));
return std::adjacent_find(boost::begin(rng),boost::end(rng),pred);
}
// range_return overloads
/// \overload
template< range_return_value re, typename ForwardRange >
inline typename range_return<ForwardRange,re>::type
adjacent_find(ForwardRange & rng)
{
BOOST_CONCEPT_ASSERT((ForwardRangeConcept<ForwardRange>));
return range_return<ForwardRange,re>::
pack(std::adjacent_find(boost::begin(rng),boost::end(rng)),
rng);
}
/// \overload
template< range_return_value re, typename ForwardRange >
inline typename range_return<const ForwardRange,re>::type
adjacent_find(const ForwardRange& rng)
{
BOOST_CONCEPT_ASSERT((ForwardRangeConcept<ForwardRange>));
return range_return<const ForwardRange,re>::
pack(std::adjacent_find(boost::begin(rng),boost::end(rng)),
rng);
}
/// \overload
template< range_return_value re, typename ForwardRange, typename BinaryPredicate >
inline typename range_return<ForwardRange,re>::type
adjacent_find(ForwardRange& rng, BinaryPredicate pred)
{
BOOST_CONCEPT_ASSERT((ForwardRangeConcept<ForwardRange>));
BOOST_CONCEPT_ASSERT((BinaryPredicateConcept<BinaryPredicate,
typename range_value<ForwardRange>::type,
typename range_value<ForwardRange>::type>));
return range_return<ForwardRange,re>::
pack(std::adjacent_find(boost::begin(rng),boost::end(rng),pred),
rng);
}
/// \overload
template< range_return_value re, typename ForwardRange, typename BinaryPredicate >
inline typename range_return<const ForwardRange,re>::type
adjacent_find(const ForwardRange& rng, BinaryPredicate pred)
{
BOOST_CONCEPT_ASSERT((ForwardRangeConcept<ForwardRange>));
return range_return<const ForwardRange,re>::
pack(std::adjacent_find(boost::begin(rng),boost::end(rng),pred),
rng);
}
}
#endif // include guard

View File

@ -0,0 +1,43 @@
// 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_BINARY_SEARCH_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_BINARY_SEARCH_HPP_INCLUDED
#include <boost/concept_check.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/concepts.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function binary_search
///
/// range-based version of the binary_search std algorithm
///
/// \pre ForwardRange is a model of the ForwardRangeConcept
/// \pre BinaryPredicate is a model of the BinaryPredicateConcept
template<class ForwardRange, class Value>
inline bool binary_search(const ForwardRange& rng, const Value& val)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::binary_search(boost::begin(rng), boost::end(rng), val);
}
/// \overload
template<class ForwardRange, class Value, class BinaryPredicate>
inline bool binary_search(const ForwardRange& rng, const Value& val,
BinaryPredicate pred)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::binary_search(boost::begin(rng), boost::end(rng), val, pred);
}
}
#endif // include guard

View File

@ -0,0 +1,35 @@
// 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_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_COPY_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/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
template< class SinglePassRange, class OutputIterator >
inline OutputIterator copy(const SinglePassRange& rng, OutputIterator out)
{
//BOOST_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange> ));
return std::copy(boost::begin(rng),boost::end(rng),out);
}
}
#endif // include guard

View File

@ -0,0 +1,37 @@
// 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_BACKWARD_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_COPY_BACKWARD_HPP_INCLUDED
#include <boost/concept_check.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/concepts.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function copy_backward
///
/// range-based version of the copy_backwards std algorithm
///
/// \pre BidirectionalRange is a model of the BidirectionalRangeConcept
/// \pre BidirectionalTraversalWriteableIterator is a model of the BidirectionalIteratorConcept
/// \pre BidirectionalTraversalWriteableIterator is a model of the WriteableIteratorConcept
template< class BidirectionalRange, class BidirectionalTraversalWriteableIterator >
inline BidirectionalTraversalWriteableIterator
copy_backward(const BidirectionalRange& rng,
BidirectionalTraversalWriteableIterator out)
{
boost::function_requires< BidirectionalRangeConcept<BidirectionalRange> >();
return std::copy_backward(boost::begin(rng), boost::end(rng), out);
}
}
#endif // include guard

View File

@ -0,0 +1,44 @@
// 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_COUNT_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_COUNT_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/difference_type.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function count
///
/// range-based version of the count std algorithm
///
/// \pre SinglePassRange is a model of the SinglePassRangeConcept
template< class SinglePassRange, class Value >
inline BOOST_DEDUCED_TYPENAME range_difference<SinglePassRange>::type
count(SinglePassRange& rng, const Value& val)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange> >();
return std::count(boost::begin(rng), boost::end(rng), val);
}
/// \overload
template< class SinglePassRange, class Value >
inline BOOST_DEDUCED_TYPENAME range_difference<SinglePassRange const>::type
count(const SinglePassRange& rng, const Value& val)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange> >();
return std::count(boost::begin(rng), boost::end(rng), val);
}
}
#endif // include guard

View File

@ -0,0 +1,45 @@
// 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_COUNT_IF_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_COUNT_IF_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/difference_type.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function count_if
///
/// range-based version of the count_if std algorithm
///
/// \pre SinglePassRange is a model of the SinglePassRangeConcept
/// \pre UnaryPredicate is a model of the UnaryPredicateConcept
template< class SinglePassRange, class UnaryPredicate >
inline BOOST_DEDUCED_TYPENAME boost::range_difference<SinglePassRange>::type
count_if(SinglePassRange& rng, UnaryPredicate pred)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange> >();
return std::count_if(boost::begin(rng), boost::end(rng), pred);
}
/// \overload
template< class SinglePassRange, class UnaryPredicate >
inline BOOST_DEDUCED_TYPENAME boost::range_difference<const SinglePassRange>::type
count_if(const SinglePassRange& rng, UnaryPredicate pred)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange> >();
return std::count_if(boost::begin(rng), boost::end(rng), pred);
}
}
#endif // include guard

View File

@ -0,0 +1,182 @@
// 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_EQUAL_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_EQUAL_HPP_INCLUDED
#include <boost/config.hpp>
#include <boost/range/concepts.hpp>
#include <iterator>
namespace boost
{
namespace range_detail
{
// An implementation of equality comparison that is optimized for iterator
// traversal categories less than RandomAccessTraversal.
template< class SinglePassTraversalReadableIterator1,
class SinglePassTraversalReadableIterator2,
class IteratorCategoryTag1,
class IteratorCategoryTag2 >
inline bool equal_impl( SinglePassTraversalReadableIterator1 first1,
SinglePassTraversalReadableIterator1 last1,
SinglePassTraversalReadableIterator2 first2,
SinglePassTraversalReadableIterator2 last2,
IteratorCategoryTag1,
IteratorCategoryTag2 )
{
do
{
// If we have reached the end of the left range then this is
// the end of the loop. They are equal if and only if we have
// simultaneously reached the end of the right range.
if (first1 == last1)
return first2 == last2;
// If we have reached the end of the right range at this line
// it indicates that the right range is shorter than the left
// and hence the result is false.
if (first2 == last2)
return false;
// continue looping if and only if the values are equal
} while(*first1++ == *first2++);
// Reaching this line in the algorithm indicates that a value
// inequality has been detected.
return false;
}
template< class SinglePassTraversalReadableIterator1,
class SinglePassTraversalReadableIterator2,
class IteratorCategoryTag1,
class IteratorCategoryTag2,
class BinaryPredicate >
inline bool equal_impl( SinglePassTraversalReadableIterator1 first1,
SinglePassTraversalReadableIterator1 last1,
SinglePassTraversalReadableIterator2 first2,
SinglePassTraversalReadableIterator2 last2,
BinaryPredicate pred,
IteratorCategoryTag1,
IteratorCategoryTag2 )
{
do
{
// If we have reached the end of the left range then this is
// the end of the loop. They are equal if and only if we have
// simultaneously reached the end of the right range.
if (first1 == last1)
return first2 == last2;
// If we have reached the end of the right range at this line
// it indicates that the right range is shorter than the left
// and hence the result is false.
if (first2 == last2)
return false;
// continue looping if and only if the values are equal
} while(pred(*first1++, *first2++));
// Reaching this line in the algorithm indicates that a value
// inequality has been detected.
return false;
}
// An implementation of equality comparison that is optimized for
// random access iterators.
template< class RandomAccessTraversalReadableIterator1,
class RandomAccessTraversalReadableIterator2 >
inline bool equal_impl( RandomAccessTraversalReadableIterator1 first1,
RandomAccessTraversalReadableIterator1 last1,
RandomAccessTraversalReadableIterator2 first2,
RandomAccessTraversalReadableIterator2 last2,
std::random_access_iterator_tag,
std::random_access_iterator_tag )
{
return ((last1 - first1) == (last2 - first2))
&& std::equal(first1, last1, first2);
}
template< class RandomAccessTraversalReadableIterator1,
class RandomAccessTraversalReadableIterator2,
class BinaryPredicate >
inline bool equal_impl( RandomAccessTraversalReadableIterator1 first1,
RandomAccessTraversalReadableIterator1 last1,
RandomAccessTraversalReadableIterator2 first2,
RandomAccessTraversalReadableIterator2 last2,
BinaryPredicate pred )
{
return ((last1 - first1) == (last2 - first2))
&& std::equal(first1, last1, first2, pred);
}
template< class SinglePassTraversalReadableIterator1,
class SinglePassTraversalReadableIterator2 >
inline bool equal( SinglePassTraversalReadableIterator1 first1,
SinglePassTraversalReadableIterator1 last1,
SinglePassTraversalReadableIterator2 first2,
SinglePassTraversalReadableIterator2 last2 )
{
BOOST_DEDUCED_TYPENAME std::iterator_traits< SinglePassTraversalReadableIterator1 >::iterator_category tag1;
BOOST_DEDUCED_TYPENAME std::iterator_traits< SinglePassTraversalReadableIterator2 >::iterator_category tag2;
return equal_impl(first1, last1, first2, last2, tag1, tag2);
}
template< class SinglePassTraversalReadableIterator1,
class SinglePassTraversalReadableIterator2,
class BinaryPredicate >
inline bool equal( SinglePassTraversalReadableIterator1 first1,
SinglePassTraversalReadableIterator1 last1,
SinglePassTraversalReadableIterator2 first2,
SinglePassTraversalReadableIterator2 last2,
BinaryPredicate pred )
{
BOOST_DEDUCED_TYPENAME std::iterator_traits< SinglePassTraversalReadableIterator1 >::iterator_category tag1;
BOOST_DEDUCED_TYPENAME std::iterator_traits< SinglePassTraversalReadableIterator2 >::iterator_category tag2;
return equal_impl(first1, last1, first2, last2, pred, tag1, tag2);
}
}
/// \brief template function equal
///
/// range-based version of the equal std algorithm
///
/// \pre SinglePassRange1 is a model of the SinglePassRangeConcept
/// \pre SinglePassRange2 is a model of the SinglePassRangeConcept
/// \pre BinaryPredicate is a model of the BinaryPredicateConcept
template< class SinglePassRange1, class SinglePassRange2 >
inline bool equal( const SinglePassRange1& rng1, const SinglePassRange2& rng2 )
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< SinglePassRangeConcept<SinglePassRange2> >();
return range_detail::equal(
boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2) );
}
/// \overload
template< class SinglePassRange1, class SinglePassRange2, class BinaryPredicate >
inline bool equal( const SinglePassRange1& rng1, const SinglePassRange2& rng2,
BinaryPredicate pred )
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< SinglePassRangeConcept<SinglePassRange2> >();
return range_detail::equal(
boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2),
pred);
}
}
#endif // include guard

View File

@ -0,0 +1,74 @@
// 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_EQUAL_RANGE_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_EQUAL_RANGE_HPP_INCLUDED
#include <boost/concept_check.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/concepts.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function equal_range
///
/// range-based version of the equal_range std algorithm
///
/// \pre ForwardRange is a model of the ForwardRangeConcept
/// \pre SortPredicate is a model of the BinaryPredicateConcept
template<class ForwardRange, class Value>
inline std::pair<
BOOST_DEDUCED_TYPENAME boost::range_iterator<ForwardRange>::type,
BOOST_DEDUCED_TYPENAME boost::range_iterator<ForwardRange>::type
>
equal_range(ForwardRange& rng, const Value& val)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::equal_range(boost::begin(rng), boost::end(rng), val);
}
/// \overload
template<class ForwardRange, class Value>
inline std::pair<
BOOST_DEDUCED_TYPENAME boost::range_iterator<const ForwardRange>::type,
BOOST_DEDUCED_TYPENAME boost::range_iterator<const ForwardRange>::type
>
equal_range(const ForwardRange& rng, const Value& val)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::equal_range(boost::begin(rng), boost::end(rng), val);
}
/// \overload
template<class ForwardRange, class Value, class SortPredicate>
inline std::pair<
BOOST_DEDUCED_TYPENAME boost::range_iterator<ForwardRange>::type,
BOOST_DEDUCED_TYPENAME boost::range_iterator<ForwardRange>::type
>
equal_range(ForwardRange& rng, const Value& val, SortPredicate pred)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::equal_range(boost::begin(rng), boost::end(rng), val, pred);
}
/// \overload
template<class ForwardRange, class Value, class SortPredicate>
inline std::pair<
BOOST_DEDUCED_TYPENAME boost::range_iterator<const ForwardRange>::type,
BOOST_DEDUCED_TYPENAME boost::range_iterator<const ForwardRange>::type
>
equal_range(const ForwardRange& rng, const Value& val, SortPredicate pred)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::equal_range(boost::begin(rng), boost::end(rng), val, pred);
}
}
#endif // include guard

View File

@ -0,0 +1,34 @@
// 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_FILL_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_FILL_HPP_INCLUDED
#include <boost/concept_check.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/concepts.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function fill
///
/// range-based version of the fill std algorithm
///
/// \pre ForwardRange is a model of the ForwardRangeConcept
template< class ForwardRange, class Value >
inline ForwardRange& fill(ForwardRange& rng, const Value& val)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
std::fill(boost::begin(rng), boost::end(rng), val);
return rng;
}
}
#endif // include guard

View File

@ -0,0 +1,36 @@
// 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_FILL_N_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_FILL_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 <algorithm>
namespace boost
{
/// \brief template function fill_n
///
/// range-based version of the fill_n std algorithm
///
/// \pre ForwardRange is a model of the ForwardRangeConcept
template< class ForwardRange, class Size, class Value >
inline ForwardRange& fill_n(ForwardRange& rng, Size n, const Value& val)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
BOOST_ASSERT( static_cast<Size>(std::distance(boost::begin(rng), boost::end(rng))) >= n );
std::fill_n(boost::begin(rng), n, val);
return rng;
}
}
#endif // include guard

View File

@ -0,0 +1,66 @@
// 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_FIND_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_FIND_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/detail/range_return.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function find
///
/// range-based version of the find std algorithm
///
/// \pre SinglePassRange is a model of the SinglePassRangeConcept
template< class SinglePassRange, class Value >
inline BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type
find( SinglePassRange& rng, const Value& val )
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange> >();
return std::find(boost::begin(rng), boost::end(rng), val);
}
/// \overload
template< class SinglePassRange, class Value >
inline BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange>::type
find( const SinglePassRange& rng, const Value& val )
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange> >();
return std::find(boost::begin(rng), boost::end(rng), val);
}
// range_return overloads
/// \overload
template< range_return_value re, class SinglePassRange, class Value >
inline BOOST_DEDUCED_TYPENAME range_return<SinglePassRange,re>::type
find( SinglePassRange& rng, const Value& val )
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange> >();
return range_return<SinglePassRange,re>::
pack(std::find(boost::begin(rng), boost::end(rng), val),
rng);
}
/// \overload
template< range_return_value re, class SinglePassRange, class Value >
inline BOOST_DEDUCED_TYPENAME range_return<const SinglePassRange,re>::type
find( const SinglePassRange& rng, const Value& val )
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange> >();
return range_return<const SinglePassRange,re>::
pack(std::find(boost::begin(rng), boost::end(rng), val),
rng);
}
}
#endif // include guard

View File

@ -0,0 +1,136 @@
// 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_FIND_END_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_FIND_END_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/detail/range_return.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function find_end
///
/// range-based version of the find_end std algorithm
///
/// \pre ForwardRange1 is a model of the ForwardRangeConcept
/// \pre ForwardRange2 is a model of the ForwardRangeConcept
/// \pre BinaryPredicate is a model of the BinaryPredicateConcept
template< class ForwardRange1, class ForwardRange2 >
inline BOOST_DEDUCED_TYPENAME range_iterator< ForwardRange1 >::type
find_end(ForwardRange1 & rng1, ForwardRange2 const & rng2)
{
boost::function_requires< ForwardRangeConcept<ForwardRange1> >();
boost::function_requires< ForwardRangeConcept<ForwardRange2> >();
return std::find_end(boost::begin(rng1),boost::end(rng1),
boost::begin(rng2),boost::end(rng2));
}
/// \overload
template< class ForwardRange1, class ForwardRange2 >
inline BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange1>::type
find_end(ForwardRange1 const & rng1, ForwardRange2 const & rng2)
{
boost::function_requires< ForwardRangeConcept<ForwardRange1> >();
boost::function_requires< ForwardRangeConcept<ForwardRange2> >();
return std::find_end(boost::begin(rng1),boost::end(rng1),
boost::begin(rng2),boost::end(rng2));
}
/// \overload
template< class ForwardRange1, class ForwardRange2, class BinaryPredicate >
inline BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange1>::type
find_end(ForwardRange1 & rng1, ForwardRange2 const & rng2, BinaryPredicate pred)
{
boost::function_requires< ForwardRangeConcept<ForwardRange1> >();
boost::function_requires< ForwardRangeConcept<ForwardRange2> >();
return std::find_end(boost::begin(rng1),boost::end(rng1),
boost::begin(rng2),boost::end(rng2),pred);
}
/// \overload
template< class ForwardRange1, class ForwardRange2, class BinaryPredicate >
inline BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange1>::type
find_end(ForwardRange1 const & rng1, ForwardRange2 const & rng2, BinaryPredicate pred)
{
boost::function_requires< ForwardRangeConcept<ForwardRange1> >();
boost::function_requires< ForwardRangeConcept<ForwardRange2> >();
return std::find_end(boost::begin(rng1),boost::end(rng1),
boost::begin(rng2),boost::end(rng2),pred);
}
/// \overload
template< range_return_value re, class ForwardRange1, class ForwardRange2 >
inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange1,re>::type
find_end(ForwardRange1& rng1, const ForwardRange2& rng2)
{
boost::function_requires< ForwardRangeConcept<ForwardRange1> >();
boost::function_requires< ForwardRangeConcept<ForwardRange2> >();
return range_return<ForwardRange1,re>::
pack(std::find_end(boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2)),
rng1);
}
/// \overload
template< range_return_value re, class ForwardRange1, class ForwardRange2 >
inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange1,re>::type
find_end(const ForwardRange1& rng1, const ForwardRange2& rng2)
{
boost::function_requires< ForwardRangeConcept<ForwardRange1> >();
boost::function_requires< ForwardRangeConcept<ForwardRange2> >();
return range_return<const ForwardRange1,re>::
pack(std::find_end(boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2)),
rng1);
}
/// \overload
template< range_return_value re, class ForwardRange1, class ForwardRange2,
class BinaryPredicate >
inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange1,re>::type
find_end(ForwardRange1& rng1, const ForwardRange2& rng2, BinaryPredicate pred)
{
boost::function_requires< ForwardRangeConcept<ForwardRange1> >();
boost::function_requires< ForwardRangeConcept<ForwardRange2> >();
return range_return<ForwardRange1,re>::
pack(std::find_end(boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2), pred),
rng1);
}
/// \overload
template< range_return_value re, class ForwardRange1, class ForwardRange2,
class BinaryPredicate >
inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange1,re>::type
find_end(const ForwardRange1& rng1, const ForwardRange2& rng2,
BinaryPredicate pred)
{
boost::function_requires< ForwardRangeConcept<ForwardRange1> >();
boost::function_requires< ForwardRangeConcept<ForwardRange2> >();
return range_return<const ForwardRange1,re>::
pack(std::find_end(boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2), pred),
rng1);
}
}
#endif // include guard

View File

@ -0,0 +1,139 @@
// 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_FIND_FIRST_OF_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_FIND_FIRST_OF_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/detail/range_return.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function find_first_of
///
/// range-based version of the find_first_of std algorithm
///
/// \pre SinglePassRange1 is a model of the SinglePassRangeConcept
/// \pre ForwardRange2 is a model of the ForwardRangeConcept
/// \pre BinaryPredicate is a model of the BinaryPredicateConcept
template< class SinglePassRange1, class ForwardRange2 >
inline BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange1>::type
find_first_of(SinglePassRange1 & rng1, ForwardRange2 const & rng2)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< ForwardRangeConcept<ForwardRange2> >();
return std::find_first_of(boost::begin(rng1),boost::end(rng1),
boost::begin(rng2),boost::end(rng2));
}
/// \overload
template< class SinglePassRange1, class ForwardRange2 >
inline BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange1>::type
find_first_of(SinglePassRange1 const & rng1, ForwardRange2 const & rng2)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< ForwardRangeConcept<ForwardRange2> >();
return std::find_first_of(boost::begin(rng1),boost::end(rng1),
boost::begin(rng2),boost::end(rng2));
}
/// \overload
template< class SinglePassRange1, class ForwardRange2, class BinaryPredicate >
inline BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange1>::type
find_first_of(SinglePassRange1 & rng1, ForwardRange2 const & rng2, BinaryPredicate pred)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< ForwardRangeConcept<ForwardRange2> >();
return std::find_first_of(boost::begin(rng1),boost::end(rng1),
boost::begin(rng2),boost::end(rng2),pred);
}
/// \overload
template< class SinglePassRange1, class ForwardRange2, class BinaryPredicate >
inline BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange1>::type
find_first_of(const SinglePassRange1& rng1, const ForwardRange2& rng2,
BinaryPredicate pred)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< ForwardRangeConcept<ForwardRange2> >();
return std::find_first_of(boost::begin(rng1),boost::end(rng1),
boost::begin(rng2),boost::end(rng2),pred);
}
// range return overloads
/// \overload
template< range_return_value re, class SinglePassRange1, class ForwardRange2 >
inline BOOST_DEDUCED_TYPENAME range_return<SinglePassRange1,re>::type
find_first_of(SinglePassRange1& rng1, const ForwardRange2& rng2)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< ForwardRangeConcept<ForwardRange2> >();
return range_return<SinglePassRange1,re>::
pack(std::find_first_of(boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2)),
rng1);
}
/// \overload
template< range_return_value re, class SinglePassRange1, class ForwardRange2 >
inline BOOST_DEDUCED_TYPENAME range_return<const SinglePassRange1,re>::type
find_first_of(const SinglePassRange1& rng1, const ForwardRange2& rng2)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< ForwardRangeConcept<ForwardRange2> >();
return range_return<const SinglePassRange1,re>::
pack(std::find_first_of(boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2)),
rng1);
}
/// \overload
template< range_return_value re, class SinglePassRange1, class ForwardRange2,
class BinaryPredicate >
inline BOOST_DEDUCED_TYPENAME range_return<SinglePassRange1,re>::type
find_first_of(SinglePassRange1 & rng1, const ForwardRange2& rng2,
BinaryPredicate pred)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< ForwardRangeConcept<ForwardRange2> >();
return range_return<SinglePassRange1,re>::
pack(std::find_first_of(boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2), pred),
rng1);
}
/// \overload
template< range_return_value re, class SinglePassRange1, class ForwardRange2,
class BinaryPredicate >
inline BOOST_DEDUCED_TYPENAME range_return<const SinglePassRange1,re>::type
find_first_of(const SinglePassRange1& rng1, const ForwardRange2& rng2,
BinaryPredicate pred)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< ForwardRangeConcept<ForwardRange2> >();
return range_return<const SinglePassRange1,re>::
pack(std::find_first_of(boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2),pred),
rng1);
}
}
#endif // include guard

View File

@ -0,0 +1,69 @@
// 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_FIND_IF_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_FIND_IF_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/detail/range_return.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function find_if
///
/// range-based version of the find_if std algorithm
///
/// \pre SinglePassRange is a model of the SinglePassRangeConcept
/// \pre UnaryPredicate is a model of the UnaryPredicateConcept
template< class SinglePassRange, class UnaryPredicate >
inline BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type
find_if( SinglePassRange& rng, UnaryPredicate pred )
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange> >();
return std::find_if(boost::begin(rng), boost::end(rng), pred);
}
/// \overload
template< class SinglePassRange, class UnaryPredicate >
inline BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange>::type
find_if( const SinglePassRange& rng, UnaryPredicate pred )
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange> >();
return std::find_if(boost::begin(rng), boost::end(rng), pred);
}
// range_return overloads
/// \overload
template< range_return_value re, class SinglePassRange, class UnaryPredicate >
inline BOOST_DEDUCED_TYPENAME range_return<SinglePassRange,re>::type
find_if( SinglePassRange& rng, UnaryPredicate pred )
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange> >();
return range_return<SinglePassRange,re>::
pack(std::find_if(boost::begin(rng), boost::end(rng), pred),
rng);
}
/// \overload
template< range_return_value re, class SinglePassRange, class UnaryPredicate >
inline BOOST_DEDUCED_TYPENAME range_return<const SinglePassRange,re>::type
find_if( const SinglePassRange& rng, UnaryPredicate pred )
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange> >();
return range_return<const SinglePassRange,re>::
pack(std::find_if(boost::begin(rng), boost::end(rng), pred),
rng);
}
}
#endif // include guard

View File

@ -0,0 +1,42 @@
// 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_FOR_EACH_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_FOR_EACH_HPP_INCLUDED
#include <boost/concept_check.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/concepts.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function for_each
///
/// range-based version of the for_each std algorithm
///
/// \pre SinglePassRange is a model of the SinglePassRangeConcept
/// \pre UnaryFunction is a model of the UnaryFunctionConcept
template< class SinglePassRange, class UnaryFunction >
inline UnaryFunction for_each(SinglePassRange & rng, UnaryFunction fun)
{
boost::function_requires< SinglePassRangeConcept< SinglePassRange > >();
return std::for_each(boost::begin(rng),boost::end(rng),fun);
}
/// \overload
template< class SinglePassRange, class UnaryFunction >
inline UnaryFunction for_each(SinglePassRange const & rng, UnaryFunction fun)
{
boost::function_requires< SinglePassRangeConcept< SinglePassRange > >();
return std::for_each(boost::begin(rng),boost::end(rng),fun);
}
} // namespace boost
#endif // include guard

View File

@ -0,0 +1,44 @@
// 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_GENERATE_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_GENERATE_HPP_INCLUDED
#include <boost/concept_check.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/concepts.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function generate
///
/// range-based version of the generate std algorithm
///
/// \pre ForwardRange is a model of the ForwardRangeConcept
/// \pre Generator is a model of the UnaryFunctionConcept
template< class ForwardRange, class Generator >
inline ForwardRange& generate( ForwardRange& rng, Generator gen )
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
std::generate(boost::begin(rng), boost::end(rng), gen);
return rng;
}
/// \overload
template< class ForwardRange, class Generator >
inline const ForwardRange& generate(const ForwardRange& rng, Generator gen)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
std::generate(boost::begin(rng), boost::end(rng), gen);
return rng;
}
}
#endif // include guard

View File

@ -0,0 +1,169 @@
// 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_HEAP_ALGORITHM_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_HEAP_ALGORITHM_HPP_INCLUDED
#include <boost/concept_check.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/concepts.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function push_heap
///
/// range-based version of the push_heap std algorithm
///
/// \pre RandomAccessRange is a model of the RandomAccessRangeConcept
/// \pre Compare is a model of the BinaryPredicateConcept
template<class RandomAccessRange>
inline void push_heap(RandomAccessRange& rng)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::push_heap(boost::begin(rng), boost::end(rng));
}
/// \overload
template<class RandomAccessRange>
inline void push_heap(const RandomAccessRange& rng)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::push_heap(boost::begin(rng), boost::end(rng));
}
/// \overload
template<class RandomAccessRange, class Compare>
inline void push_heap(RandomAccessRange& rng, Compare comp_pred)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::push_heap(boost::begin(rng), boost::end(rng), comp_pred);
}
/// \overload
template<class RandomAccessRange, class Compare>
inline void push_heap(const RandomAccessRange& rng, Compare comp_pred)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::push_heap(boost::begin(rng), boost::end(rng), comp_pred);
}
/// \brief template function pop_heap
///
/// range-based version of the pop_heap std algorithm
///
/// \pre RandomAccessRange is a model of the RandomAccessRangeConcept
/// \pre Compare is a model of the BinaryPredicateConcept
template<class RandomAccessRange>
inline void pop_heap(RandomAccessRange& rng)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::pop_heap(boost::begin(rng), boost::end(rng));
}
/// \overload
template<class RandomAccessRange>
inline void pop_heap(const RandomAccessRange& rng)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::pop_heap(boost::begin(rng),boost::end(rng));
}
/// \overload
template<class RandomAccessRange, class Compare>
inline void pop_heap(RandomAccessRange& rng, Compare comp_pred)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::pop_heap(boost::begin(rng), boost::end(rng), comp_pred);
}
/// \overload
template<class RandomAccessRange, class Compare>
inline void pop_heap(const RandomAccessRange& rng, Compare comp_pred)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::pop_heap(boost::begin(rng), boost::end(rng), comp_pred);
}
/// \brief template function make_heap
///
/// range-based version of the make_heap std algorithm
///
/// \pre RandomAccessRange is a model of the RandomAccessRangeConcept
/// \pre Compare is a model of the BinaryPredicateConcept
template<class RandomAccessRange>
inline void make_heap(RandomAccessRange& rng)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::make_heap(boost::begin(rng), boost::end(rng));
}
/// \overload
template<class RandomAccessRange>
inline void make_heap(const RandomAccessRange& rng)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::make_heap(boost::begin(rng),boost::end(rng));
}
/// \overload
template<class RandomAccessRange, class Compare>
inline void make_heap(RandomAccessRange& rng, Compare comp_pred)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::make_heap(boost::begin(rng), boost::end(rng), comp_pred);
}
/// \overload
template<class RandomAccessRange, class Compare>
inline void make_heap(const RandomAccessRange& rng, Compare comp_pred)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::make_heap(boost::begin(rng), boost::end(rng), comp_pred);
}
/// \brief template function sort_heap
///
/// range-based version of the sort_heap std algorithm
///
/// \pre RandomAccessRange is a model of the RandomAccessRangeConcept
/// \pre Compare is a model of the BinaryPredicateConcept
template<class RandomAccessRange>
inline void sort_heap(RandomAccessRange& rng)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::sort_heap(boost::begin(rng), boost::end(rng));
}
/// \overload
template<class RandomAccessRange>
inline void sort_heap(const RandomAccessRange& rng)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::sort_heap(boost::begin(rng), boost::end(rng));
}
/// \overload
template<class RandomAccessRange, class Compare>
inline void sort_heap(RandomAccessRange& rng, Compare comp_pred)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::sort_heap(boost::begin(rng), boost::end(rng), comp_pred);
}
/// \overload
template<class RandomAccessRange, class Compare>
inline void sort_heap(const RandomAccessRange& rng, Compare comp_pred)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::sort_heap(boost::begin(rng), boost::end(rng), comp_pred);
}
}
#endif // include guard

View File

@ -0,0 +1,68 @@
// 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_INPLACE_MERGE_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_INPLACE_MERGE_HPP_INCLUDED
#include <boost/concept_check.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/concepts.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function inplace_merge
///
/// range-based version of the inplace_merge std algorithm
///
/// \pre BidirectionalRange is a model of the BidirectionalRangeConcept
/// \pre BinaryPredicate is a model of the BinaryPredicateConcept
template<class BidirectionalRange>
inline BidirectionalRange& inplace_merge(BidirectionalRange& rng,
BOOST_DEDUCED_TYPENAME range_iterator<BidirectionalRange>::type middle)
{
boost::function_requires< BidirectionalRangeConcept<BidirectionalRange> >();
std::inplace_merge(boost::begin(rng), middle, boost::end(rng));
return rng;
}
/// \overload
template<class BidirectionalRange>
inline const BidirectionalRange& inplace_merge(const BidirectionalRange& rng,
BOOST_DEDUCED_TYPENAME boost::range_iterator<const BidirectionalRange>::type middle)
{
boost::function_requires< BidirectionalRangeConcept<BidirectionalRange> >();
std::inplace_merge(boost::begin(rng), middle, boost::end(rng));
return rng;
}
/// \overload
template<class BidirectionalRange, class BinaryPredicate>
inline BidirectionalRange& inplace_merge(BidirectionalRange& rng,
BOOST_DEDUCED_TYPENAME boost::range_iterator<BidirectionalRange>::type middle,
BinaryPredicate pred)
{
boost::function_requires< BidirectionalRangeConcept<BidirectionalRange> >();
std::inplace_merge(boost::begin(rng), middle, boost::end(rng), pred);
return rng;
}
/// \overload
template<class BidirectionalRange, class BinaryPredicate>
inline const BidirectionalRange& inplace_merge(const BidirectionalRange& rng,
BOOST_DEDUCED_TYPENAME boost::range_iterator<const BidirectionalRange>::type middle,
BinaryPredicate pred)
{
boost::function_requires< BidirectionalRangeConcept<BidirectionalRange> >();
std::inplace_merge(boost::begin(rng), middle, boost::end(rng), pred);
return rng;
}
}
#endif // include guard

View File

@ -0,0 +1,52 @@
// 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_LEXICOGRAPHICAL_COMPARE_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_LEXICOGRAPHICAL_COMPARE_HPP_INCLUDED
#include <boost/concept_check.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/concepts.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function lexicographic_compare
///
/// range-based version of the lexicographic_compare std algorithm
///
/// \pre SinglePassRange1 is a model of the SinglePassRangeConcept
/// \pre SinglePassRange2 is a model of the SinglePassRangeConcept
template<class SinglePassRange1, class SinglePassRange2>
inline bool lexicographical_compare(const SinglePassRange1& rng1,
const SinglePassRange2& rng2)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< SinglePassRangeConcept<SinglePassRange2> >();
return std::lexicographical_compare(
boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2));
}
/// \overload
template<class SinglePassRange1, class SinglePassRange2,
class BinaryPredicate>
inline bool lexicographical_compare(const SinglePassRange1& rng1,
const SinglePassRange2& rng2,
BinaryPredicate pred)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< SinglePassRangeConcept<SinglePassRange2> >();
return std::lexicographical_compare(
boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2), pred);
}
}
#endif // include guard

View File

@ -0,0 +1,99 @@
// 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_LOWER_BOUND_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_LOWER_BOUND_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/detail/range_return.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function lower_bound
///
/// range-based version of the lower_bound std algorithm
///
/// \pre ForwardRange is a model of the ForwardRangeConcept
template< class ForwardRange, class Value >
inline BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type
lower_bound( ForwardRange& rng, Value val )
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::lower_bound(boost::begin(rng), boost::end(rng), val);
}
/// \overload
template< class ForwardRange, class Value >
inline BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type
lower_bound( const ForwardRange& rng, Value val )
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::lower_bound(boost::begin(rng), boost::end(rng), val);
}
/// \overload
template< class ForwardRange, class Value, class SortPredicate >
inline BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type
lower_bound( ForwardRange& rng, Value val, SortPredicate pred )
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::lower_bound(boost::begin(rng), boost::end(rng), val, pred);
}
/// \overload
template< class ForwardRange, class Value, class SortPredicate >
inline BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type
lower_bound( const ForwardRange& rng, Value val, SortPredicate pred )
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::lower_bound(boost::begin(rng), boost::end(rng), val, pred);
}
/// \overload
template< range_return_value re, class ForwardRange, class Value >
inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange,re>::type
lower_bound( ForwardRange& rng, Value val )
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return range_return<ForwardRange,re>::
pack(std::lower_bound(boost::begin(rng), boost::end(rng), val),
rng);
}
/// \overload
template< range_return_value re, class ForwardRange, class Value >
inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange,re>::type
lower_bound( const ForwardRange& rng, Value val )
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return range_return<const ForwardRange,re>::
pack(std::lower_bound(boost::begin(rng), boost::end(rng), val),
rng);
}
/// \overload
template< range_return_value re, class ForwardRange, class Value, class SortPredicate >
inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange,re>::type
lower_bound( ForwardRange& rng, Value val, SortPredicate pred )
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return range_return<ForwardRange,re>::
pack(std::lower_bound(boost::begin(rng), boost::end(rng), val, pred),
rng);
}
/// \overload
template< range_return_value re, class ForwardRange, class Value, class SortPredicate >
inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange,re>::type
lower_bound( const ForwardRange& rng, Value val, SortPredicate pred )
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return range_return<const ForwardRange,re>::
pack(std::lower_bound(boost::begin(rng), boost::end(rng), val, pred),
rng);
}
}
#endif // include guard

View File

@ -0,0 +1,109 @@
// 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_MAX_ELEMENT_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_MAX_ELEMENT_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/detail/range_return.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function max_element
///
/// range-based version of the max_element std algorithm
///
/// \pre ForwardRange is a model of the ForwardRangeConcept
/// \pre BinaryPredicate is a model of the BinaryPredicateConcept
template<class ForwardRange>
inline BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type
max_element(ForwardRange& rng)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::max_element(boost::begin(rng), boost::end(rng));
}
/// \overload
template<class ForwardRange>
inline BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type
max_element(const ForwardRange& rng)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::max_element(boost::begin(rng), boost::end(rng));
}
/// \overload
template<class ForwardRange, class BinaryPredicate>
inline BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type
max_element(ForwardRange& rng, BinaryPredicate pred)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::max_element(boost::begin(rng), boost::end(rng), pred);
}
/// \overload
template<class ForwardRange, class BinaryPredicate>
inline BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type
max_element(const ForwardRange& rng, BinaryPredicate pred)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::max_element(boost::begin(rng), boost::end(rng), pred);
}
// range_return overloads
/// \overload
template<range_return_value re, class ForwardRange>
inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange,re>::type
max_element(ForwardRange& rng)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return range_return<ForwardRange,re>::pack(
std::max_element(boost::begin(rng), boost::end(rng)),
rng);
}
/// \overload
template<range_return_value re, class ForwardRange>
inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange,re>::type
max_element(const ForwardRange& rng)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return range_return<const ForwardRange,re>::pack(
std::max_element(boost::begin(rng), boost::end(rng)),
rng);
}
/// \overload
template<range_return_value re, class ForwardRange, class BinaryPredicate>
inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange,re>::type
max_element(ForwardRange& rng, BinaryPredicate pred)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return range_return<ForwardRange,re>::pack(
std::max_element(boost::begin(rng), boost::end(rng), pred),
rng);
}
/// \overload
template<range_return_value re, class ForwardRange, class BinaryPredicate>
inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange,re>::type
max_element(const ForwardRange& rng, BinaryPredicate pred)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return range_return<const ForwardRange,re>::pack(
std::max_element(boost::begin(rng), boost::end(rng), pred),
rng);
}
}
#endif // include guard

View File

@ -0,0 +1,55 @@
// 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_MERGE_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_MERGE_HPP_INCLUDED
#include <boost/concept_check.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/concepts.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function merge
///
/// range-based version of the merge std algorithm
///
/// \pre SinglePassRange1 is a model of the SinglePassRangeConcept
/// \pre SinglePassRange2 is a model of the SinglePassRangeConcept
/// \pre BinaryPredicate is a model of the BinaryPredicateConcept
///
template<class SinglePassRange1, class SinglePassRange2,
class OutputIterator>
inline OutputIterator merge(const SinglePassRange1& rng1,
const SinglePassRange2& rng2,
OutputIterator out)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< SinglePassRangeConcept<SinglePassRange2> >();
return std::merge(boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2), out);
}
/// \overload
template<class SinglePassRange1, class SinglePassRange2,
class OutputIterator, class BinaryPredicate>
inline OutputIterator merge(const SinglePassRange1& rng1,
const SinglePassRange2& rng2,
OutputIterator out,
BinaryPredicate pred)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< SinglePassRangeConcept<SinglePassRange2> >();
return std::merge(boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2), out, pred);
}
}
#endif // include guard

View File

@ -0,0 +1,109 @@
// 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_MIN_ELEMENT_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_MIN_ELEMENT_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/detail/range_return.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function min_element
///
/// range-based version of the min_element std algorithm
///
/// \pre ForwardRange is a model of the ForwardRangeConcept
/// \pre BinaryPredicate is a model of the BinaryPredicateConcept
template<class ForwardRange>
inline BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type
min_element(ForwardRange& rng)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::min_element(boost::begin(rng), boost::end(rng));
}
/// \overload
template<class ForwardRange>
inline BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type
min_element(const ForwardRange& rng)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::min_element(boost::begin(rng), boost::end(rng));
}
/// \overload
template<class ForwardRange, class BinaryPredicate>
inline BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type
min_element(ForwardRange& rng, BinaryPredicate pred)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::min_element(boost::begin(rng), boost::end(rng), pred);
}
/// \overload
template<class ForwardRange, class BinaryPredicate>
inline BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type
min_element(const ForwardRange& rng, BinaryPredicate pred)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::min_element(boost::begin(rng), boost::end(rng), pred);
}
// range_return overloads
/// \overload
template<range_return_value re, class ForwardRange>
inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange,re>::type
min_element(ForwardRange& rng)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return range_return<ForwardRange,re>::pack(
std::min_element(boost::begin(rng), boost::end(rng)),
rng);
}
/// \overload
template<range_return_value re, class ForwardRange>
inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange,re>::type
min_element(const ForwardRange& rng)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return range_return<const ForwardRange,re>::pack(
std::min_element(boost::begin(rng), boost::end(rng)),
rng);
}
/// \overload
template<range_return_value re, class ForwardRange, class BinaryPredicate>
inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange,re>::type
min_element(ForwardRange& rng, BinaryPredicate pred)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return range_return<ForwardRange,re>::pack(
std::min_element(boost::begin(rng), boost::end(rng), pred),
rng);
}
/// \overload
template<range_return_value re, class ForwardRange, class BinaryPredicate>
inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange,re>::type
min_element(const ForwardRange& rng, BinaryPredicate pred)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return range_return<const ForwardRange,re>::pack(
std::min_element(boost::begin(rng), boost::end(rng), pred),
rng);
}
}
#endif // include guard

View File

@ -0,0 +1,182 @@
// 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_MISMATCH_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_MISMATCH_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/difference_type.hpp>
#include <algorithm>
namespace boost
{
namespace range_detail
{
template< class SinglePassTraversalReadableIterator1,
class SinglePassTraversalReadableIterator2 >
inline std::pair<SinglePassTraversalReadableIterator1,
SinglePassTraversalReadableIterator2>
mismatch_impl(SinglePassTraversalReadableIterator1 first1,
SinglePassTraversalReadableIterator1 last1,
SinglePassTraversalReadableIterator2 first2,
SinglePassTraversalReadableIterator2 last2)
{
while (first1 != last1 && first2 != last2 && *first1 == *first2)
{
++first1;
++first2;
}
return std::pair<SinglePassTraversalReadableIterator1,
SinglePassTraversalReadableIterator2>(first1, first2);
}
template< class SinglePassTraversalReadableIterator1,
class SinglePassTraversalReadableIterator2,
class BinaryPredicate >
inline std::pair<SinglePassTraversalReadableIterator1,
SinglePassTraversalReadableIterator2>
mismatch_impl(SinglePassTraversalReadableIterator1 first1,
SinglePassTraversalReadableIterator1 last1,
SinglePassTraversalReadableIterator2 first2,
SinglePassTraversalReadableIterator2 last2,
BinaryPredicate pred)
{
while (first1 != last1 && first2 != last2 && pred(*first1, *first2))
{
++first1;
++first2;
}
return std::pair<SinglePassTraversalReadableIterator1,
SinglePassTraversalReadableIterator2>(first1, first2);
}
}
/// \brief template function mismatch
///
/// range-based version of the mismatch std algorithm
///
/// \pre SinglePassRange1 is a model of the SinglePassRangeConcept
/// \pre SinglePassRange2 is a model of the SinglePassRangeConcept
/// \pre BinaryPredicate is a model of the BinaryPredicateConcept
template< class SinglePassRange1, class SinglePassRange2 >
inline std::pair<
BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange1>::type,
BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange2>::type >
mismatch(SinglePassRange1& rng1, const SinglePassRange2 & rng2)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< SinglePassRangeConcept<SinglePassRange2> >();
return range_detail::mismatch_impl(boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2));
}
/// \overload
template< class SinglePassRange1, class SinglePassRange2 >
inline std::pair<
BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange1>::type,
BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange2>::type >
mismatch(const SinglePassRange1& rng1, const SinglePassRange2& rng2)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< SinglePassRangeConcept<SinglePassRange2> >();
return range_detail::mismatch_impl(boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2));
}
/// \overload
template< class SinglePassRange1, class SinglePassRange2 >
inline std::pair<
BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange1>::type,
BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange2>::type >
mismatch(SinglePassRange1& rng1, SinglePassRange2 & rng2)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< SinglePassRangeConcept<SinglePassRange2> >();
return range_detail::mismatch_impl(boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2));
}
/// \overload
template< class SinglePassRange1, class SinglePassRange2 >
inline std::pair<
BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange1>::type,
BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange2>::type >
mismatch(const SinglePassRange1& rng1, SinglePassRange2& rng2)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< SinglePassRangeConcept<SinglePassRange2> >();
return range_detail::mismatch_impl(boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2));
}
/// \overload
template< class SinglePassRange1, class SinglePassRange2, class BinaryPredicate >
inline std::pair<
BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange1>::type,
BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange2>::type >
mismatch(SinglePassRange1& rng1, const SinglePassRange2& rng2, BinaryPredicate pred)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< SinglePassRangeConcept<SinglePassRange2> >();
return range_detail::mismatch_impl(boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2), pred);
}
/// \overload
template< class SinglePassRange1, class SinglePassRange2, class BinaryPredicate >
inline std::pair<
BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange1>::type,
BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange2>::type >
mismatch(const SinglePassRange1& rng1, const SinglePassRange2& rng2, BinaryPredicate pred)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< SinglePassRangeConcept<SinglePassRange2> >();
return range_detail::mismatch_impl(boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2), pred);
}
/// \overload
template< class SinglePassRange1, class SinglePassRange2, class BinaryPredicate >
inline std::pair<
BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange1>::type,
BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange2>::type >
mismatch(SinglePassRange1& rng1, SinglePassRange2& rng2, BinaryPredicate pred)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< SinglePassRangeConcept<SinglePassRange2> >();
return range_detail::mismatch_impl(boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2), pred);
}
/// \overload
template< class SinglePassRange1, class SinglePassRange2, class BinaryPredicate >
inline std::pair<
BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange1>::type,
BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange2>::type >
mismatch(const SinglePassRange1& rng1, SinglePassRange2& rng2, BinaryPredicate pred)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< SinglePassRangeConcept<SinglePassRange2> >();
return range_detail::mismatch_impl(boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2), pred);
}
}
#endif // include guard

View File

@ -0,0 +1,64 @@
// 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_NTH_ELEMENT_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_NTH_ELEMENT_HPP_INCLUDED
#include <boost/concept_check.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/concepts.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function nth_element
///
/// range-based version of the nth_element std algorithm
///
/// \pre RandomAccessRange is a model of the RandomAccessRangeConcept
/// \pre BinaryPredicate is a model of the BinaryPredicateConcept
template<class RandomAccessRange>
inline void nth_element(RandomAccessRange& rng,
BOOST_DEDUCED_TYPENAME range_iterator<RandomAccessRange>::type nth)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::nth_element(boost::begin(rng), nth, boost::end(rng));
}
/// \overload
template<class RandomAccessRange>
inline void nth_element(const RandomAccessRange& rng,
BOOST_DEDUCED_TYPENAME range_iterator<const RandomAccessRange>::type nth)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::nth_element(boost::begin(rng),nth,boost::end(rng));
}
/// \overload
template<class RandomAccessRange, class BinaryPredicate>
inline void nth_element(RandomAccessRange& rng,
BOOST_DEDUCED_TYPENAME range_iterator<RandomAccessRange>::type nth,
BinaryPredicate sort_pred)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::nth_element(boost::begin(rng), nth, boost::end(rng), sort_pred);
}
/// \overload
template<class RandomAccessRange, class BinaryPredicate>
inline void nth_element(const RandomAccessRange& rng,
BOOST_DEDUCED_TYPENAME range_iterator<const RandomAccessRange>::type nth,
BinaryPredicate sort_pred)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::nth_element(boost::begin(rng),nth,boost::end(rng), sort_pred);
}
}
#endif // include guard

View 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_PARTIAL_SORT_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_PARTIAL_SORT_HPP_INCLUDED
#include <boost/concept_check.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/concepts.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function partial_sort
///
/// range-based version of the partial_sort std algorithm
///
/// \pre RandomAccessRange is a model of the RandomAccessRangeConcept
/// \pre BinaryPredicate is a model of the BinaryPredicateConcept
template<class RandomAccessRange>
inline void partial_sort(RandomAccessRange& rng,
BOOST_DEDUCED_TYPENAME range_iterator<RandomAccessRange>::type middle)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::partial_sort(boost::begin(rng), middle, boost::end(rng));
}
/// \overload
template<class RandomAccessRange>
inline void partial_sort(const RandomAccessRange& rng,
BOOST_DEDUCED_TYPENAME range_iterator<const RandomAccessRange>::type middle)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::partial_sort(boost::begin(rng), middle, boost::end(rng));
}
/// \overload
template<class RandomAccessRange, class BinaryPredicate>
inline void partial_sort(RandomAccessRange& rng,
BOOST_DEDUCED_TYPENAME range_iterator<RandomAccessRange>::type middle,
BinaryPredicate sort_pred)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::partial_sort(boost::begin(rng), middle, boost::end(rng),
sort_pred);
}
/// \overload
template<class RandomAccessRange, class BinaryPredicate>
inline void partial_sort(const RandomAccessRange& rng,
BOOST_DEDUCED_TYPENAME range_iterator<const RandomAccessRange>::type middle,
BinaryPredicate sort_pred)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::partial_sort(boost::begin(rng), middle, boost::end(rng), sort_pred);
}
}
#endif // include guard

View File

@ -0,0 +1,58 @@
// 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_PARTIAL_SORT_COPY_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_PARTIAL_SORT_COPY_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
{
/// \brief template function partial_sort_copy
///
/// range-based version of the partial_sort_copy std algorithm
///
/// \pre SinglePassRange is a model of the SinglePassRangeConcept
/// \pre RandomAccessRange is a model of the Mutable_RandomAccessRangeConcept
/// \pre BinaryPredicate is a model of the BinaryPredicateConcept
template<typename SinglePassRange, typename RandomAccessRange>
inline typename range_iterator<RandomAccessRange>::type
partial_sort_copy(const SinglePassRange& rng1, RandomAccessRange& rng2)
{
BOOST_CONCEPT_ASSERT((SinglePassRangeConcept<SinglePassRange>));
BOOST_CONCEPT_ASSERT((WriteableRandomAccessRangeConcept<RandomAccessRange>));
BOOST_CONCEPT_ASSERT((range_detail::SameTypeConcept<typename range_value<SinglePassRange>::type, typename range_value<RandomAccessRange>::type>));
BOOST_CONCEPT_ASSERT((LessThanComparableConcept<typename range_value<SinglePassRange>::type>));
return std::partial_sort_copy(boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2));
}
/// \overload
template<typename SinglePassRange, typename RandomAccessRange,
typename BinaryPredicate>
inline typename range_iterator<RandomAccessRange>::type
partial_sort_copy(const SinglePassRange& rng1, RandomAccessRange& rng2,
BinaryPredicate pred)
{
BOOST_CONCEPT_ASSERT((SinglePassRangeConcept<SinglePassRange>));
BOOST_CONCEPT_ASSERT((WriteableRandomAccessRangeConcept<RandomAccessRange>));
BOOST_CONCEPT_ASSERT((range_detail::SameTypeConcept<typename range_value<SinglePassRange>::type, typename range_value<RandomAccessRange>::type>));
BOOST_CONCEPT_ASSERT((BinaryPredicateConcept<BinaryPredicate, typename range_value<RandomAccessRange>::type, typename range_value<RandomAccessRange>::type>));
return std::partial_sort_copy(boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2), pred);
}
}
#endif // include guard

View File

@ -0,0 +1,68 @@
// 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_PARTITION__HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_PARTITION__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/detail/range_return.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function partition
///
/// range-based version of the partition std algorithm
///
/// \pre ForwardRange is a model of the ForwardRangeConcept
template<class ForwardRange, class UnaryPredicate>
inline BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type
partition(ForwardRange& rng, UnaryPredicate pred)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::partition(boost::begin(rng),boost::end(rng),pred);
}
/// \overload
template<class ForwardRange, class UnaryPredicate>
inline BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type
partition(const ForwardRange& rng, UnaryPredicate pred)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::partition(boost::begin(rng),boost::end(rng),pred);
}
// range_return overloads
/// \overload
template< range_return_value re, class ForwardRange,
class UnaryPredicate >
inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange,re>::type
partition(ForwardRange& rng, UnaryPredicate pred)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return boost::range_return<ForwardRange,re>::
pack(std::partition(boost::begin(rng), boost::end(rng), pred), rng);
}
/// \overload
template< range_return_value re, class ForwardRange,
class UnaryPredicate >
inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange,re>::type
partition(const ForwardRange& rng, UnaryPredicate pred)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return boost::range_return<const ForwardRange,re>::
pack(std::partition(boost::begin(rng), boost::end(rng), pred), rng);
}
}
#endif // include guard

View File

@ -0,0 +1,117 @@
// 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_PERMUTATION_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_PERMUTATION_HPP_INCLUDED
#include <boost/concept_check.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/concepts.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function next_permutation
///
/// range-based version of the next_permutation std algorithm
///
/// \pre BidirectionalRange is a model of the BidirectionalRangeConcept
/// \pre Compare is a model of the BinaryPredicateConcept
template<class BidirectionalRange>
inline bool next_permutation(BidirectionalRange& rng)
{
boost::function_requires<
BidirectionalRangeConcept<BidirectionalRange> >();
return std::next_permutation(boost::begin(rng), boost::end(rng));
}
/// \overload
template<class BidirectionalRange>
inline bool next_permutation(const BidirectionalRange& rng)
{
boost::function_requires<
BidirectionalRangeConcept<BidirectionalRange> >();
return std::next_permutation(boost::begin(rng), boost::end(rng));
}
/// \overload
template<class BidirectionalRange, class Compare>
inline bool next_permutation(BidirectionalRange& rng, Compare comp_pred)
{
boost::function_requires<
BidirectionalRangeConcept<BidirectionalRange> >();
return std::next_permutation(boost::begin(rng), boost::end(rng),
comp_pred);
}
/// \overload
template<class BidirectionalRange, class Compare>
inline bool next_permutation(const BidirectionalRange& rng,
Compare comp_pred)
{
boost::function_requires<
BidirectionalRangeConcept<BidirectionalRange> >();
return std::next_permutation(boost::begin(rng), boost::end(rng),
comp_pred);
}
/// \brief template function prev_permutation
///
/// range-based version of the prev_permutation std algorithm
///
/// \pre BidirectionalRange is a model of the BidirectionalRangeConcept
/// \pre Compare is a model of the BinaryPredicateConcept
template<class BidirectionalRange>
inline bool prev_permutation(BidirectionalRange& rng)
{
boost::function_requires<
BidirectionalRangeConcept<BidirectionalRange> >();
return std::prev_permutation(boost::begin(rng), boost::end(rng));
}
/// \overload
template<class BidirectionalRange>
inline bool prev_permutation(const BidirectionalRange& rng)
{
boost::function_requires<
BidirectionalRangeConcept<BidirectionalRange> >();
return std::prev_permutation(boost::begin(rng), boost::end(rng));
}
/// \overload
template<class BidirectionalRange, class Compare>
inline bool prev_permutation(BidirectionalRange& rng, Compare comp_pred)
{
boost::function_requires<
BidirectionalRangeConcept<BidirectionalRange> >();
return std::prev_permutation(boost::begin(rng), boost::end(rng),
comp_pred);
}
/// \overload
template<class BidirectionalRange, class Compare>
inline bool prev_permutation(const BidirectionalRange& rng,
Compare comp_pred)
{
boost::function_requires<
BidirectionalRangeConcept<BidirectionalRange> >();
return std::prev_permutation(boost::begin(rng), boost::end(rng),
comp_pred);
}
}
#endif // include guard

View File

@ -0,0 +1,62 @@
// 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_RANDOM_SHUFFLE_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_RANDOM_SHUFFLE_HPP_INCLUDED
#include <boost/concept_check.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/concepts.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function random_shuffle
///
/// range-based version of the random_shuffle std algorithm
///
/// \pre RandomAccessRange is a model of the RandomAccessRangeConcept
/// \pre Generator is a model of the UnaryFunctionConcept
template<class RandomAccessRange>
inline RandomAccessRange& random_shuffle(RandomAccessRange& rng)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::random_shuffle(boost::begin(rng), boost::end(rng));
return rng;
}
/// \overload
template<class RandomAccessRange>
inline const RandomAccessRange& random_shuffle(const RandomAccessRange& rng)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::random_shuffle(boost::begin(rng),boost::end(rng));
return rng;
}
/// \overload
template<class RandomAccessRange, class Generator>
inline RandomAccessRange& random_shuffle(RandomAccessRange& rng, Generator& gen)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::random_shuffle(boost::begin(rng), boost::end(rng), gen);
return rng;
}
/// \overload
template<class RandomAccessRange, class Generator>
inline const RandomAccessRange& random_shuffle(const RandomAccessRange& rng, Generator& gen)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::random_shuffle(boost::begin(rng), boost::end(rng), gen);
return rng;
}
}
#endif // include guard

View File

@ -0,0 +1,70 @@
// 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_REMOVE_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_REMOVE_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/detail/range_return.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function remove
///
/// range-based version of the remove std algorithm
///
/// \pre ForwardRange is a model of the ForwardRangeConcept
template< class ForwardRange, class Value >
inline BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type
remove(ForwardRange& rng, const Value& val)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::remove(boost::begin(rng),boost::end(rng),val);
}
/// \overload
template< class ForwardRange, class Value >
inline BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type
remove(const ForwardRange& rng, const Value& val)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::remove(boost::begin(rng),boost::end(rng),val);
}
// range_return overloads
/// \overload
template< range_return_value re, class ForwardRange, class Value >
inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange,re>::type
remove(ForwardRange& rng, const Value& val)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return range_return<ForwardRange,re>::pack(
std::remove(boost::begin(rng), boost::end(rng), val),
rng);
}
/// \overload
template< range_return_value re, class ForwardRange, class Value >
inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange,re>::type
remove(const ForwardRange& rng, const Value& val)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return range_return<const ForwardRange,re>::pack(
std::remove(boost::begin(rng), boost::end(rng), val),
rng);
}
}
#endif // include guard

View File

@ -0,0 +1,38 @@
// 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_REMOVE_COPY_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_REMOVE_COPY_HPP_INCLUDED
#include <boost/concept_check.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/concepts.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function remove_copy
///
/// range-based version of the remove_copy std algorithm
///
/// \pre SinglePassRange is a model of the SinglePassRangeConcept
/// \pre OutputIterator is a model of the OutputIteratorConcept
/// \pre Value is a model of the EqualityComparableConcept
/// \pre Objects of type Value can be compared for equality with objects of
/// InputIterator's value type.
template< class SinglePassRange, class OutputIterator, class Value >
inline OutputIterator
remove_copy(SinglePassRange& rng, OutputIterator out_it, const Value& val)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange> >();
return std::remove_copy(boost::begin(rng), boost::end(rng), out_it, val);
}
}
#endif // include guard

View File

@ -0,0 +1,38 @@
// 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_REMOVE_COPY_IF_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_REMOVE_COPY_IF_HPP_INCLUDED
#include <boost/concept_check.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/concepts.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function remove_copy_if
///
/// range-based version of the remove_copy_if std algorithm
///
/// \pre SinglePassRange is a model of the SinglePassRangeConcept
/// \pre OutputIterator is a model of the OutputIteratorConcept
/// \pre Predicate is a model of the PredicateConcept
/// \pre InputIterator's value type is convertible to Predicate's argument type
/// \pre out_it is not an iterator in the range rng
template< class SinglePassRange, class OutputIterator, class Predicate >
inline OutputIterator
remove_copy_if(SinglePassRange& rng, OutputIterator out_it, Predicate pred)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange> >();
return std::remove_copy_if(boost::begin(rng), boost::end(rng), out_it, pred);
}
}
#endif // include guard

View File

@ -0,0 +1,70 @@
// 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_REMOVE_IF_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_REMOVE_IF_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/detail/range_return.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function remove_if
///
/// range-based version of the remove_if std algorithm
///
/// \pre ForwardRange is a model of the ForwardRangeConcept
/// \pre UnaryPredicate is a model of the UnaryPredicateConcept
template< class ForwardRange, class UnaryPredicate >
inline BOOST_DEDUCED_TYPENAME boost::range_iterator<ForwardRange>::type
remove_if(ForwardRange& rng, UnaryPredicate pred)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::remove_if(boost::begin(rng), boost::end(rng), pred);
}
/// \overload
template< class ForwardRange, class UnaryPredicate >
inline BOOST_DEDUCED_TYPENAME boost::range_iterator<const ForwardRange>::type
remove_if(const ForwardRange& rng, UnaryPredicate pred)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::remove_if(boost::begin(rng),boost::end(rng),pred);
}
// range_return overloads
/// \overload
template< range_return_value re, class ForwardRange, class UnaryPredicate >
inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange,re>::type
remove_if(ForwardRange& rng, UnaryPredicate pred)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return range_return<ForwardRange,re>::pack(
std::remove_if(boost::begin(rng), boost::end(rng), pred),
rng);
}
/// \overload
template< range_return_value re, class ForwardRange, class UnaryPredicate >
inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange,re>::type
remove_if(const ForwardRange& rng, UnaryPredicate pred)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return range_return<const ForwardRange,re>::pack(
std::remove_if(boost::begin(rng), boost::end(rng), pred),
rng);
}
}
#endif // include guard

View 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_REPLACE_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_REPLACE_HPP_INCLUDED
#include <boost/concept_check.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/concepts.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function replace
///
/// range-based version of the replace std algorithm
///
/// \pre ForwardRange is a model of the ForwardRangeConcept
template< class ForwardRange, class Value >
inline ForwardRange&
replace(ForwardRange& rng, const Value& what,
const Value& with_what)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
std::replace(boost::begin(rng), boost::end(rng), what, with_what);
return rng;
}
/// \overload
template< class ForwardRange, class Value >
inline const ForwardRange&
replace(const ForwardRange& rng, const Value& what,
const Value& with_what)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
std::replace(boost::begin(rng), boost::end(rng), what, with_what);
return rng;
}
}
#endif // include guard

View File

@ -0,0 +1,36 @@
// 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_REPLACE_COPY_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_REPLACE_COPY_HPP_INCLUDED
#include <boost/concept_check.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/concepts.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function replace_copy
///
/// range-based version of the replace_copy std algorithm
///
/// \pre ForwardRange is a model of the ForwardRangeConcept
template< class ForwardRange, class OutputIterator, class Value >
inline OutputIterator
replace_copy(ForwardRange& rng, OutputIterator out_it, const Value& what,
const Value& with_what)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::replace_copy(boost::begin(rng), boost::end(rng), out_it,
what, with_what);
}
}
#endif // include guard

View File

@ -0,0 +1,40 @@
// 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_REPLACE_COPY_IF_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_REPLACE_COPY_IF_HPP_INCLUDED
#include <boost/concept_check.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/concepts.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function replace_copy_if
///
/// range-based version of the replace_copy_if std algorithm
///
/// \pre ForwardRange is a model of the ForwardRangeConcept
/// \pre Predicate is a model of the PredicateConcept
/// \pre Value is convertible to Predicate's argument type
/// \pre Value is Assignable
/// \pre Value is convertible to a type in OutputIterator's set of value types.
template< class ForwardRange, class OutputIterator, class Predicate, class Value >
inline OutputIterator
replace_copy_if(ForwardRange& rng, OutputIterator out_it, Predicate pred,
const Value& with_what)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::replace_copy_if(boost::begin(rng), boost::end(rng), out_it,
pred, with_what);
}
}
#endif // include guard

View File

@ -0,0 +1,49 @@
// 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_REPLACE_IF_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_REPLACE_IF_HPP_INCLUDED
#include <boost/concept_check.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/concepts.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function replace_if
///
/// range-based version of the replace_if std algorithm
///
/// \pre ForwardRange is a model of the ForwardRangeConcept
/// \pre UnaryPredicate is a model of the UnaryPredicateConcept
template< class ForwardRange, class UnaryPredicate, class Value >
inline ForwardRange&
replace_if(ForwardRange& rng, UnaryPredicate pred,
const Value& val)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
std::replace_if(boost::begin(rng), boost::end(rng), pred, val);
return rng;
}
/// \overload
template< class ForwardRange, class UnaryPredicate, class Value >
inline const ForwardRange&
replace_if(const ForwardRange& rng, UnaryPredicate pred,
const Value& val)
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
std::replace_if(boost::begin(rng), boost::end(rng), pred, val);
return rng;
}
}
#endif // include guard

View File

@ -0,0 +1,44 @@
// 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_REVERSE_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_REVERSE_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/detail/range_return.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function reverse
///
/// range-based version of the reverse std algorithm
///
/// \pre BidirectionalRange is a model of the BidirectionalRangeConcept
template<class BidirectionalRange>
inline BidirectionalRange& reverse(BidirectionalRange& rng)
{
boost::function_requires< BidirectionalRangeConcept<BidirectionalRange> >();
std::reverse(boost::begin(rng), boost::end(rng));
return rng;
}
/// \overload
template<class BidirectionalRange>
inline const BidirectionalRange& reverse(const BidirectionalRange& rng)
{
boost::function_requires< BidirectionalRangeConcept<BidirectionalRange> >();
std::reverse(boost::begin(rng), boost::end(rng));
return rng;
}
}
#endif // include guard

View File

@ -0,0 +1,42 @@
// 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_REVERSE_COPY_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_REVERSE_COPY_HPP_INCLUDED
#include <boost/concept_check.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/concepts.hpp>
#include <boost/iterator/iterator_concepts.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function reverse_copy
///
/// range-based version of the reverse_copy std algorithm
///
/// \pre BidirectionalRange is a model of the BidirectionalRangeConcept
template<typename BidirectionalRange, typename OutputIterator>
inline OutputIterator reverse_copy(BidirectionalRange& rng, OutputIterator out)
{
BOOST_CONCEPT_ASSERT((BidirectionalRangeConcept<BidirectionalRange>));
return std::reverse_copy(boost::begin(rng), boost::end(rng), out);
}
/// \overload
template<typename BidirectionalRange, typename OutputIterator>
inline OutputIterator reverse_copy(const BidirectionalRange& rng, OutputIterator out)
{
BOOST_CONCEPT_ASSERT((BidirectionalRangeConcept<BidirectionalRange>));
return std::reverse_copy(boost::begin(rng), boost::end(rng), out);
}
}
#endif // include guard

View File

@ -0,0 +1,46 @@
// 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_ROTATE_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_ROTATE_HPP_INCLUDED
#include <boost/concept_check.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/concepts.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function rotate
///
/// range-based version of the rotate std algorithm
///
/// \pre Rng meets the requirements for a Forward range
template<typename ForwardRange>
inline ForwardRange& rotate(ForwardRange& rng,
typename range_iterator<ForwardRange>::type middle)
{
BOOST_CONCEPT_ASSERT((ForwardRangeConcept<ForwardRange>));
std::rotate(boost::begin(rng), middle, boost::end(rng));
return rng;
}
/// \overload
template<typename ForwardRange>
inline const ForwardRange&
rotate(const ForwardRange& rng,
typename range_iterator<const ForwardRange>::type middle)
{
BOOST_CONCEPT_ASSERT((ForwardRangeConcept<ForwardRange>));
std::rotate(boost::begin(rng), middle, boost::end(rng));
return rng;
}
}
#endif // include guard

View File

@ -0,0 +1,38 @@
// 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_ROTATE_COPY_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_ROTATE_COPY_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/iterator.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function rotate
///
/// range-based version of the rotate std algorithm
///
/// \pre Rng meets the requirements for a Forward range
template<typename ForwardRange, typename OutputIterator>
inline OutputIterator rotate_copy(
const ForwardRange& rng,
typename range_iterator<const ForwardRange>::type middle,
OutputIterator target
)
{
BOOST_CONCEPT_ASSERT((ForwardRangeConcept<ForwardRange>));
return std::rotate_copy(boost::begin(rng), middle, boost::end(rng), target);
}
}
#endif // include guard

View File

@ -0,0 +1,131 @@
// 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_SEARCH_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_SEARCH_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/detail/range_return.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function search
///
/// range-based version of the search std algorithm
///
/// \pre ForwardRange1 is a model of the ForwardRangeConcept
/// \pre ForwardRange2 is a model of the ForwardRangeConcept
/// \pre BinaryPredicate is a model of the BinaryPredicateConcept
template< class ForwardRange1, class ForwardRange2 >
inline BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange1>::type
search(ForwardRange1& rng1, const ForwardRange2& rng2)
{
boost::function_requires< ForwardRangeConcept<ForwardRange1> >();
boost::function_requires< ForwardRangeConcept<ForwardRange2> >();
return std::search(boost::begin(rng1),boost::end(rng1),
boost::begin(rng2),boost::end(rng2));
}
/// \overload
template< class ForwardRange1, class ForwardRange2 >
inline BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange1>::type
search(const ForwardRange1& rng1, const ForwardRange2& rng2)
{
boost::function_requires< ForwardRangeConcept<ForwardRange1> >();
boost::function_requires< ForwardRangeConcept<ForwardRange2> >();
return std::search(boost::begin(rng1),boost::end(rng1),
boost::begin(rng2),boost::end(rng2));
}
/// \overload
template< class ForwardRange1, class ForwardRange2, class BinaryPredicate >
inline BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange1>::type
search(ForwardRange1& rng1, const ForwardRange2& rng2, BinaryPredicate pred)
{
boost::function_requires< ForwardRangeConcept<ForwardRange1> >();
boost::function_requires< ForwardRangeConcept<ForwardRange2> >();
return std::search(boost::begin(rng1),boost::end(rng1),
boost::begin(rng2),boost::end(rng2),pred);
}
/// \overload
template< class ForwardRange1, class ForwardRange2, class BinaryPredicate >
inline BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange1>::type
search(const ForwardRange1& rng1, const ForwardRange2& rng2,
BinaryPredicate pred)
{
boost::function_requires< ForwardRangeConcept<ForwardRange1> >();
boost::function_requires< ForwardRangeConcept<ForwardRange2> >();
return std::search(boost::begin(rng1),boost::end(rng1),
boost::begin(rng2),boost::end(rng2),pred);
}
// range_return overloads
/// \overload
template< range_return_value re, class ForwardRange1, class ForwardRange2 >
inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange1,re>::type
search(ForwardRange1& rng1, const ForwardRange2& rng2)
{
boost::function_requires< ForwardRangeConcept<ForwardRange1> >();
boost::function_requires< ForwardRangeConcept<ForwardRange2> >();
return range_return<ForwardRange1,re>::
pack(std::search(boost::begin(rng1),boost::end(rng1),
boost::begin(rng2),boost::end(rng2)),
rng1);
}
/// \overload
template< range_return_value re, class ForwardRange1, class ForwardRange2 >
inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange1,re>::type
search(const ForwardRange1& rng1, const ForwardRange2& rng2)
{
boost::function_requires< ForwardRangeConcept<ForwardRange1> >();
boost::function_requires< ForwardRangeConcept<ForwardRange2> >();
return range_return<const ForwardRange1,re>::
pack(std::search(boost::begin(rng1),boost::end(rng1),
boost::begin(rng2),boost::end(rng2)),
rng1);
}
/// \overload
template< range_return_value re, class ForwardRange1, class ForwardRange2,
class BinaryPredicate >
inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange1,re>::type
search(ForwardRange1& rng1, const ForwardRange2& rng2, BinaryPredicate pred)
{
boost::function_requires< ForwardRangeConcept<ForwardRange1> >();
boost::function_requires< ForwardRangeConcept<ForwardRange2> >();
return range_return<ForwardRange1,re>::
pack(std::search(boost::begin(rng1),boost::end(rng1),
boost::begin(rng2),boost::end(rng2),pred),
rng1);
}
/// \overload
template< range_return_value re, class ForwardRange1, class ForwardRange2,
class BinaryPredicate >
inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange1,re>::type
search(const ForwardRange1& rng1, const ForwardRange2& rng2,
BinaryPredicate pred)
{
boost::function_requires< ForwardRangeConcept<ForwardRange1> >();
boost::function_requires< ForwardRangeConcept<ForwardRange2> >();
return range_return<const ForwardRange1,re>::
pack(std::search(boost::begin(rng1),boost::end(rng1),
boost::begin(rng2),boost::end(rng2),pred),
rng1);
}
}
#endif // include guard

View File

@ -0,0 +1,140 @@
// 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_SEARCH_N_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_SEARCH_N_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/detail/range_return.hpp>
#include <boost/range/value_type.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function search
///
/// range-based version of the search std algorithm
///
/// \pre ForwardRange is a model of the ForwardRangeConcept
/// \pre Integer is an integral type
/// \pre Value is a model of the EqualityComparableConcept
/// \pre ForwardRange's value type is a model of the EqualityComparableConcept
/// \pre Object's of ForwardRange's value type can be compared for equality with Objects of type Value
template< typename ForwardRange, typename Integer, typename Value >
inline typename range_iterator<ForwardRange>::type
search_n(ForwardRange& rng, Integer count, const Value& value)
{
BOOST_CONCEPT_ASSERT((ForwardRangeConcept<ForwardRange>));
return std::search_n(boost::begin(rng),boost::end(rng), count, value);
}
/// \overload
template< typename ForwardRange, typename Integer, typename Value >
inline typename range_iterator<const ForwardRange>::type
search_n(const ForwardRange& rng, Integer count, const Value& value)
{
BOOST_CONCEPT_ASSERT((ForwardRangeConcept<ForwardRange>));
return std::search_n(boost::begin(rng), boost::end(rng), count, value);
}
/// \overload
template< typename ForwardRange, typename Integer, class Value,
typename BinaryPredicate >
inline typename range_iterator<ForwardRange>::type
search_n(ForwardRange& rng, Integer count, const Value& value,
BinaryPredicate binary_pred)
{
BOOST_CONCEPT_ASSERT((ForwardRangeConcept<ForwardRange>));
BOOST_CONCEPT_ASSERT((BinaryPredicateConcept<BinaryPredicate,
typename range_value<ForwardRange>::type, const Value&>));
return std::search_n(boost::begin(rng), boost::end(rng),
count, value, binary_pred);
}
/// \overload
template< typename ForwardRange, typename Integer, typename Value,
typename BinaryPredicate >
inline typename range_iterator<const ForwardRange>::type
search_n(const ForwardRange& rng, Integer count, const Value& value,
BinaryPredicate binary_pred)
{
BOOST_CONCEPT_ASSERT((ForwardRangeConcept<ForwardRange>));
BOOST_CONCEPT_ASSERT((BinaryPredicateConcept<BinaryPredicate,
typename range_value<const ForwardRange>::type, const Value&>));
return std::search_n(boost::begin(rng), boost::end(rng),
count, value, binary_pred);
}
// range_return overloads
/// \overload
template< range_return_value re, typename ForwardRange, typename Integer,
typename Value >
inline typename range_return<ForwardRange,re>::type
search_n(ForwardRange& rng, Integer count, const Value& value)
{
BOOST_CONCEPT_ASSERT((ForwardRangeConcept<ForwardRange>));
return range_return<ForwardRange,re>::
pack(std::search_n(boost::begin(rng),boost::end(rng),
count, value),
rng);
}
/// \overload
template< range_return_value re, typename ForwardRange, typename Integer,
class Value >
inline typename range_return<const ForwardRange,re>::type
search_n(const ForwardRange& rng, Integer count, const Value& value)
{
BOOST_CONCEPT_ASSERT((ForwardRangeConcept<ForwardRange>));
return range_return<const ForwardRange,re>::
pack(std::search_n(boost::begin(rng), boost::end(rng),
count, value),
rng);
}
/// \overload
template< range_return_value re, typename ForwardRange, typename Integer,
typename Value, typename BinaryPredicate >
inline typename range_return<ForwardRange,re>::type
search_n(ForwardRange& rng, Integer count, const Value& value,
BinaryPredicate pred)
{
BOOST_CONCEPT_ASSERT((ForwardRangeConcept<ForwardRange>));
BOOST_CONCEPT_ASSERT((BinaryPredicateConcept<BinaryPredicate,
typename range_value<ForwardRange>::type,
const Value&>));
return range_return<ForwardRange,re>::
pack(std::search_n(boost::begin(rng), boost::end(rng),
count, value, pred),
rng);
}
/// \overload
template< range_return_value re, typename ForwardRange, typename Integer,
typename Value, typename BinaryPredicate >
inline typename range_return<const ForwardRange,re>::type
search_n(const ForwardRange& rng, Integer count, const Value& value,
BinaryPredicate pred)
{
BOOST_CONCEPT_ASSERT((ForwardRangeConcept<ForwardRange>));
BOOST_CONCEPT_ASSERT((BinaryPredicateConcept<BinaryPredicate,
typename range_value<const ForwardRange>::type,
const Value&>));
return range_return<const ForwardRange,re>::
pack(std::search_n(boost::begin(rng), boost::end(rng),
count, value, pred),
rng);
}
}
#endif // include guard

View File

@ -0,0 +1,188 @@
// 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_SET_ALGORITHM_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_SET_ALGORITHM_HPP_INCLUDED
#include <boost/concept_check.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/concepts.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function includes
///
/// range-based version of the includes std algorithm
///
/// \pre SinglePassRange1 is a model of the SinglePassRangeConcept
/// \pre SinglePassRange2 is a model of the SinglePassRangeConcept
/// \pre BinaryPredicate is a model of the BinaryPredicateConcept
template<class SinglePassRange1, class SinglePassRange2>
inline bool includes(const SinglePassRange1& rng1,
const SinglePassRange2& rng2)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< SinglePassRangeConcept<SinglePassRange2> >();
return std::includes(boost::begin(rng1),boost::end(rng1),
boost::begin(rng2),boost::end(rng2));
}
/// \overload
template<class SinglePassRange1, class SinglePassRange2,
class BinaryPredicate>
inline bool includes(const SinglePassRange1& rng1,
const SinglePassRange2& rng2,
BinaryPredicate pred)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< SinglePassRangeConcept<SinglePassRange2> >();
return std::includes(boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2), pred);
}
/// \brief template function set_union
///
/// range-based version of the set_union std algorithm
///
/// \pre SinglePassRange1 is a model of the SinglePassRangeConcept
/// \pre SinglePassRange2 is a model of the SinglePassRangeConcept
/// \pre BinaryPredicate is a model of the BinaryPredicateConcept
template<class SinglePassRange1, class SinglePassRange2,
class OutputIterator>
inline OutputIterator set_union(const SinglePassRange1& rng1,
const SinglePassRange2& rng2,
OutputIterator out)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< SinglePassRangeConcept<SinglePassRange2> >();
return std::set_union(boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2), out);
}
/// \overload
template<class SinglePassRange1, class SinglePassRange2,
class OutputIterator, class BinaryPredicate>
inline OutputIterator set_union(const SinglePassRange1& rng1,
const SinglePassRange2& rng2,
OutputIterator out,
BinaryPredicate pred)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< SinglePassRangeConcept<SinglePassRange2> >();
return std::set_union(boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2), out, pred);
}
/// \brief template function set_intersection
///
/// range-based version of the set_intersection std algorithm
///
/// \pre SinglePassRange1 is a model of the SinglePassRangeConcept
/// \pre SinglePassRange2 is a model of the SinglePassRangeConcept
/// \pre BinaryPredicate is a model of the BinaryPredicateConcept
template<class SinglePassRange1, class SinglePassRange2,
class OutputIterator>
inline OutputIterator set_intersection(const SinglePassRange1& rng1,
const SinglePassRange2& rng2,
OutputIterator out)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< SinglePassRangeConcept<SinglePassRange2> >();
return std::set_intersection(boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2), out);
}
/// \overload
template<class SinglePassRange1, class SinglePassRange2,
class OutputIterator, class BinaryPredicate>
inline OutputIterator set_intersection(const SinglePassRange1& rng1,
const SinglePassRange2& rng2,
OutputIterator out,
BinaryPredicate pred)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< SinglePassRangeConcept<SinglePassRange2> >();
return std::set_intersection(boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2),
out, pred);
}
/// \brief template function set_difference
///
/// range-based version of the set_difference std algorithm
///
/// \pre SinglePassRange1 is a model of the SinglePassRangeConcept
/// \pre SinglePassRange2 is a model of the SinglePassRangeConcept
/// \pre BinaryPredicate is a model of the BinaryPredicateConcept
template<class SinglePassRange1, class SinglePassRange2,
class OutputIterator>
inline OutputIterator set_difference(const SinglePassRange1& rng1,
const SinglePassRange2& rng2,
OutputIterator out)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< SinglePassRangeConcept<SinglePassRange2> >();
return std::set_difference(boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2), out);
}
/// \overload
template<class SinglePassRange1, class SinglePassRange2,
class OutputIterator, class BinaryPredicate>
inline OutputIterator set_difference(const SinglePassRange1& rng1,
const SinglePassRange2& rng2,
OutputIterator out,
BinaryPredicate pred)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< SinglePassRangeConcept<SinglePassRange2> >();
return std::set_difference(
boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2), out, pred);
}
/// \brief template function set_symmetric_difference
///
/// range-based version of the set_symmetric_difference std algorithm
///
/// \pre SinglePassRange1 is a model of the SinglePassRangeConcept
/// \pre SinglePassRange2 is a model of the SinglePassRangeConcept
/// \pre BinaryPredicate is a model of the BinaryPredicateConcept
template<class SinglePassRange1, class SinglePassRange2,
class OutputIterator>
inline OutputIterator
set_symmetric_difference(const SinglePassRange1& rng1,
const SinglePassRange2& rng2,
OutputIterator out)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< SinglePassRangeConcept<SinglePassRange2> >();
return std::set_symmetric_difference(boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2), out);
}
/// \overload
template<class SinglePassRange1, class SinglePassRange2,
class OutputIterator, class BinaryPredicate>
inline OutputIterator
set_symmetric_difference(const SinglePassRange1& rng1,
const SinglePassRange2& rng2,
OutputIterator out,
BinaryPredicate pred)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< SinglePassRangeConcept<SinglePassRange2> >();
return std::set_symmetric_difference(
boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2), out, pred);
}
}
#endif // include guard

View File

@ -0,0 +1,63 @@
// 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_SORT_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_SORT_HPP_INCLUDED
#include <boost/concept_check.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/concepts.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function sort
///
/// range-based version of the sort std algorithm
///
/// \pre RandomAccessRange is a model of the RandomAccessRangeConcept
/// \pre BinaryPredicate is a model of the BinaryPredicateConcept
template<class RandomAccessRange>
inline RandomAccessRange& sort(RandomAccessRange& rng)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::sort(boost::begin(rng), boost::end(rng));
return rng;
}
/// \overload
template<class RandomAccessRange>
inline const RandomAccessRange& sort(const RandomAccessRange& rng)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::sort(boost::begin(rng),boost::end(rng));
return rng;
}
/// \overload
template<class RandomAccessRange, class BinaryPredicate>
inline RandomAccessRange& sort(RandomAccessRange& rng, BinaryPredicate pred)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::sort(boost::begin(rng), boost::end(rng), pred);
return rng;
}
/// \overload
template<class RandomAccessRange, class BinaryPredicate>
inline const RandomAccessRange& sort(const RandomAccessRange& rng, BinaryPredicate pred)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::sort(boost::begin(rng), boost::end(rng), pred);
return rng;
}
}
#endif // include guard

View File

@ -0,0 +1,68 @@
// 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_STABLE_PARTITION_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_STABLE_PARTITION_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/detail/range_return.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function stable_partition
///
/// range-based version of the stable_partition std algorithm
///
/// \pre BidirectionalRange is a model of the BidirectionalRangeConcept
/// \pre UnaryPredicate is a model of the UnaryPredicateConcept
template<class BidirectionalRange, class UnaryPredicate>
inline BOOST_DEDUCED_TYPENAME range_iterator<BidirectionalRange>::type
stable_partition(BidirectionalRange& rng, UnaryPredicate pred)
{
boost::function_requires< BidirectionalRangeConcept<BidirectionalRange> >();
return std::stable_partition(boost::begin(rng), boost::end(rng), pred);
}
/// \overload
template<class BidirectionalRange, class UnaryPredicate>
inline BOOST_DEDUCED_TYPENAME range_iterator<const BidirectionalRange>::type
stable_partition(const BidirectionalRange& rng, UnaryPredicate pred)
{
boost::function_requires< BidirectionalRangeConcept<BidirectionalRange> >();
return std::stable_partition(boost::begin(rng),boost::end(rng),pred);
}
// range_return overloads
template<range_return_value re, class BidirectionalRange, class UnaryPredicate>
inline BOOST_DEDUCED_TYPENAME range_return<BidirectionalRange,re>::type
stable_partition(BidirectionalRange& rng, UnaryPredicate pred)
{
boost::function_requires< BidirectionalRangeConcept<BidirectionalRange> >();
return range_return<BidirectionalRange,re>::pack(
std::stable_partition(boost::begin(rng), boost::end(rng), pred),
rng);
}
/// \overload
template<range_return_value re, class BidirectionalRange, class UnaryPredicate>
inline BOOST_DEDUCED_TYPENAME range_return<const BidirectionalRange,re>::type
stable_partition(const BidirectionalRange& rng, UnaryPredicate pred)
{
boost::function_requires< BidirectionalRangeConcept<BidirectionalRange> >();
return range_return<const BidirectionalRange,re>::pack(
std::stable_partition(boost::begin(rng),boost::end(rng),pred),
rng);
}
}
#endif // include guard

View File

@ -0,0 +1,62 @@
// 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_STABLE_SORT_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_STABLE_SORT_HPP_INCLUDED
#include <boost/concept_check.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/concepts.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function stable_sort
///
/// range-based version of the stable_sort std algorithm
///
/// \pre RandomAccessRange is a model of the RandomAccessRangeConcept
/// \pre BinaryPredicate is a model of the BinaryPredicateConcept
template<class RandomAccessRange>
inline RandomAccessRange& stable_sort(RandomAccessRange& rng)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::stable_sort(boost::begin(rng), boost::end(rng));
return rng;
}
/// \overload
template<class RandomAccessRange>
inline const RandomAccessRange& stable_sort(const RandomAccessRange& rng)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::stable_sort(boost::begin(rng), boost::end(rng));
return rng;
}
/// \overload
template<class RandomAccessRange, class BinaryPredicate>
inline RandomAccessRange& stable_sort(RandomAccessRange& rng, BinaryPredicate sort_pred)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::stable_sort(boost::begin(rng), boost::end(rng), sort_pred);
return rng;
}
/// \overload
template<class RandomAccessRange, class BinaryPredicate>
inline const RandomAccessRange& stable_sort(const RandomAccessRange& rng, BinaryPredicate sort_pred)
{
boost::function_requires< RandomAccessRangeConcept<RandomAccessRange> >();
std::stable_sort(boost::begin(rng), boost::end(rng), sort_pred);
return rng;
}
}
#endif // include guard

View File

@ -0,0 +1,81 @@
// 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_SWAP_RANGES_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_SWAP_RANGES_HPP_INCLUDED
#include <boost/assert.hpp>
#include <boost/concept_check.hpp>
#include <boost/iterator/iterator_categories.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/concepts.hpp>
#include <boost/range/iterator.hpp>
#include <algorithm>
namespace boost
{
namespace range_detail
{
template<typename Iterator1, typename Iterator2>
void swap_ranges_impl(Iterator1 it1, Iterator1 last1,
Iterator2 it2, Iterator2 last2,
single_pass_traversal_tag,
single_pass_traversal_tag)
{
ignore_unused_variable_warning(last2);
for (; it1 != last1; ++it1, ++it2)
{
BOOST_ASSERT( it2 != last2 );
std::iter_swap(it1, it2);
}
}
template<typename Iterator1, typename Iterator2>
void swap_ranges_impl(Iterator1 it1, Iterator1 last1,
Iterator2 it2, Iterator2 last2,
random_access_traversal_tag,
random_access_traversal_tag)
{
ignore_unused_variable_warning(last2);
BOOST_ASSERT( last2 - it2 >= last1 - it1 );
std::swap_ranges(it1, last1, it2);
}
template<typename Iterator1, typename Iterator2>
void swap_ranges_impl(Iterator1 first1, Iterator1 last1,
Iterator2 first2, Iterator2 last2)
{
swap_ranges_impl(first1, last1, first2, last2,
typename iterator_traversal<Iterator1>::type(),
typename iterator_traversal<Iterator2>::type());
}
} // namespace range_detail
/// \brief template function swap_ranges
///
/// range-based version of the swap_ranges std algorithm
///
/// \pre SinglePassRange1 is a model of the SinglePassRangeConcept
/// \pre SinglePassRange2 is a model of the SinglePassRangeConcept
template< typename SinglePassRange1, typename SinglePassRange2 >
inline SinglePassRange2&
swap_ranges(SinglePassRange1& range1, SinglePassRange2& range2)
{
BOOST_CONCEPT_ASSERT((SinglePassRangeConcept<SinglePassRange1>));
BOOST_CONCEPT_ASSERT((SinglePassRangeConcept<SinglePassRange2>));
boost::range_detail::swap_ranges_impl(
boost::begin(range1), boost::end(range1),
boost::begin(range2), boost::end(range2));
return range2;
}
}
#endif // include guard

View File

@ -0,0 +1,85 @@
// 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_TRANSFORM_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_TRANSFORM_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 <algorithm>
namespace boost
{
/// \brief template function transform
///
/// range-based version of the transform std algorithm
///
/// \pre SinglePassRange1 is a model of the SinglePassRangeConcept
/// \pre SinglePassRange2 is a model of the SinglePassRangeConcept
/// \pre OutputIterator is a model of the OutputIteratorConcept
/// \pre UnaryOperation is a model of the UnaryFunctionConcept
/// \pre BinaryOperation is a model of the BinaryFunctionConcept
template< class SinglePassRange1,
class OutputIterator,
class UnaryOperation >
inline OutputIterator
transform(const SinglePassRange1& rng,
OutputIterator out,
UnaryOperation fun)
{
return std::transform(boost::begin(rng),boost::end(rng),out,fun);
}
namespace range_detail
{
template< class SinglePassTraversalReadableIterator1,
class SinglePassTraversalReadableIterator2,
class OutputIterator,
class BinaryFunction >
inline OutputIterator
transform_impl(SinglePassTraversalReadableIterator1 first1,
SinglePassTraversalReadableIterator1 last1,
SinglePassTraversalReadableIterator2 first2,
SinglePassTraversalReadableIterator2 last2,
OutputIterator out,
BinaryFunction fn)
{
for (; first1 != last1; ++first1, ++first2)
{
BOOST_ASSERT( first2 != last2 );
*out = fn(*first1, *first2);
++out;
}
return out;
}
}
/// \overload
template< class SinglePassRange1,
class SinglePassRange2,
class OutputIterator,
class BinaryOperation >
inline OutputIterator
transform(const SinglePassRange1& rng1,
const SinglePassRange2& rng2,
OutputIterator out,
BinaryOperation fun)
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< SinglePassRangeConcept<SinglePassRange2> >();
return range_detail::transform_impl(
boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), boost::end(rng2),
out, fun);
}
}
#endif // include guard

View File

@ -0,0 +1,101 @@
// 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_UNIQUE_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_UNIQUE_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/detail/range_return.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function unique
///
/// range-based version of the unique std algorithm
///
/// \pre Rng meets the requirements for a Forward range
template< range_return_value re, class ForwardRange >
inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange,re>::type
unique( ForwardRange& rng )
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return range_return<ForwardRange,re>::
pack( std::unique( boost::begin(rng),
boost::end(rng)), rng );
}
/// \overload
template< range_return_value re, class ForwardRange >
inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange,re>::type
unique( const ForwardRange& rng )
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return range_return<const ForwardRange,re>::
pack( std::unique( boost::begin(rng),
boost::end(rng)), rng );
}
/// \overload
template< range_return_value re, class ForwardRange, class BinaryPredicate >
inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange,re>::type
unique( ForwardRange& rng, BinaryPredicate pred )
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return range_return<ForwardRange,re>::
pack(std::unique(boost::begin(rng), boost::end(rng), pred),
rng);
}
/// \overload
template< range_return_value re, class ForwardRange, class BinaryPredicate >
inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange,re>::type
unique( const ForwardRange& rng, BinaryPredicate pred )
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return range_return<const ForwardRange,re>::
pack(std::unique(boost::begin(rng), boost::end(rng), pred),
rng);
}
/// \overload
template< class ForwardRange >
inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange, return_begin_found>::type
unique( ForwardRange& rng )
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return boost::unique<return_begin_found>(rng);
}
/// \overload
template< class ForwardRange >
inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange, return_begin_found>::type
unique( const ForwardRange& rng )
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return boost::unique<return_begin_found>(rng);
}
/// \overload
template< class ForwardRange, class BinaryPredicate >
inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange, return_begin_found>::type
unique( ForwardRange& rng, BinaryPredicate pred )
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return boost::unique<return_begin_found>(rng);
}
/// \overload
template< class ForwardRange, class BinaryPredicate >
inline BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type
unique( const ForwardRange& rng, BinaryPredicate pred )
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return boost::unique<return_begin_found>(rng, pred);
}
}
#endif // include guard

View File

@ -0,0 +1,45 @@
// 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_UNIQUE_COPY_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_UNIQUE_COPY_HPP_INCLUDED
#include <boost/concept_check.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/concepts.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function unique_copy
///
/// range-based version of the unique_copy std algorithm
///
/// \pre SinglePassRange is a model of the SinglePassRangeConcept
/// \pre OutputIterator is a model of the OutputIteratorConcept
/// \pre BinaryPredicate is a model of the BinaryPredicateConcept
template< class SinglePassRange, class OutputIterator >
inline OutputIterator
unique_copy( const SinglePassRange& rng, OutputIterator out_it )
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange> >();
return std::unique_copy(boost::begin(rng), boost::end(rng), out_it);
}
/// \overload
template< class SinglePassRange, class OutputIterator, class BinaryPredicate >
inline OutputIterator
unique_copy( const SinglePassRange& rng, OutputIterator out_it,
BinaryPredicate pred )
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange> >();
return std::unique_copy(boost::begin(rng), boost::end(rng), out_it, pred);
}
}
#endif // include guard

View File

@ -0,0 +1,101 @@
// 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_UPPER_BOUND_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_UPPER_BOUND_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/detail/range_return.hpp>
#include <algorithm>
namespace boost
{
/// \brief template function upper_bound
///
/// range-based version of the upper_bound std algorithm
///
/// \pre ForwardRange is a model of the ForwardRangeConcept
template< class ForwardRange, class Value >
inline BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type
upper_bound( ForwardRange& rng, Value val )
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::upper_bound(boost::begin(rng), boost::end(rng), val);
}
/// \overload
template< class ForwardRange, class Value >
inline BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type
upper_bound( const ForwardRange& rng, Value val )
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::upper_bound(boost::begin(rng), boost::end(rng), val);
}
/// \overload
template< class ForwardRange, class Value, class SortPredicate >
inline BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type
upper_bound( ForwardRange& rng, Value val, SortPredicate pred )
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::upper_bound(boost::begin(rng), boost::end(rng), val, pred);
}
/// \overload
template< class ForwardRange, class Value, class SortPredicate >
inline BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type
upper_bound( const ForwardRange& rng, Value val, SortPredicate pred )
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return std::upper_bound(boost::begin(rng), boost::end(rng), val, pred);
}
/// \overload
template< range_return_value re, class ForwardRange, class Value >
inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange,re>::type
upper_bound( ForwardRange& rng, Value val )
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return range_return<ForwardRange,re>::
pack(std::upper_bound(boost::begin(rng), boost::end(rng), val),
rng);
}
/// \overload
template< range_return_value re, class ForwardRange, class Value >
inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange,re>::type
upper_bound( const ForwardRange& rng, Value val )
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return range_return<const ForwardRange,re>::
pack(std::upper_bound(boost::begin(rng), boost::end(rng), val),
rng);
}
/// \overload
template< range_return_value re, class ForwardRange, class Value,
class SortPredicate >
inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange,re>::type
upper_bound( ForwardRange& rng, Value val, SortPredicate pred )
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return range_return<ForwardRange,re>::
pack(std::upper_bound(boost::begin(rng), boost::end(rng), val, pred),
rng);
}
/// \overload
template< range_return_value re, class ForwardRange, class Value,
class SortPredicate >
inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange,re>::type
upper_bound( const ForwardRange& rng, Value val, SortPredicate pred )
{
boost::function_requires< ForwardRangeConcept<ForwardRange> >();
return range_return<const ForwardRange,re>::
pack(std::upper_bound(boost::begin(rng), boost::end(rng), val, pred),
rng);
}
}
#endif // include guard

View File

@ -0,0 +1,27 @@
// Boost.Range library
//
// Copyright Neil Groves 2007. 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)
//
// Copyright Thorsten Ottosen 2006. 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_HPP
#define BOOST_RANGE_ALGORITHM_EXT_HPP
#include <boost/range/algorithm_ext/copy_n.hpp>
#include <boost/range/algorithm_ext/for_each.hpp>
#include <boost/range/algorithm_ext/is_sorted.hpp>
#include <boost/range/algorithm_ext/overwrite.hpp>
#include <boost/range/algorithm_ext/push_back.hpp>
#include <boost/range/algorithm_ext/push_front.hpp>
#include <boost/range/algorithm_ext/insert.hpp>
#include <boost/range/algorithm_ext/erase.hpp>
#endif

View 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

View 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

View 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

View 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

View 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

View 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

View 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

View 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

310
include/boost/range/combine.hpp Executable file
View File

@ -0,0 +1,310 @@
#ifndef BOOST_RANGE_COMBINE_HPP
#define BOOST_RANGE_COMBINE_HPP
#include <boost/iterator/zip_iterator.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/type_traits/is_void.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/plus.hpp>
#include <boost/mpl/arithmetic.hpp>
#include <boost/config.hpp>
namespace boost
{
namespace detail
{
struct void_ { typedef void_ type; };
}
template<> struct range_iterator<detail::void_>
{
typedef tuples::null_type type;
};
namespace detail
{
inline tuples::null_type range_begin( void_& )
{ return tuples::null_type(); }
inline tuples::null_type range_end( void_& )
{ return tuples::null_type(); }
template< class T >
struct tuple_iter
{
typedef typename mpl::eval_if_c< is_same<T,void_>::value,
mpl::identity<tuples::null_type>,
range_iterator<T> >::type
type;
};
template< class Rng1, class Rng2 >
struct tuple_range
{
typedef typename mpl::eval_if_c< is_same<Rng1,void_>::value,
void_,
mpl::identity<Rng1> >::type
type;
};
template
<
class R1,
class R2,
class R3,
class R4,
class R5,
class R6
>
struct generate_tuple
{
typedef boost::tuple< typename tuple_iter<R1>::type,
typename tuple_iter<R2>::type,
typename tuple_iter<R3>::type,
typename tuple_iter<R4>::type,
typename tuple_iter<R5>::type,
typename tuple_iter<R6>::type >
type;
static type begin( R1& r1, R2& r2, R3& r3, R4& r4, R5& r5, R6& r6 )
{
return make_tuple( boost::begin(r1),
boost::begin(r2),
boost::begin(r3),
boost::begin(r4),
boost::begin(r5),
boost::begin(r6) );
}
static type end( R1& r1, R2& r2, R3& r3, R4& r4, R5& r5, R6& r6 )
{
return make_tuple( boost::end(r1),
boost::end(r2),
boost::end(r3),
boost::end(r4),
boost::end(r5),
boost::end(r6) );
}
};
template
<
class R1,
class R2 = void_,
class R3 = void_,
class R4 = void_,
class R5 = void_,
class R6 = void_
>
struct zip_rng
: iterator_range<
zip_iterator< typename generate_tuple<R1,R2,R3,R4,R5,R6>::type >
>
{
private:
typedef generate_tuple<R1,R2,R3,R4,R5,R6>
generator;
typedef typename generator::type
tuple;
typedef zip_iterator<tuple>
zip_iter;
typedef iterator_range<zip_iter>
base;
public:
zip_rng( R1& r1, R2& r2, R3& r3, R4& r4, R5& r5, R6& r6 )
: base( zip_iter( generator::begin(r1,r2,r3,r4,r5,r6) ),
zip_iter( generator::end(r1,r2,r3,r4,r5,r6) ) )
{
BOOST_ASSERT(boost::distance(r1) <= boost::distance(r2));
BOOST_ASSERT(boost::distance(r1) <= boost::distance(r3));
BOOST_ASSERT(boost::distance(r1) <= boost::distance(r4));
BOOST_ASSERT(boost::distance(r1) <= boost::distance(r5));
BOOST_ASSERT(boost::distance(r1) <= boost::distance(r6));
}
template< class Zip, class Rng >
zip_rng( Zip& z, Rng& r )
: base( zip_iter( generator::begin( z, r ) ),
zip_iter( generator::end( z, r ) ) )
{
// @todo: tuple::begin( should be overloaded for this situation
}
struct tuple_length : tuples::length<tuple>
{ };
template< unsigned N >
struct get
{
template< class Z, class R >
static typename tuples::element<N,tuple>::type begin( Z& z, R& )
{
return get<N>( z.begin().get_iterator_tuple() );
}
template< class Z, class R >
static typename tuples::element<N,tuple>::type end( Z& z, R& r )
{
return get<N>( z.end().get_iterator_tuple() );
}
};
};
template< class Rng1, class Rng2 >
struct zip_range
: iterator_range<
zip_iterator<
tuple< typename range_iterator<Rng1>::type,
typename range_iterator<Rng2>::type >
> >
{
private:
typedef zip_iterator<
tuple< typename range_iterator<Rng1>::type,
typename range_iterator<Rng2>::type >
>
zip_iter;
typedef iterator_range<zip_iter>
base;
public:
zip_range( Rng1& r1, Rng2& r2 )
: base( zip_iter( make_tuple(boost::begin(r1),
boost::begin(r2)) ),
zip_iter( make_tuple(boost::end(r1),
boost::end(r2)) ) )
{
BOOST_ASSERT(boost::distance(r1) <= boost::distance(r2));
}
};
template< class Rng1, class Rng2, class Rng3 >
struct zip_range3
: iterator_range<
zip_iterator<
tuple< typename range_iterator<Rng1>::type,
typename range_iterator<Rng2>::type,
typename range_iterator<Rng3>::type >
> >
{
private:
typedef zip_iterator<
tuple< typename range_iterator<Rng1>::type,
typename range_iterator<Rng2>::type,
typename range_iterator<Rng3>::type >
>
zip_iter;
typedef iterator_range<zip_iter>
base;
public:
zip_range3( Rng1& r1, Rng2& r2, Rng3& r3 )
: base( zip_iter( make_tuple(boost::begin(r1),
boost::begin(r2),
boost::begin(r3)) ),
zip_iter( make_tuple(boost::end(r1),
boost::end(r2),
boost::end(r3)) )
)
{
BOOST_ASSERT(distance(r1) <= distance(r2));
BOOST_ASSERT(distance(r1) <= distance(r3));
}
};
struct combine_tag {};
template< class Rng >
inline zip_rng<Rng>
operator&( combine_tag, Rng& r )
{
return zip_rng<Rng>(r);
}
template< class Rng >
inline iterator_range<const Rng>
operator&( combine_tag, const Rng& r )
{
return iterator_range<const Rng>(r);
}
template
<
class R1,
class R2,
class R3,
class R4,
class R5,
class Rng
>
inline typename zip_rng<R1,R2,R3,R4,R5>::next
operator&( const zip_rng<R1,R2,R3,R4,R5>& zip,
Rng& r )
{
return zip_rng<R1,R2,R3,R4,R5>::next( zip, r );
}
//
// This one should be able to be made generic
//
// template
// <
// class R1,
// class R2 = void,
// class R3 = void,
// class R4 = void,
// class R5 = void,
// class R6 = void
// >
// inline zip_range<R1,R2,R3,R4,R4,R5,R6>::type
// x
//
//
/*
template< class Rng1, class Rng2, class Rng3 >
inline zip_range3<Rng1,Rng2,Rng3>
operator&( const zip_range<Rng1,Rng2>& r1, const Rng3& r3 )
{
return zip_range3<Rn1,Rng2,Rng3>(
}*/
} // namespace 'detail'
template< class Rng1, class Rng2 >
inline detail::zip_range<Rng1,Rng2> combine( Rng1& r1, Rng2& r2 )
{
return detail::zip_range<Rng1,Rng2>(r1,r2);
}
template< class Rng1, class Rng2 >
inline detail::zip_range<const Rng1,Rng2> combine( const Rng1& r1, Rng2& r2 )
{
return detail::zip_range<const Rng1,Rng2>(r1,r2);
}
template< class Rng1, class Rng2 >
inline detail::zip_range<Rng1,const Rng2> combine( Rng1& r1, const Rng2& r2 )
{
return detail::zip_range<Rng1,Rng2>(r1,r2);
}
template< class Rng1, class Rng2 >
inline detail::zip_range<const Rng1,const Rng2> combine( const Rng1& r1, const Rng2& r2 )
{
return detail::zip_range<const Rng1,const Rng2>(r1,r2);
}
//
// @todo: find a solution that scales better
// instead of adding 6 overloads!
//
}
#endif

265
include/boost/range/concepts.hpp Executable file → Normal file
View File

@ -1,5 +1,10 @@
// Boost.Range library concept checks
//
// Copyright Neil Groves 2009. Use, modification and distribution
// are 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)
//
// Copyright Daniel Walker 2006. Use, modification and distribution
// are subject to the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@ -15,6 +20,9 @@
#include <boost/iterator/iterator_concepts.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/iterator.hpp>
#include <boost/range/value_type.hpp>
#include <boost/range/detail/misc_concept.hpp>
/*!
* \file
@ -29,20 +37,15 @@
* concept.
*
* \code
* function_requires<ForwardRangeConcept<T> >();
* BOOST_CONCEPT_ASSERT((ForwardRangeConcept<T>));
* \endcode
*
* An additional concept check is required for the value access
* property of the range. For example to check for a
* ForwardReadableRange, the following code is required.
* A different concept check is required to ensure writeable value
* access. For example to check for a ForwardRange that can be written
* to, the following code is required.
*
* \code
* function_requires<ForwardRangeConcept<T> >();
* function_requires<
* ReadableIteratorConcept<
* typename range_iterator<T>::type
* >
* >();
* BOOST_CONCEPT_ASSERT((WriteableForwardRangeConcept<T>));
* \endcode
*
* \see http://www.boost.org/libs/range/doc/range.html for details
@ -55,84 +58,218 @@
namespace boost {
namespace range_detail {
// Rationale for the inclusion of redefined iterator concept
// classes:
//
// The Range algorithms often do not require that the iterators are
// Assignable, but the correct standard conformant iterators
// do require the iterators to be a model of the Assignable concept.
// Iterators that contains a functor that is not assignable therefore
// are not correct models of the standard iterator concepts,
// despite being adequate for most algorithms. An example of this
// use case is the combination of the boost::adaptors::filtered
// class with a boost::lambda::bind generated functor.
// Ultimately modeling the range concepts using composition
// with the Boost.Iterator concepts would render the library
// incompatible with many common Boost.Lambda expressions.
template<typename Iterator>
struct IncrementableIteratorConcept : CopyConstructible<Iterator>
{
typedef typename iterator_traversal<Iterator>::type traversal_category;
BOOST_CONCEPT_ASSERT((
Convertible<
traversal_category,
incrementable_traversal_tag
>));
BOOST_CONCEPT_USAGE(IncrementableIteratorConcept)
{
++i;
(void)i++;
}
private:
Iterator i;
};
template<typename Iterator>
struct SinglePassIteratorConcept
: IncrementableIteratorConcept<Iterator>
, EqualityComparable<Iterator>
{
BOOST_CONCEPT_ASSERT((
Convertible<
typename SinglePassIteratorConcept::traversal_category,
single_pass_traversal_tag
>));
};
template<typename Iterator>
struct ForwardIteratorConcept
: SinglePassIteratorConcept<Iterator>
, DefaultConstructible<Iterator>
{
typedef typename boost::detail::iterator_traits<Iterator>::difference_type difference_type;
BOOST_MPL_ASSERT((is_integral<difference_type>));
BOOST_MPL_ASSERT_RELATION(std::numeric_limits<difference_type>::is_signed, ==, true);
BOOST_CONCEPT_ASSERT((
Convertible<
typename ForwardIteratorConcept::traversal_category,
forward_traversal_tag
>));
};
template<typename Iterator>
struct BidirectionalIteratorConcept
: ForwardIteratorConcept<Iterator>
{
BOOST_CONCEPT_ASSERT((
Convertible<
typename BidirectionalIteratorConcept::traversal_category,
bidirectional_traversal_tag
>));
BOOST_CONCEPT_USAGE(BidirectionalIteratorConcept)
{
--i;
(void)i--;
}
private:
Iterator i;
};
template<typename Iterator>
struct RandomAccessIteratorConcept
: BidirectionalIteratorConcept<Iterator>
{
BOOST_CONCEPT_ASSERT((
Convertible<
typename RandomAccessIteratorConcept::traversal_category,
random_access_traversal_tag
>));
BOOST_CONCEPT_USAGE(RandomAccessIteratorConcept)
{
i += n;
i = i + n;
i = n + i;
i -= n;
i = i - n;
n = i - j;
}
private:
typename RandomAccessIteratorConcept::difference_type n;
Iterator i;
Iterator j;
};
} // namespace range_detail
//! Check if a type T models the SinglePassRange range concept.
template<typename T>
struct SinglePassRangeConcept
struct SinglePassRangeConcept
{
typedef typename range_iterator<T const>::type range_const_iterator;
typedef typename range_iterator<T>::type range_iterator;
typedef typename range_iterator<T const>::type const_iterator;
typedef typename range_iterator<T>::type iterator;
void constraints()
{
function_requires<
boost_concepts::SinglePassIteratorConcept<
range_iterator
>
>();
i = boost::begin(a);
i = boost::end(a);
const_constraints(a);
BOOST_CONCEPT_ASSERT((range_detail::SinglePassIteratorConcept<iterator>));
BOOST_CONCEPT_ASSERT((range_detail::SinglePassIteratorConcept<const_iterator>));
BOOST_CONCEPT_USAGE(SinglePassRangeConcept)
{
// This has been modified from assigning to this->i
// (where i was a member variable) to improve
// compatibility with Boost.Lambda
iterator i1 = boost::begin(*m_range);
iterator i2 = boost::end(*m_range);
ignore_unused_variable_warning(i1);
ignore_unused_variable_warning(i2);
const_constraints(*m_range);
}
void const_constraints(const T& a)
private:
void const_constraints(const T& const_range)
{
ci = boost::begin(a);
ci = boost::end(a);
const_iterator ci1 = boost::begin(const_range);
const_iterator ci2 = boost::end(const_range);
ignore_unused_variable_warning(ci1);
ignore_unused_variable_warning(ci2);
}
T a;
range_iterator i;
range_const_iterator ci;
// Rationale:
// The type of m_range is T* rather than T because it allows
// T to be an abstract class. The other obvious alternative of
// T& produces a warning on some compilers.
T* m_range;
};
//! Check if a type T models the ForwardRange range concept.
template<typename T>
struct ForwardRangeConcept
struct ForwardRangeConcept : SinglePassRangeConcept<T>
{
void constraints()
BOOST_CONCEPT_ASSERT((range_detail::ForwardIteratorConcept<typename ForwardRangeConcept::iterator>));
BOOST_CONCEPT_ASSERT((range_detail::ForwardIteratorConcept<typename ForwardRangeConcept::const_iterator>));
};
template<typename Range>
struct WriteableRangeConcept
{
typedef typename range_iterator<Range>::type iterator;
BOOST_CONCEPT_USAGE(WriteableRangeConcept)
{
function_requires<
SinglePassRangeConcept<T>
>();
function_requires<
boost_concepts::ForwardTraversalConcept<
typename range_iterator<T>::type
>
>();
*i = v;
}
private:
iterator i;
typename range_value<Range>::type v;
};
//! Check if a type T models the WriteableForwardRange range concept.
template<typename T>
struct WriteableForwardRangeConcept
: ForwardRangeConcept<T>
, WriteableRangeConcept<T>
{
};
//! Check if a type T models the BidirectionalRange range concept.
template<typename T>
struct BidirectionalRangeConcept
struct BidirectionalRangeConcept : ForwardRangeConcept<T>
{
BOOST_CONCEPT_ASSERT((BidirectionalIteratorConcept<typename BidirectionalRangeConcept::iterator>));
BOOST_CONCEPT_ASSERT((BidirectionalIteratorConcept<typename BidirectionalRangeConcept::const_iterator>));
};
//! Check if a type T models the WriteableBidirectionalRange range concept.
template<typename T>
struct WriteableBidirectionalRangeConcept
: BidirectionalRangeConcept<T>
, WriteableRangeConcept<T>
{
void constraints()
{
function_requires<
ForwardRangeConcept<T>
>();
function_requires<
boost_concepts::BidirectionalTraversalConcept<
typename range_iterator<T>::type
>
>();
}
};
//! Check if a type T models the RandomAccessRange range concept.
template<typename T>
struct RandomAccessRangeConcept
struct RandomAccessRangeConcept : BidirectionalRangeConcept<T>
{
BOOST_CONCEPT_ASSERT((RandomAccessIteratorConcept<typename RandomAccessRangeConcept::iterator>));
BOOST_CONCEPT_ASSERT((RandomAccessIteratorConcept<typename RandomAccessRangeConcept::const_iterator>));
};
//! Check if a type T models the WriteableRandomAccessRange range concept.
template<typename T>
struct WriteableRandomAccessRangeConcept
: RandomAccessRangeConcept<T>
, WriteableRangeConcept<T>
{
void constraints()
{
function_requires<
BidirectionalRangeConcept<T>
>();
function_requires<
boost_concepts::RandomAccessTraversalConcept<
typename range_iterator<T>::type
>
>();
}
};
} // namespace boost

11
include/boost/range/const_iterator.hpp Executable file → Normal file
View File

@ -21,6 +21,7 @@
#include <boost/range/detail/const_iterator.hpp>
#else
#include <boost/range/detail/extract_optional_type.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <cstddef>
#include <utility>
@ -31,11 +32,13 @@ namespace boost
// default
//////////////////////////////////////////////////////////////////////////
namespace range_detail {
BOOST_RANGE_EXTRACT_OPTIONAL_TYPE( const_iterator )
}
template< typename C >
struct range_const_iterator
{
typedef BOOST_DEDUCED_TYPENAME C::const_iterator type;
};
struct range_const_iterator : range_detail::extract_const_iterator<C>
{};
//////////////////////////////////////////////////////////////////////////
// pair

View File

@ -0,0 +1,69 @@
// Boost.Range library
//
// Copyright Neil Groves 2008. Use, modification and
// distribution is subject to the Boost Software Licence, 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_COUNTING_RANGE_HPP_INCLUDED
#define BOOST_RANGE_COUNTING_RANGE_HPP_INCLUDED
#include <boost/config.hpp>
#if BOOST_MSVC >= 1400
#pragma warning(push)
#pragma warning(disable : 4244)
#endif
#include <boost/range/iterator_range_core.hpp>
#include <boost/range/value_type.hpp>
#include <boost/iterator/counting_iterator.hpp>
#include <boost/utility.hpp>
namespace boost
{
template<class Value>
inline iterator_range<counting_iterator<Value> >
counting_range(Value first, Value last)
{
typedef counting_iterator<Value> counting_iterator_t;
typedef iterator_range<counting_iterator_t> result_t;
return result_t(counting_iterator_t(first),
counting_iterator_t(last));
}
template<class Range>
inline iterator_range<counting_iterator<BOOST_DEDUCED_TYPENAME range_value<const Range>::type> >
counting_range(const Range& rng)
{
typedef counting_iterator<BOOST_DEDUCED_TYPENAME range_value<const Range>::type> counting_iterator_t;
typedef iterator_range<counting_iterator_t> result_t;
return boost::empty(rng)
? result_t()
: result_t(
counting_iterator_t(*boost::begin(rng)),
counting_iterator_t(*boost::prior(boost::end(rng))));
}
template<class Range>
inline iterator_range<counting_iterator<BOOST_DEDUCED_TYPENAME range_value<Range>::type> >
counting_range(Range& rng)
{
typedef counting_iterator<BOOST_DEDUCED_TYPENAME range_value<Range>::type> counting_iterator_t;
typedef iterator_range<counting_iterator_t> result_t;
return boost::empty(rng)
? result_t()
: result_t(
counting_iterator_t(*boost::begin(rng)),
counting_iterator_t(*boost::prior(boost::end(rng))));
}
} // namespace boost
#if BOOST_MSVC >= 1400
#pragma warning(pop)
#endif
#endif // include guard

View File

@ -0,0 +1,79 @@
// 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_DETAIL_DEMOTE_ITERATOR_TRAVERSAL_TAG_HPP_INCLUDED
#define BOOST_RANGE_DETAIL_DEMOTE_ITERATOR_TRAVERSAL_TAG_HPP_INCLUDED
#include <boost/iterator/iterator_categories.hpp>
namespace boost
{
namespace range_detail
{
template<class IteratorTraversalTag1, class IteratorTraversalTag2>
struct demote_iterator_traversal_tag
{
};
#define BOOST_DEMOTE_TRAVERSAL_TAG( Tag1, Tag2, ResultTag ) \
template<> struct demote_iterator_traversal_tag< Tag1 , Tag2 > \
{ \
typedef ResultTag type; \
};
BOOST_DEMOTE_TRAVERSAL_TAG( no_traversal_tag, no_traversal_tag, no_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( no_traversal_tag, incrementable_traversal_tag, no_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( no_traversal_tag, single_pass_traversal_tag, no_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( no_traversal_tag, forward_traversal_tag, no_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( no_traversal_tag, bidirectional_traversal_tag, no_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( no_traversal_tag, random_access_traversal_tag, no_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( incrementable_traversal_tag, no_traversal_tag, no_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( incrementable_traversal_tag, incrementable_traversal_tag, incrementable_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( incrementable_traversal_tag, single_pass_traversal_tag, incrementable_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( incrementable_traversal_tag, forward_traversal_tag, incrementable_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( incrementable_traversal_tag, bidirectional_traversal_tag, incrementable_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( incrementable_traversal_tag, random_access_traversal_tag, incrementable_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( single_pass_traversal_tag, no_traversal_tag, no_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( single_pass_traversal_tag, incrementable_traversal_tag, incrementable_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( single_pass_traversal_tag, single_pass_traversal_tag, single_pass_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( single_pass_traversal_tag, forward_traversal_tag, single_pass_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( single_pass_traversal_tag, bidirectional_traversal_tag, single_pass_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( single_pass_traversal_tag, random_access_traversal_tag, single_pass_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( forward_traversal_tag, no_traversal_tag, no_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( forward_traversal_tag, incrementable_traversal_tag, incrementable_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( forward_traversal_tag, single_pass_traversal_tag, single_pass_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( forward_traversal_tag, forward_traversal_tag, forward_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( forward_traversal_tag, bidirectional_traversal_tag, forward_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( forward_traversal_tag, random_access_traversal_tag, forward_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( bidirectional_traversal_tag, no_traversal_tag, no_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( bidirectional_traversal_tag, incrementable_traversal_tag, incrementable_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( bidirectional_traversal_tag, single_pass_traversal_tag, single_pass_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( bidirectional_traversal_tag, forward_traversal_tag, forward_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( bidirectional_traversal_tag, bidirectional_traversal_tag, bidirectional_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( bidirectional_traversal_tag, random_access_traversal_tag, bidirectional_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( random_access_traversal_tag, no_traversal_tag, no_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( random_access_traversal_tag, incrementable_traversal_tag, incrementable_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( random_access_traversal_tag, single_pass_traversal_tag, single_pass_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( random_access_traversal_tag, forward_traversal_tag, forward_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( random_access_traversal_tag, bidirectional_traversal_tag, bidirectional_traversal_tag )
BOOST_DEMOTE_TRAVERSAL_TAG( random_access_traversal_tag, random_access_traversal_tag, random_access_traversal_tag )
#undef BOOST_DEMOTE_TRAVERSAL_TAG
} // namespace range_detail
} // namespace boost
#endif // include guard

View File

@ -0,0 +1,52 @@
// Boost.Range library
//
// Copyright Arno Schoedl & 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_DETAIL_EXTRACT_OPTIONAL_TYPE_HPP_INCLUDED
#define BOOST_RANGE_DETAIL_EXTRACT_OPTIONAL_TYPE_HPP_INCLUDED
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif
#include <boost/config.hpp>
#ifdef BOOST_NO_PARTIAL_TEMPLATE_SPECIALIZATION
#define BOOST_RANGE_EXTRACT_OPTIONAL_TYPE( a_typedef ) \
template< typename C > \
struct extract_ ## a_typedef \
{ \
typedef BOOST_DEDUCED_TYPENAME C::a_typedef type; \
};
#else
namespace boost {
namespace range_detail {
template< typename T > struct exists { typedef void type; };
}
}
// Defines extract_some_typedef<T> which exposes T::some_typedef as
// extract_some_typedef<T>::type if T::some_typedef exists. Otherwise
// extract_some_typedef<T> is empty.
#define BOOST_RANGE_EXTRACT_OPTIONAL_TYPE( a_typedef ) \
template< typename C, typename Enable=void > \
struct extract_ ## a_typedef \
{}; \
template< typename C > \
struct extract_ ## a_typedef< C \
, BOOST_DEDUCED_TYPENAME boost::range_detail::exists< BOOST_DEDUCED_TYPENAME C::a_typedef >::type \
> { \
typedef BOOST_DEDUCED_TYPENAME C::a_typedef type; \
};
#endif
#endif // include guard

View File

@ -0,0 +1,357 @@
// 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_DETAIL_JOIN_ITERATOR_HPP_INCLUDED
#define BOOST_RANGE_DETAIL_JOIN_ITERATOR_HPP_INCLUDED
#include <iterator>
#include <boost/iterator/iterator_traits.hpp>
#include <boost/iterator/iterator_facade.hpp>
#include <boost/intrusive_ptr.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/empty.hpp>
#include <boost/range/detail/demote_iterator_traversal_tag.hpp>
#include <boost/range/value_type.hpp>
#include <boost/utility.hpp>
namespace boost
{
namespace range_detail
{
template<typename Iterator1, typename Iterator2>
struct join_iterator_link
{
private:
class reference_count_t
{
public:
reference_count_t() : m_count(0u) {}
reference_count_t(const reference_count_t&) : m_count(0u) {}
reference_count_t& operator=(const reference_count_t&) { return *this; }
void increment() { ++m_count; }
bool decrement() { return --m_count ? false : true; }
private:
unsigned int m_count;
};
public:
join_iterator_link(Iterator1 last1, Iterator2 first2)
: last1(last1)
, first2(first2)
{
}
void add_reference() const
{
count.increment();
}
bool release_reference() const
{
return count.decrement();
}
Iterator1 last1;
Iterator2 first2;
private:
join_iterator_link() /* = delete */ ;
mutable reference_count_t count;
};
} // range_detail
template<typename Iterator1, typename Iterator2>
inline void intrusive_ptr_add_ref(const range_detail::join_iterator_link<Iterator1,Iterator2>* p)
{
p->add_reference();
}
template<typename Iterator1, typename Iterator2>
inline void intrusive_ptr_release(const range_detail::join_iterator_link<Iterator1,Iterator2>* p)
{
if (p->release_reference())
delete p;
}
namespace range_detail
{
class join_iterator_begin_tag {};
class join_iterator_end_tag {};
template<typename Iterator1
, typename Iterator2
, typename Reference
>
class join_iterator_union
{
public:
typedef Iterator1 iterator1_t;
typedef Iterator2 iterator2_t;
join_iterator_union() {}
join_iterator_union(unsigned int /*selected*/, const iterator1_t& it1, const iterator2_t& it2) : m_it1(it1), m_it2(it2) {}
iterator1_t& it1() { return m_it1; }
const iterator1_t& it1() const { return m_it1; }
iterator2_t& it2() { return m_it2; }
const iterator2_t& it2() const { return m_it2; }
Reference dereference(unsigned int selected) const
{
return selected ? *m_it2 : *m_it1;
}
bool equal(const join_iterator_union& other, unsigned int selected) const
{
return selected
? m_it2 == other.m_it2
: m_it1 == other.m_it1;
}
private:
iterator1_t m_it1;
iterator2_t m_it2;
};
template<class Iterator, class Reference>
class join_iterator_union<Iterator, Iterator, Reference>
{
public:
typedef Iterator iterator1_t;
typedef Iterator iterator2_t;
join_iterator_union() {}
join_iterator_union(unsigned int selected, const iterator1_t& it1, const iterator2_t& it2)
: m_it(selected ? it2 : it1)
{
}
iterator1_t& it1() { return m_it; }
const iterator1_t& it1() const { return m_it; }
iterator2_t& it2() { return m_it; }
const iterator2_t& it2() const { return m_it; }
Reference dereference(unsigned int) const
{
return *m_it;
}
bool equal(const join_iterator_union& other, unsigned int selected) const
{
return m_it == other.m_it;
}
private:
iterator1_t m_it;
};
template<typename Iterator1
, typename Iterator2
, typename ValueType = typename iterator_value<Iterator1>::type
, typename Reference = typename iterator_reference<Iterator1>::type
, typename Traversal = typename demote_iterator_traversal_tag<
typename iterator_traversal<Iterator1>::type
, typename iterator_traversal<Iterator2>::type>::type
>
class join_iterator
: public iterator_facade<join_iterator<Iterator1,Iterator2,ValueType,Reference,Traversal>, ValueType, Traversal, Reference>
{
typedef join_iterator_link<Iterator1, Iterator2> link_t;
typedef join_iterator_union<Iterator1, Iterator2, Reference> iterator_union;
public:
typedef Iterator1 iterator1_t;
typedef Iterator2 iterator2_t;
join_iterator() : m_section(0u) {}
join_iterator(unsigned int section, Iterator1 current1, Iterator1 last1, Iterator2 first2, Iterator2 current2)
: m_section(section)
, m_it(section, current1, current2)
, m_link(new link_t(last1, first2))
{
}
template<typename Range1, typename Range2>
join_iterator(Range1& r1, Range2& r2, join_iterator_begin_tag)
: m_section(boost::empty(r1) ? 1u : 0u)
, m_it(boost::empty(r1) ? 1u : 0u, boost::begin(r1), boost::begin(r2))
, m_link(new link_t(boost::end(r1), boost::begin(r2)))
{
}
template<typename Range1, typename Range2>
join_iterator(const Range1& r1, const Range2& r2, join_iterator_begin_tag)
: m_section(boost::empty(r1) ? 1u : 0u)
, m_it(boost::empty(r1) ? 1u : 0u, boost::const_begin(r1), boost::const_begin(r2))
, m_link(new link_t(boost::const_end(r1), boost::const_begin(r2)))
{
}
template<typename Range1, typename Range2>
join_iterator(Range1& r1, Range2& r2, join_iterator_end_tag)
: m_section(1u)
, m_it(1u, boost::end(r1), boost::end(r2))
, m_link(new link_t(boost::end(r1), boost::begin(r2)))
{
}
template<typename Range1, typename Range2>
join_iterator(const Range1& r1, const Range2& r2, join_iterator_end_tag)
: m_section(1u)
, m_it(1u, boost::const_end(r1), boost::const_end(r2))
, m_link(new link_t(boost::const_end(r1), boost::const_begin(r2)))
{
}
private:
void increment()
{
if (m_section)
++m_it.it2();
else
{
++m_it.it1();
if (m_it.it1() == m_link->last1)
{
m_it.it2() = m_link->first2;
m_section = 1u;
}
}
}
void decrement()
{
if (m_section)
{
if (m_it.it2() == m_link->first2)
{
m_it.it1() = boost::prior(m_link->last1);
m_section = 0u;
}
else
--m_it.it2();
}
else
--m_it.it1();
}
typename join_iterator::reference dereference() const
{
return m_it.dereference(m_section);
}
bool equal(const join_iterator& other) const
{
return m_section == other.m_section
&& m_it.equal(other.m_it, m_section);
}
void advance(typename join_iterator::difference_type offset)
{
if (m_section)
advance_from_range2(offset);
else
advance_from_range1(offset);
}
typename join_iterator::difference_type distance_to(const join_iterator& other) const
{
typename join_iterator::difference_type result;
if (m_section)
{
if (other.m_section)
result = other.m_it.it2() - m_it.it2();
else
{
result = (m_link->first2 - m_it.it2())
+ (other.m_it.it1() - m_link->last1);
BOOST_ASSERT( result <= 0 );
}
}
else
{
if (other.m_section)
{
result = (m_link->last1 - m_it.it1())
+ (other.m_it.it2() - m_link->first2);
}
else
result = other.m_it.it1() - m_it.it1();
}
return result;
}
void advance_from_range2(typename join_iterator::difference_type offset)
{
typedef typename join_iterator::difference_type difference_t;
BOOST_ASSERT( m_section == 1u );
if (offset < 0)
{
difference_t r2_dist = m_link->first2 - m_it.it2();
BOOST_ASSERT( r2_dist <= 0 );
if (offset >= r2_dist)
std::advance(m_it.it2(), offset);
else
{
difference_t r1_dist = offset - r2_dist;
BOOST_ASSERT( r1_dist <= 0 );
m_it.it1() = m_link->last1 + r1_dist;
m_section = 0u;
}
}
else
std::advance(m_it.it2(), offset);
}
void advance_from_range1(typename join_iterator::difference_type offset)
{
typedef typename join_iterator::difference_type difference_t;
BOOST_ASSERT( m_section == 0u );
if (offset > 0)
{
difference_t r1_dist = m_link->last1 - m_it.it1();
BOOST_ASSERT( r1_dist >= 0 );
if (offset < r1_dist)
std::advance(m_it.it1(), offset);
else
{
difference_t r2_dist = offset - r1_dist;
BOOST_ASSERT( r2_dist >= 0 );
m_it.it2() = m_link->first2 + r2_dist;
m_section = 1u;
}
}
else
std::advance(m_it.it1(), offset);
}
unsigned int m_section;
iterator_union m_it;
intrusive_ptr<const link_t> m_link;
friend class ::boost::iterator_core_access;
};
} // namespace range_detail
} // namespace boost
#endif // include guard

View File

@ -0,0 +1,33 @@
// Boost.Range library concept checks
//
// Copyright Neil Groves 2009. Use, modification and distribution
// are 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)
//
#ifndef BOOST_RANGE_DETAIL_MISC_CONCEPT_HPP_INCLUDED
#define BOOST_RANGE_DETAIL_MISC_CONCEPT_HPP_INCLUDED
#include <boost/concept_check.hpp>
namespace boost
{
namespace range_detail
{
template<typename T1, typename T2>
class SameTypeConcept
{
public:
BOOST_CONCEPT_USAGE(SameTypeConcept)
{
same_type(a,b);
}
private:
template<typename T> void same_type(T,T) {}
T1 a;
T2 b;
};
}
}
#endif // include guard

View File

@ -0,0 +1,180 @@
// 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_DETAIL_RANGE_RETURN_HPP_INCLUDED
#define BOOST_RANGE_DETAIL_RANGE_RETURN_HPP_INCLUDED
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/iterator_range.hpp>
namespace boost
{
enum range_return_value
{
// (*) indicates the most common values
return_found, // only the found resulting iterator (*)
return_next, // next(found) iterator
return_prior, // prior(found) iterator
return_begin_found, // [begin, found) range (*)
return_begin_next, // [begin, next(found)) range
return_begin_prior, // [begin, prior(found)) range
return_found_end, // [found, end) range (*)
return_next_end, // [next(found), end) range
return_prior_end, // [prior(found), end) range
return_begin_end // [begin, end) range
};
template< class SinglePassRange, range_return_value >
struct range_return
{
typedef boost::iterator_range<
BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type > type;
static type pack(BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type found,
SinglePassRange& rng)
{
return type(found, boost::end(rng));
}
};
template< class SinglePassRange >
struct range_return< SinglePassRange, return_found >
{
typedef BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type type;
static type pack(type found, SinglePassRange&)
{
return found;
}
};
template< class SinglePassRange >
struct range_return< SinglePassRange, return_next >
{
typedef BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type type;
static type pack(type found, SinglePassRange& rng)
{
return found == boost::end(rng)
? found
: boost::next(found);
}
};
template< class BidirectionalRange >
struct range_return< BidirectionalRange, return_prior >
{
typedef BOOST_DEDUCED_TYPENAME range_iterator<BidirectionalRange>::type type;
static type pack(type found, BidirectionalRange& rng)
{
return found == boost::begin(rng)
? found
: boost::prior(found);
}
};
template< class SinglePassRange >
struct range_return< SinglePassRange, return_begin_found >
{
typedef boost::iterator_range<
BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type > type;
static type pack(BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type found,
SinglePassRange& rng)
{
return type(boost::begin(rng), found);
}
};
template< class SinglePassRange >
struct range_return< SinglePassRange, return_begin_next >
{
typedef boost::iterator_range<
BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type > type;
static type pack(BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type found,
SinglePassRange& rng)
{
return type( boost::begin(rng),
found == boost::end(rng) ? found : boost::next(found) );
}
};
template< class BidirectionalRange >
struct range_return< BidirectionalRange, return_begin_prior >
{
typedef boost::iterator_range<
BOOST_DEDUCED_TYPENAME range_iterator<BidirectionalRange>::type > type;
static type pack(BOOST_DEDUCED_TYPENAME range_iterator<BidirectionalRange>::type found,
BidirectionalRange& rng)
{
return type( boost::begin(rng),
found == boost::begin(rng) ? found : boost::prior(found) );
}
};
template< class SinglePassRange >
struct range_return< SinglePassRange, return_found_end >
{
typedef boost::iterator_range<
BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type > type;
static type pack(BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type found,
SinglePassRange& rng)
{
return type(found, boost::end(rng));
}
};
template< class SinglePassRange >
struct range_return< SinglePassRange, return_next_end >
{
typedef boost::iterator_range<
BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type > type;
static type pack(BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type found,
SinglePassRange& rng)
{
return type( found == boost::end(rng) ? found : boost::next(found),
boost::end(rng) );
}
};
template< class BidirectionalRange >
struct range_return< BidirectionalRange, return_prior_end >
{
typedef boost::iterator_range<
BOOST_DEDUCED_TYPENAME range_iterator<BidirectionalRange>::type > type;
static type pack(BOOST_DEDUCED_TYPENAME range_iterator<BidirectionalRange>::type found,
BidirectionalRange& rng)
{
return type( found == boost::begin(rng) ? found : boost::prior(found),
boost::end(rng) );
}
};
template< class SinglePassRange >
struct range_return< SinglePassRange, return_begin_end >
{
typedef boost::iterator_range<
BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type > type;
static type pack(BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type found,
SinglePassRange& rng)
{
return type(boost::begin(rng), boost::end(rng));
}
};
}
#endif // include guard

View File

@ -0,0 +1,202 @@
// Boost.Range library
//
// Copyright Neil Groves 2010. 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_IRANGE_HPP_INCLUDED
#define BOOST_RANGE_IRANGE_HPP_INCLUDED
#include <boost/assert.hpp>
#include <boost/iterator/iterator_facade.hpp>
#include <boost/range/iterator_range.hpp>
namespace boost
{
namespace range_detail
{
// integer_iterator is an iterator over an integer sequence that
// is bounded only by the limits of the underlying integer
// representation.
//
// This is useful for implementing the irange(first, last)
// function.
//
// Note:
// This use of this iterator and irange is appreciably less
// performant than the corresponding hand-written integer
// loop on many compilers.
template<typename Integer>
class integer_iterator
: public boost::iterator_facade<
integer_iterator<Integer>,
Integer,
boost::random_access_traversal_tag,
const Integer&
>
{
typedef boost::iterator_facade<
integer_iterator<Integer>,
Integer,
boost::random_access_traversal_tag,
const Integer&
> base_t;
public:
typedef typename base_t::value_type value_type;
typedef typename base_t::difference_type difference_type;
typedef typename base_t::reference reference;
integer_iterator() : m_value() {}
explicit integer_iterator(value_type x) : m_value(x) {}
private:
void increment()
{
++m_value;
}
void decrement()
{
--m_value;
}
void advance(difference_type offset)
{
m_value += offset;
}
difference_type distance_to(const integer_iterator& other) const
{
return other.m_value - m_value;
}
bool equal(const integer_iterator& other) const
{
return m_value == other.m_value;
}
reference dereference() const
{
return m_value;
}
friend class ::boost::iterator_core_access;
value_type m_value;
};
// integer_iterator_with_step is similar in nature to the
// integer_iterator but provides the ability to 'move' in
// a number of steps specified at construction time.
//
// The three variable implementation provides the best guarantees
// of loop termination upon various combinations of input.
//
// While this design is less performant than some less
// safe alternatives, the use of ranges and iterators to
// perform counting will never be optimal anyhow, hence
// if optimal performance is desired a handcoded loop
// is the solution.
template<typename Integer>
class integer_iterator_with_step
: public boost::iterator_facade<
integer_iterator_with_step<Integer>,
Integer,
boost::random_access_traversal_tag,
Integer,
std::ptrdiff_t
>
{
typedef boost::iterator_facade<
integer_iterator_with_step<Integer>,
Integer,
boost::random_access_traversal_tag,
Integer,
std::ptrdiff_t
> base_t;
public:
typedef typename base_t::value_type value_type;
typedef typename base_t::difference_type difference_type;
typedef typename base_t::reference reference;
integer_iterator_with_step(value_type first, value_type step, difference_type step_size)
: m_first(first)
, m_step(step)
, m_step_size(step_size)
{
BOOST_ASSERT( step >= 0 );
BOOST_ASSERT( step_size != 0 );
}
private:
void increment()
{
++m_step;
}
void decrement()
{
--m_step;
}
void advance(difference_type offset)
{
m_step += offset;
}
difference_type distance_to(const integer_iterator_with_step& other) const
{
return other.m_step - m_step;
}
bool equal(const integer_iterator_with_step& other) const
{
return m_step == other.m_step;
}
reference dereference() const
{
return m_first + (m_step * m_step_size);
}
friend class ::boost::iterator_core_access;
value_type m_first;
value_type m_step;
difference_type m_step_size;
};
} // namespace range_detail
template<typename Integer>
iterator_range< range_detail::integer_iterator<Integer> >
irange(Integer first, Integer last)
{
BOOST_ASSERT( first <= last );
return boost::iterator_range< range_detail::integer_iterator<Integer> >(
range_detail::integer_iterator<Integer>(first),
range_detail::integer_iterator<Integer>(last));
}
template<typename Integer, typename StepSize>
iterator_range< range_detail::integer_iterator_with_step<Integer> >
irange(Integer first, Integer last, StepSize step_size)
{
BOOST_ASSERT( step_size != 0 );
BOOST_ASSERT( (step_size > 0) ? (last >= first) : (last <= first) );
typedef typename range_detail::integer_iterator_with_step<Integer> iterator_t;
const std::ptrdiff_t last_step
= (static_cast<std::ptrdiff_t>(last) - static_cast<std::ptrdiff_t>(first))
/ (static_cast<std::ptrdiff_t>(step_size));
return boost::iterator_range< iterator_t >(
iterator_t(first, 0, step_size),
iterator_t(first, last_step, step_size));
}
} // namespace boost
#endif // include guard

View File

@ -0,0 +1,34 @@
// Boost.Range library
//
// Copyright Neil Groves 2008. Use, modification and
// distribution is subject to the Boost Software Licence, 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_ISTREAM_RANGE_HPP_INCLUDED
#define BOOST_RANGE_ISTREAM_RANGE_HPP_INCLUDED
/*!
* \file istream_range.hpp
*/
#include <iterator>
#include <boost/config.hpp>
#include <boost/range/range.hpp>
namespace boost
{
template<class Type, class Elem, class Traits> inline
range<std::istream_iterator<Type, Elem, Traits> >
istream_range(std::basic_istream<Elem, Traits>& in)
{
return range<std::istream_iterator<Type, Elem, Traits> >(
std::istream_iterator<Type>(in),
std::istream_iterator<Type>());
}
} // namespace boost
#endif // include guard

View File

@ -1,659 +1,16 @@
// Boost.Range library
//
// Copyright Thorsten Ottosen & Pavol Droba 2003-2004. Use, modification and
// distribution is subject to the Boost Software License, Version
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// 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_ITERATOR_RANGE_HPP_INCLUDED
#define BOOST_RANGE_ITERATOR_RANGE_HPP_INCLUDED
#ifndef BOOST_RANGE_ITERATOR_RANGE_HPP
#define BOOST_RANGE_ITERATOR_RANGE_HPP
#include <boost/config.hpp> // Define __STL_CONFIG_H, if appropriate.
#include <boost/detail/workaround.hpp>
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
#pragma warning( push )
#pragma warning( disable : 4996 )
#endif
// From boost/dynamic_bitset.hpp; thanks to Matthias Troyer for Cray X1 patch.
#ifndef BOOST_OLD_IOSTREAMS
# if defined(__STL_CONFIG_H) && \
!defined (__STL_USE_NEW_IOSTREAMS) && !defined(__crayx1) \
/**/
# define BOOST_OLD_IOSTREAMS
# endif
#endif // #ifndef BOOST_OLD_IOSTREAMS
#include <boost/assert.hpp>
#include <boost/iterator/iterator_traits.hpp>
#include <boost/type_traits/is_abstract.hpp>
#include <boost/range/functions.hpp>
#include <boost/range/iterator.hpp>
#include <boost/range/difference_type.hpp>
#include <boost/utility/enable_if.hpp>
#include <iterator>
#include <algorithm>
#ifndef _STLP_NO_IOSTREAMS
# ifndef BOOST_OLD_IOSTREAMS
# include <ostream>
# else
# include <ostream.h>
# endif
#endif // _STLP_NO_IOSTREAMS
#include <cstddef>
/*! \file
Defines the \c iterator_class and related functions.
\c iterator_range is a simple wrapper of iterator pair idiom. It provides
a rich subset of Container interface.
*/
namespace boost
{
namespace iterator_range_detail
{
//
// The functions adl_begin and adl_end are implemented in a separate
// class for gcc-2.9x
//
template<typename IteratorT>
struct iterator_range_impl {
template< class ForwardRange >
static IteratorT adl_begin( ForwardRange& r )
{
return IteratorT( boost::begin( r ) );
}
template< class ForwardRange >
static IteratorT adl_end( ForwardRange& r )
{
return IteratorT( boost::end( r ) );
}
};
template< class Left, class Right >
inline bool equal( const Left& l, const Right& r )
{
typedef BOOST_DEDUCED_TYPENAME boost::range_difference<Left>::type sz_type;
sz_type l_size = boost::distance( l ),
r_size = boost::distance( r );
if( l_size != r_size )
return false;
return std::equal( boost::begin(l), boost::end(l),
boost::begin(r) );
}
template< class Left, class Right >
inline bool less_than( const Left& l, const Right& r )
{
return std::lexicographical_compare( boost::begin(l),
boost::end(l),
boost::begin(r),
boost::end(r) );
}
struct range_tag { };
struct const_range_tag { };
}
// iterator range template class -----------------------------------------//
//! iterator_range class
/*!
An \c iterator_range delimits a range in a sequence by beginning and ending iterators.
An iterator_range can be passed to an algorithm which requires a sequence as an input.
For example, the \c toupper() function may be used most frequently on strings,
but can also be used on iterator_ranges:
\code
boost::tolower( find( s, "UPPERCASE STRING" ) );
\endcode
Many algorithms working with sequences take a pair of iterators,
delimiting a working range, as an arguments. The \c iterator_range class is an
encapsulation of a range identified by a pair of iterators.
It provides a collection interface,
so it is possible to pass an instance to an algorithm requiring a collection as an input.
*/
template<typename IteratorT>
class iterator_range
{
protected: // Used by sub_range
//! implementation class
typedef iterator_range_detail::iterator_range_impl<IteratorT> impl;
public:
//! this type
typedef iterator_range<IteratorT> type;
//BOOST_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION(value_type);
//! Encapsulated value type
typedef BOOST_DEDUCED_TYPENAME
iterator_value<IteratorT>::type value_type;
//! Difference type
typedef BOOST_DEDUCED_TYPENAME
iterator_difference<IteratorT>::type difference_type;
//! Size type
typedef std::size_t size_type; // note: must be unsigned
//! This type
typedef iterator_range<IteratorT> this_type;
//! Refence type
//
// Needed because value-type is the same for
// const and non-const iterators
//
typedef BOOST_DEDUCED_TYPENAME
iterator_reference<IteratorT>::type reference;
//! const_iterator type
/*!
There is no distinction between const_iterator and iterator.
These typedefs are provides to fulfill container interface
*/
typedef IteratorT const_iterator;
//! iterator type
typedef IteratorT iterator;
private: // for return value of operator()()
typedef BOOST_DEDUCED_TYPENAME
boost::mpl::if_< boost::is_abstract<value_type>,
reference, value_type >::type abstract_value_type;
public:
iterator_range() : m_Begin( iterator() ), m_End( iterator() )
#ifndef NDEBUG
, singular( true )
#endif
{ }
//! Constructor from a pair of iterators
template< class Iterator >
iterator_range( Iterator Begin, Iterator End ) :
m_Begin(Begin), m_End(End)
#ifndef NDEBUG
, singular(false)
#endif
{}
//! Constructor from a Range
template< class Range >
iterator_range( const Range& r ) :
m_Begin( impl::adl_begin( r ) ), m_End( impl::adl_end( r ) )
#ifndef NDEBUG
, singular(false)
#endif
{}
//! Constructor from a Range
template< class Range >
iterator_range( Range& r ) :
m_Begin( impl::adl_begin( r ) ), m_End( impl::adl_end( r ) )
#ifndef NDEBUG
, singular(false)
#endif
{}
//! Constructor from a Range
template< class Range >
iterator_range( const Range& r, iterator_range_detail::const_range_tag ) :
m_Begin( impl::adl_begin( r ) ), m_End( impl::adl_end( r ) )
#ifndef NDEBUG
, singular(false)
#endif
{}
//! Constructor from a Range
template< class Range >
iterator_range( Range& r, iterator_range_detail::range_tag ) :
m_Begin( impl::adl_begin( r ) ), m_End( impl::adl_end( r ) )
#ifndef NDEBUG
, singular(false)
#endif
{}
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
this_type& operator=( const this_type& r )
{
m_Begin = r.begin();
m_End = r.end();
#ifndef NDEBUG
singular = r.singular;
#endif
return *this;
}
#endif
template< class Iterator >
iterator_range& operator=( const iterator_range<Iterator>& r )
{
m_Begin = r.begin();
m_End = r.end();
#ifndef NDEBUG
singular = r.is_singular();
#endif
return *this;
}
template< class ForwardRange >
iterator_range& operator=( ForwardRange& r )
{
m_Begin = impl::adl_begin( r );
m_End = impl::adl_end( r );
#ifndef NDEBUG
singular = false;
#endif
return *this;
}
template< class ForwardRange >
iterator_range& operator=( const ForwardRange& r )
{
m_Begin = impl::adl_begin( r );
m_End = impl::adl_end( r );
#ifndef NDEBUG
singular = false;
#endif
return *this;
}
IteratorT begin() const
{
BOOST_ASSERT( !is_singular() );
return m_Begin;
}
IteratorT end() const
{
BOOST_ASSERT( !is_singular() );
return m_End;
}
difference_type size() const
{
BOOST_ASSERT( !is_singular() );
return m_End - m_Begin;
}
bool empty() const
{
BOOST_ASSERT( !is_singular() );
return m_Begin == m_End;
}
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
operator bool() const
{
return !empty();
}
#else
typedef iterator (iterator_range::*unspecified_bool_type) () const;
operator unspecified_bool_type() const
{
return empty() ? 0: &iterator_range::end;
}
#endif
bool equal( const iterator_range& r ) const
{
BOOST_ASSERT( !is_singular() );
return m_Begin == r.m_Begin && m_End == r.m_End;
}
#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
bool operator==( const iterator_range& r ) const
{
BOOST_ASSERT( !is_singular() );
return iterator_range_detail::equal( *this, r );
}
bool operator!=( const iterator_range& r ) const
{
BOOST_ASSERT( !is_singular() );
return !operator==(r);
}
bool operator<( const iterator_range& r ) const
{
BOOST_ASSERT( !is_singular() );
return iterator_range_detail::less_than( *this, r );
}
#endif
public: // convenience
reference front() const
{
BOOST_ASSERT( !empty() );
return *m_Begin;
}
reference back() const
{
BOOST_ASSERT( !empty() );
IteratorT last( m_End );
return *--last;
}
reference operator[]( difference_type at ) const
{
BOOST_ASSERT( at >= 0 && at < size() );
return m_Begin[at];
}
//
// When storing transform iterators, operator[]()
// fails because it returns by reference. Therefore
// operator()() is provided for these cases.
//
abstract_value_type operator()( difference_type at ) const
{
BOOST_ASSERT( at >= 0 && at < size() );
return m_Begin[at];
}
iterator_range& advance_begin( difference_type n )
{
BOOST_ASSERT( !is_singular() );
std::advance( m_Begin, n );
return *this;
}
iterator_range& advance_end( difference_type n )
{
BOOST_ASSERT( !is_singular() );
std::advance( m_End, n );
return *this;
}
private:
// begin and end iterators
IteratorT m_Begin;
IteratorT m_End;
#ifndef NDEBUG
bool singular;
#endif
public:
bool is_singular() const
{
#ifndef NDEBUG
return singular;
#else
return false;
#endif
}
protected:
//
// Allow subclasses an easy way to access the
// base type
//
typedef iterator_range iterator_range_;
};
// iterator range free-standing operators ---------------------------//
#ifndef _STLP_NO_IOSTREAMS
# ifndef BOOST_OLD_IOSTREAMS
//! iterator_range output operator
/*!
Output the range to an ostream. Elements are outputed
in a sequence without separators.
*/
template< typename IteratorT, typename Elem, typename Traits >
inline std::basic_ostream<Elem,Traits>& operator<<(
std::basic_ostream<Elem, Traits>& Os,
const iterator_range<IteratorT>& r )
{
std::copy( r.begin(), r.end(),
std::ostream_iterator< BOOST_DEDUCED_TYPENAME
iterator_value<IteratorT>::type,
Elem, Traits>(Os) );
return Os;
}
# else
//! iterator_range output operator
/*!
Output the range to an ostream. Elements are outputed
in a sequence without separators.
*/
template< typename IteratorT >
inline std::ostream& operator<<(
std::ostream& Os,
const iterator_range<IteratorT>& r )
{
std::copy( r.begin(), r.end(), std::ostream_iterator<char>(Os));
return Os;
}
# endif
#endif // _STLP_NO_IOSTREAMS
/////////////////////////////////////////////////////////////////////
// comparison operators
/////////////////////////////////////////////////////////////////////
template< class IteratorT, class ForwardRange >
inline bool operator==( const ForwardRange& l,
const iterator_range<IteratorT>& r )
{
return iterator_range_detail::equal( l, r );
}
template< class IteratorT, class ForwardRange >
inline bool operator!=( const ForwardRange& l,
const iterator_range<IteratorT>& r )
{
return !iterator_range_detail::equal( l, r );
}
template< class IteratorT, class ForwardRange >
inline bool operator<( const ForwardRange& l,
const iterator_range<IteratorT>& r )
{
return iterator_range_detail::less_than( l, r );
}
#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
#else
template< class Iterator1T, class Iterator2T >
inline bool operator==( const iterator_range<Iterator1T>& l,
const iterator_range<Iterator2T>& r )
{
return iterator_range_detail::equal( l, r );
}
template< class IteratorT, class ForwardRange >
inline bool operator==( const iterator_range<IteratorT>& l,
const ForwardRange& r )
{
return iterator_range_detail::equal( l, r );
}
template< class Iterator1T, class Iterator2T >
inline bool operator!=( const iterator_range<Iterator1T>& l,
const iterator_range<Iterator2T>& r )
{
return !iterator_range_detail::equal( l, r );
}
template< class IteratorT, class ForwardRange >
inline bool operator!=( const iterator_range<IteratorT>& l,
const ForwardRange& r )
{
return !iterator_range_detail::equal( l, r );
}
template< class Iterator1T, class Iterator2T >
inline bool operator<( const iterator_range<Iterator1T>& l,
const iterator_range<Iterator2T>& r )
{
return iterator_range_detail::less_than( l, r );
}
template< class IteratorT, class ForwardRange >
inline bool operator<( const iterator_range<IteratorT>& l,
const ForwardRange& r )
{
return iterator_range_detail::less_than( l, r );
}
#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING
// iterator range utilities -----------------------------------------//
//! iterator_range construct helper
/*!
Construct an \c iterator_range from a pair of iterators
\param Begin A begin iterator
\param End An end iterator
\return iterator_range object
*/
template< typename IteratorT >
inline iterator_range< IteratorT >
make_iterator_range( IteratorT Begin, IteratorT End )
{
return iterator_range<IteratorT>( Begin, End );
}
#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
template< typename Range >
inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<Range>::type >
make_iterator_range( Range& r )
{
return iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<Range>::type >
( boost::begin( r ), boost::end( r ) );
}
#else
//! iterator_range construct helper
/*!
Construct an \c iterator_range from a \c Range containing the begin
and end iterators.
*/
template< class ForwardRange >
inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type >
make_iterator_range( ForwardRange& r )
{
return iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type >
( r, iterator_range_detail::range_tag() );
}
template< class ForwardRange >
inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type >
make_iterator_range( const ForwardRange& r )
{
return iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type >
( r, iterator_range_detail::const_range_tag() );
}
#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING
namespace iterator_range_detail
{
template< class Range >
inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<Range>::type >
make_range_impl( Range& r,
BOOST_DEDUCED_TYPENAME range_difference<Range>::type advance_begin,
BOOST_DEDUCED_TYPENAME range_difference<Range>::type advance_end )
{
//
// Not worth the effort
//
//if( advance_begin == 0 && advance_end == 0 )
// return make_iterator_range( r );
//
BOOST_DEDUCED_TYPENAME range_iterator<Range>::type
new_begin = boost::begin( r ),
new_end = boost::end( r );
std::advance( new_begin, advance_begin );
std::advance( new_end, advance_end );
return make_iterator_range( new_begin, new_end );
}
}
#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
template< class Range >
inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<Range>::type >
make_iterator_range( Range& r,
BOOST_DEDUCED_TYPENAME range_difference<Range>::type advance_begin,
BOOST_DEDUCED_TYPENAME range_difference<Range>::type advance_end )
{
//BOOST_ASSERT( advance_begin - advance_end <= size(r) && "creating invalid range" );
return iterator_range_detail::make_range_impl( r, advance_begin, advance_end );
}
#else
template< class Range >
inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<Range>::type >
make_iterator_range( Range& r,
BOOST_DEDUCED_TYPENAME range_difference<Range>::type advance_begin,
BOOST_DEDUCED_TYPENAME range_difference<Range>::type advance_end )
{
//BOOST_ASSERT( advance_begin - advance_end <= size(r) && "creating invalid range" );
return iterator_range_detail::make_range_impl( r, advance_begin, advance_end );
}
template< class Range >
inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<const Range>::type >
make_iterator_range( const Range& r,
BOOST_DEDUCED_TYPENAME range_difference<Range>::type advance_begin,
BOOST_DEDUCED_TYPENAME range_difference<Range>::type advance_end )
{
//BOOST_ASSERT( advance_begin - advance_end <= size(r) && "creating invalid range" );
return iterator_range_detail::make_range_impl( r, advance_begin, advance_end );
}
#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING
//! copy a range into a sequence
/*!
Construct a new sequence of the specified type from the elements
in the given range
\param Range An input range
\return New sequence
*/
template< typename SeqT, typename Range >
inline SeqT copy_range( const Range& r )
{
return SeqT( boost::begin( r ), boost::end( r ) );
}
} // namespace 'boost'
#undef BOOST_OLD_IOSTREAMS
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
#pragma warning( pop )
#endif
#endif
#include "boost/range/iterator_range_core.hpp"
#include "boost/range/iterator_range_io.hpp"
#endif // include guard

View File

@ -0,0 +1,540 @@
// Boost.Range library
//
// Copyright Neil Groves & Thorsten Ottosen & Pavol Droba 2003-2004.
// 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_ITERATOR_RANGE_CORE_HPP_INCLUDED
#define BOOST_RANGE_ITERATOR_RANGE_CORE_HPP_INCLUDED
#include <boost/config.hpp> // Define __STL_CONFIG_H, if appropriate.
#include <boost/detail/workaround.hpp>
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
#pragma warning( push )
#pragma warning( disable : 4996 )
#endif
#include <boost/assert.hpp>
#include <boost/iterator/iterator_traits.hpp>
#include <boost/type_traits/is_abstract.hpp>
#include <boost/range/functions.hpp>
#include <boost/range/iterator.hpp>
#include <boost/range/difference_type.hpp>
#include <boost/range/algorithm/equal.hpp>
#include <boost/utility/enable_if.hpp>
#include <iterator>
#include <algorithm>
#include <cstddef>
/*! \file
Defines the \c iterator_class and related functions.
\c iterator_range is a simple wrapper of iterator pair idiom. It provides
a rich subset of Container interface.
*/
namespace boost
{
namespace iterator_range_detail
{
//
// The functions adl_begin and adl_end are implemented in a separate
// class for gcc-2.9x
//
template<typename IteratorT>
struct iterator_range_impl {
template< class ForwardRange >
static IteratorT adl_begin( ForwardRange& r )
{
return IteratorT( boost::begin( r ) );
}
template< class ForwardRange >
static IteratorT adl_end( ForwardRange& r )
{
return IteratorT( boost::end( r ) );
}
};
template< class Left, class Right >
inline bool less_than( const Left& l, const Right& r )
{
return std::lexicographical_compare( boost::begin(l),
boost::end(l),
boost::begin(r),
boost::end(r) );
}
// This version is maintained since it is used in other boost libraries
// such as Boost.Assign
template< class Left, class Right >
inline bool equal(const Left& l, const Right& r)
{
return boost::equal(l, r);
}
struct range_tag { };
struct const_range_tag { };
}
// iterator range template class -----------------------------------------//
//! iterator_range class
/*!
An \c iterator_range delimits a range in a sequence by beginning and ending iterators.
An iterator_range can be passed to an algorithm which requires a sequence as an input.
For example, the \c toupper() function may be used most frequently on strings,
but can also be used on iterator_ranges:
\code
boost::tolower( find( s, "UPPERCASE STRING" ) );
\endcode
Many algorithms working with sequences take a pair of iterators,
delimiting a working range, as an arguments. The \c iterator_range class is an
encapsulation of a range identified by a pair of iterators.
It provides a collection interface,
so it is possible to pass an instance to an algorithm requiring a collection as an input.
*/
template<typename IteratorT>
class iterator_range
{
protected: // Used by sub_range
//! implementation class
typedef iterator_range_detail::iterator_range_impl<IteratorT> impl;
public:
//! this type
typedef iterator_range<IteratorT> type;
//BOOST_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION(value_type);
//! Encapsulated value type
typedef BOOST_DEDUCED_TYPENAME
iterator_value<IteratorT>::type value_type;
//! Difference type
typedef BOOST_DEDUCED_TYPENAME
iterator_difference<IteratorT>::type difference_type;
//! Size type
typedef std::size_t size_type; // note: must be unsigned
//! This type
typedef iterator_range<IteratorT> this_type;
//! Reference type
//
// Needed because value-type is the same for
// const and non-const iterators
//
typedef BOOST_DEDUCED_TYPENAME
iterator_reference<IteratorT>::type reference;
//! const_iterator type
/*!
There is no distinction between const_iterator and iterator.
These typedefs are provides to fulfill container interface
*/
typedef IteratorT const_iterator;
//! iterator type
typedef IteratorT iterator;
private: // for return value of operator()()
typedef BOOST_DEDUCED_TYPENAME
boost::mpl::if_< boost::is_abstract<value_type>,
reference, value_type >::type abstract_value_type;
public:
iterator_range() : m_Begin( iterator() ), m_End( iterator() )
{ }
//! Constructor from a pair of iterators
template< class Iterator >
iterator_range( Iterator Begin, Iterator End ) :
m_Begin(Begin), m_End(End)
{}
//! Constructor from a Range
template< class Range >
iterator_range( const Range& r ) :
m_Begin( impl::adl_begin( r ) ), m_End( impl::adl_end( r ) )
{}
//! Constructor from a Range
template< class Range >
iterator_range( Range& r ) :
m_Begin( impl::adl_begin( r ) ), m_End( impl::adl_end( r ) )
{}
//! Constructor from a Range
template< class Range >
iterator_range( const Range& r, iterator_range_detail::const_range_tag ) :
m_Begin( impl::adl_begin( r ) ), m_End( impl::adl_end( r ) )
{}
//! Constructor from a Range
template< class Range >
iterator_range( Range& r, iterator_range_detail::range_tag ) :
m_Begin( impl::adl_begin( r ) ), m_End( impl::adl_end( r ) )
{}
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
this_type& operator=( const this_type& r )
{
m_Begin = r.begin();
m_End = r.end();
return *this;
}
#endif
template< class Iterator >
iterator_range& operator=( const iterator_range<Iterator>& r )
{
m_Begin = r.begin();
m_End = r.end();
return *this;
}
template< class ForwardRange >
iterator_range& operator=( ForwardRange& r )
{
m_Begin = impl::adl_begin( r );
m_End = impl::adl_end( r );
return *this;
}
template< class ForwardRange >
iterator_range& operator=( const ForwardRange& r )
{
m_Begin = impl::adl_begin( r );
m_End = impl::adl_end( r );
return *this;
}
IteratorT begin() const
{
return m_Begin;
}
IteratorT end() const
{
return m_End;
}
difference_type size() const
{
return m_End - m_Begin;
}
bool empty() const
{
return m_Begin == m_End;
}
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
operator bool() const
{
return !empty();
}
#else
typedef iterator (iterator_range::*unspecified_bool_type) () const;
operator unspecified_bool_type() const
{
return empty() ? 0: &iterator_range::end;
}
#endif
bool equal( const iterator_range& r ) const
{
return m_Begin == r.m_Begin && m_End == r.m_End;
}
#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
bool operator==( const iterator_range& r ) const
{
return boost::equal( *this, r );
}
bool operator!=( const iterator_range& r ) const
{
return !operator==(r);
}
bool operator<( const iterator_range& r ) const
{
return iterator_range_detail::less_than( *this, r );
}
#endif
public: // convenience
reference front() const
{
BOOST_ASSERT( !empty() );
return *m_Begin;
}
reference back() const
{
BOOST_ASSERT( !empty() );
IteratorT last( m_End );
return *--last;
}
reference operator[]( difference_type at ) const
{
BOOST_ASSERT( at >= 0 && at < size() );
return m_Begin[at];
}
//
// When storing transform iterators, operator[]()
// fails because it returns by reference. Therefore
// operator()() is provided for these cases.
//
abstract_value_type operator()( difference_type at ) const
{
BOOST_ASSERT( at >= 0 && at < size() );
return m_Begin[at];
}
iterator_range& advance_begin( difference_type n )
{
std::advance( m_Begin, n );
return *this;
}
iterator_range& advance_end( difference_type n )
{
std::advance( m_End, n );
return *this;
}
private:
// begin and end iterators
IteratorT m_Begin;
IteratorT m_End;
protected:
//
// Allow subclasses an easy way to access the
// base type
//
typedef iterator_range iterator_range_;
};
// iterator range free-standing operators ---------------------------//
/////////////////////////////////////////////////////////////////////
// comparison operators
/////////////////////////////////////////////////////////////////////
template< class IteratorT, class ForwardRange >
inline bool operator==( const ForwardRange& l,
const iterator_range<IteratorT>& r )
{
return boost::equal( l, r );
}
template< class IteratorT, class ForwardRange >
inline bool operator!=( const ForwardRange& l,
const iterator_range<IteratorT>& r )
{
return !boost::equal( l, r );
}
template< class IteratorT, class ForwardRange >
inline bool operator<( const ForwardRange& l,
const iterator_range<IteratorT>& r )
{
return iterator_range_detail::less_than( l, r );
}
#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
#else
template< class Iterator1T, class Iterator2T >
inline bool operator==( const iterator_range<Iterator1T>& l,
const iterator_range<Iterator2T>& r )
{
return boost::equal( l, r );
}
template< class IteratorT, class ForwardRange >
inline bool operator==( const iterator_range<IteratorT>& l,
const ForwardRange& r )
{
return boost::equal( l, r );
}
template< class Iterator1T, class Iterator2T >
inline bool operator!=( const iterator_range<Iterator1T>& l,
const iterator_range<Iterator2T>& r )
{
return !boost::equal( l, r );
}
template< class IteratorT, class ForwardRange >
inline bool operator!=( const iterator_range<IteratorT>& l,
const ForwardRange& r )
{
return !boost::equal( l, r );
}
template< class Iterator1T, class Iterator2T >
inline bool operator<( const iterator_range<Iterator1T>& l,
const iterator_range<Iterator2T>& r )
{
return iterator_range_detail::less_than( l, r );
}
template< class IteratorT, class ForwardRange >
inline bool operator<( const iterator_range<IteratorT>& l,
const ForwardRange& r )
{
return iterator_range_detail::less_than( l, r );
}
#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING
// iterator range utilities -----------------------------------------//
//! iterator_range construct helper
/*!
Construct an \c iterator_range from a pair of iterators
\param Begin A begin iterator
\param End An end iterator
\return iterator_range object
*/
template< typename IteratorT >
inline iterator_range< IteratorT >
make_iterator_range( IteratorT Begin, IteratorT End )
{
return iterator_range<IteratorT>( Begin, End );
}
#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
template< typename Range >
inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<Range>::type >
make_iterator_range( Range& r )
{
return iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<Range>::type >
( boost::begin( r ), boost::end( r ) );
}
#else
//! iterator_range construct helper
/*!
Construct an \c iterator_range from a \c Range containing the begin
and end iterators.
*/
template< class ForwardRange >
inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type >
make_iterator_range( ForwardRange& r )
{
return iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type >
( r, iterator_range_detail::range_tag() );
}
template< class ForwardRange >
inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type >
make_iterator_range( const ForwardRange& r )
{
return iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type >
( r, iterator_range_detail::const_range_tag() );
}
#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING
namespace iterator_range_detail
{
template< class Range >
inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<Range>::type >
make_range_impl( Range& r,
BOOST_DEDUCED_TYPENAME range_difference<Range>::type advance_begin,
BOOST_DEDUCED_TYPENAME range_difference<Range>::type advance_end )
{
//
// Not worth the effort
//
//if( advance_begin == 0 && advance_end == 0 )
// return make_iterator_range( r );
//
BOOST_DEDUCED_TYPENAME range_iterator<Range>::type
new_begin = boost::begin( r ),
new_end = boost::end( r );
std::advance( new_begin, advance_begin );
std::advance( new_end, advance_end );
return make_iterator_range( new_begin, new_end );
}
}
#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
template< class Range >
inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<Range>::type >
make_iterator_range( Range& r,
BOOST_DEDUCED_TYPENAME range_difference<Range>::type advance_begin,
BOOST_DEDUCED_TYPENAME range_difference<Range>::type advance_end )
{
//BOOST_ASSERT( advance_begin - advance_end <= size(r) && "creating invalid range" );
return iterator_range_detail::make_range_impl( r, advance_begin, advance_end );
}
#else
template< class Range >
inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<Range>::type >
make_iterator_range( Range& r,
BOOST_DEDUCED_TYPENAME range_difference<Range>::type advance_begin,
BOOST_DEDUCED_TYPENAME range_difference<Range>::type advance_end )
{
//BOOST_ASSERT( advance_begin - advance_end <= size(r) && "creating invalid range" );
return iterator_range_detail::make_range_impl( r, advance_begin, advance_end );
}
template< class Range >
inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<const Range>::type >
make_iterator_range( const Range& r,
BOOST_DEDUCED_TYPENAME range_difference<Range>::type advance_begin,
BOOST_DEDUCED_TYPENAME range_difference<Range>::type advance_end )
{
//BOOST_ASSERT( advance_begin - advance_end <= size(r) && "creating invalid range" );
return iterator_range_detail::make_range_impl( r, advance_begin, advance_end );
}
#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING
//! copy a range into a sequence
/*!
Construct a new sequence of the specified type from the elements
in the given range
\param Range An input range
\return New sequence
*/
template< typename SeqT, typename Range >
inline SeqT copy_range( const Range& r )
{
return SeqT( boost::begin( r ), boost::end( r ) );
}
} // namespace 'boost'
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
#pragma warning( pop )
#endif
#endif

View File

@ -0,0 +1,93 @@
// 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_ITERATOR_RANGE_IO_HPP_INCLUDED
#define BOOST_RANGE_ITERATOR_RANGE_IO_HPP_INCLUDED
#include <boost/config.hpp>
#include <boost/detail/workaround.hpp>
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
#pragma warning( push )
#pragma warning( disable : 4996 )
#endif
// From boost/dynamic_bitset.hpp; thanks to Matthias Troyer for Cray X1 patch.
#ifndef BOOST_OLD_IOSTREAMS
# if defined(__STL_CONFIG_H) && \
!defined (__STL_USE_NEW_IOSTREAMS) && !defined(__crayx1) \
/**/
# define BOOST_OLD_IOSTREAMS
# endif
#endif // #ifndef BOOST_OLD_IOSTREAMS
#ifndef _STLP_NO_IOSTREAMS
# ifndef BOOST_OLD_IOSTREAMS
# include <ostream>
# else
# include <ostream.h>
# endif
#endif // _STLP_NO_IOSTREAMS
#include <boost/range/iterator_range_core.hpp>
#include <iterator>
#include <algorithm>
#include <cstddef>
namespace boost
{
#ifndef _STLP_NO_IOSTREAMS
# ifndef BOOST_OLD_IOSTREAMS
//! iterator_range output operator
/*!
Output the range to an ostream. Elements are outputed
in a sequence without separators.
*/
template< typename IteratorT, typename Elem, typename Traits >
inline std::basic_ostream<Elem,Traits>& operator<<(
std::basic_ostream<Elem, Traits>& Os,
const iterator_range<IteratorT>& r )
{
std::copy( r.begin(), r.end(),
std::ostream_iterator< BOOST_DEDUCED_TYPENAME
iterator_value<IteratorT>::type,
Elem, Traits>(Os) );
return Os;
}
# else
//! iterator_range output operator
/*!
Output the range to an ostream. Elements are outputed
in a sequence without separators.
*/
template< typename IteratorT >
inline std::ostream& operator<<(
std::ostream& Os,
const iterator_range<IteratorT>& r )
{
std::copy( r.begin(), r.end(), std::ostream_iterator<char>(Os));
return Os;
}
# endif
#endif // _STLP_NO_IOSTREAMS
} // namespace boost
#undef BOOST_OLD_IOSTREAMS
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
#pragma warning(pop)
#endif
#endif // include guard

View File

@ -0,0 +1,68 @@
// 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_JOIN_HPP_INCLUDED
#define BOOST_RANGE_JOIN_HPP_INCLUDED
#include <boost/config.hpp>
#include <boost/range/detail/join_iterator.hpp>
#include <boost/range/concepts.hpp>
#include <boost/range/iterator_range.hpp>
namespace boost
{
template<class SinglePassRange1, class SinglePassRange2>
iterator_range<range_detail::join_iterator<
BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange1>::type,
BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange2>::type,
BOOST_DEDUCED_TYPENAME add_const<
BOOST_DEDUCED_TYPENAME range_value<const SinglePassRange1>::type>::type>
>
join(const SinglePassRange1& r1, const SinglePassRange2& r2)
{
BOOST_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange1> ));
BOOST_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange2> ));
typedef range_detail::join_iterator<
BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange1>::type,
BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange2>::type,
BOOST_DEDUCED_TYPENAME add_const<
BOOST_DEDUCED_TYPENAME range_value<const SinglePassRange1>::type>::type> iterator_t;
return iterator_range<iterator_t>(
iterator_t(r1, r2, range_detail::join_iterator_begin_tag()),
iterator_t(r1, r2, range_detail::join_iterator_end_tag()));
}
template<class SinglePassRange1, class SinglePassRange2>
iterator_range<range_detail::join_iterator<
BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange1>::type,
BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange2>::type,
BOOST_DEDUCED_TYPENAME range_value<SinglePassRange1>::type>
>
join(SinglePassRange1& r1, SinglePassRange2& r2)
{
BOOST_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange1> ));
BOOST_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange2> ));
typedef range_detail::join_iterator<
BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange1>::type,
BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange2>::type,
BOOST_DEDUCED_TYPENAME range_value<SinglePassRange1>::type> iterator_t;
return iterator_range<iterator_t>(
iterator_t(r1, r2, range_detail::join_iterator_begin_tag()),
iterator_t(r1, r2, range_detail::join_iterator_end_tag()));
}
} // namespace boost
#endif // include guard

11
include/boost/range/mutable_iterator.hpp Executable file → Normal file
View File

@ -21,6 +21,7 @@
#include <boost/range/detail/iterator.hpp>
#else
#include <boost/range/detail/extract_optional_type.hpp>
#include <boost/iterator/iterator_traits.hpp>
#include <cstddef>
#include <utility>
@ -31,11 +32,13 @@ namespace boost
// default
//////////////////////////////////////////////////////////////////////////
namespace range_detail {
BOOST_RANGE_EXTRACT_OPTIONAL_TYPE( iterator )
}
template< typename C >
struct range_mutable_iterator
{
typedef BOOST_DEDUCED_TYPENAME C::iterator type;
};
struct range_mutable_iterator : range_detail::extract_iterator<C>
{};
//////////////////////////////////////////////////////////////////////////
// pair

117
include/boost/range/numeric.hpp Executable file
View File

@ -0,0 +1,117 @@
///////////////////////////////////////////////////////////////////////////////
/// \file algorithm.hpp
/// Contains range-based versions of the std algorithms
//
/////////////////////////////////////////////////////////////////////////////
// Copyright 2009 Neil Groves.
// Distributed under 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)
//
// Copyright 2006 Thorsten Ottosen.
// Distributed under 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)
//
// Copyright 2004 Eric Niebler.
// Distributed under 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)
#if defined(_MSC_VER) && _MSC_VER >= 1000
#pragma once
#endif
#ifndef BOOST_RANGE_NUMERIC_HPP
#define BOOST_RANGE_NUMERIC_HPP
#include <boost/config.hpp>
#include <boost/assert.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/concepts.hpp>
#include <numeric>
namespace boost
{
template< class SinglePassRange, class Value >
inline Value accumulate( const SinglePassRange& rng, Value init )
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange> >();
return std::accumulate( boost::begin(rng), boost::end(rng), init );
}
template< class SinglePassRange, class Value, class BinaryOperation >
inline Value accumulate( const SinglePassRange& rng, Value init, BinaryOperation op )
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange> >();
return std::accumulate( boost::begin(rng), boost::end(rng), init, op );
}
template< class SinglePassRange1, class SinglePassRange2, class Value >
inline Value inner_product( const SinglePassRange1& rng1, const SinglePassRange2& rng2, Value init )
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< SinglePassRangeConcept<SinglePassRange2> >();
BOOST_ASSERT( boost::distance(rng2) >= boost::distance(rng1) );
return std::inner_product( boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), init );
}
template< class SinglePassRange1,
class SinglePassRange2,
class Value,
class BinaryOperation1, class BinaryOperation2 >
inline Value inner_product( const SinglePassRange1& rng1, const SinglePassRange2& rng2,
Value init,
BinaryOperation1 op1, BinaryOperation2 op2 )
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange1> >();
boost::function_requires< SinglePassRangeConcept<SinglePassRange2> >();
BOOST_ASSERT( boost::distance(rng2) >= boost::distance(rng1) );
return std::inner_product( boost::begin(rng1), boost::end(rng1),
boost::begin(rng2), init, op1, op2 );
}
template< class SinglePassRange, class OutputIterator >
inline OutputIterator partial_sum ( const SinglePassRange& rng,
OutputIterator result )
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange> >();
return std::partial_sum( boost::begin(rng), boost::end(rng), result );
}
template< class SinglePassRange, class OutputIterator, class BinaryOperation >
inline OutputIterator partial_sum ( const SinglePassRange& rng, OutputIterator result,
BinaryOperation op )
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange> >();
return std::partial_sum( boost::begin(rng), boost::end(rng), result, op );
}
template< class SinglePassRange, class OutputIterator >
inline OutputIterator adjacent_difference ( const SinglePassRange& rng,
OutputIterator result )
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange> >();
return std::adjacent_difference( boost::begin(rng), boost::end(rng),
result );
}
template< class SinglePassRange, class OutputIterator, class BinaryOperation >
inline OutputIterator adjacent_difference ( const SinglePassRange& rng,
OutputIterator result,
BinaryOperation op )
{
boost::function_requires< SinglePassRangeConcept<SinglePassRange> >();
return std::adjacent_difference( boost::begin(rng), boost::end(rng),
result, op );
}
}
#endif

View File

@ -1,5 +1,6 @@
// Boost.Range library
//
// Copyright Neil Groves 2009.
// Copyright Thorsten Ottosen 2003-2004. Use, modification and
// distribution is subject to the Boost Software License, Version
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
@ -22,6 +23,7 @@
#include <boost/range/value_type.hpp>
#include <boost/range/size_type.hpp>
#include <boost/range/difference_type.hpp>
#include <boost/range/algorithm/equal.hpp>
#include <boost/assert.hpp>
#include <boost/type_traits/is_reference.hpp>
#include <boost/type_traits/remove_reference.hpp>
@ -151,14 +153,14 @@ namespace boost
inline bool operator==( const sub_range<ForwardRange>& l,
const sub_range<ForwardRange2>& r )
{
return iterator_range_detail::equal( l, r );
return boost::equal( l, r );
}
template< class ForwardRange, class ForwardRange2 >
inline bool operator!=( const sub_range<ForwardRange>& l,
const sub_range<ForwardRange2>& r )
{
return !iterator_range_detail::equal( l, r );
return !boost::equal( l, r );
}
template< class ForwardRange, class ForwardRange2 >

View File

@ -0,0 +1,73 @@
#ifndef BOOST_RANGE_UNBOUNDED_RANGE_HPP
#define BOOST_RANGE_UNBOUNDED_RANGE_HPP
#include <boost/range/iterator_range.hpp>
#include <boost/config.hpp>
namespace boost
{
template< class Iter >
struct unbounded_iterator_range : iterator_range<Iter>
{
explicit unbounded_iterator_range( Iter r )
: iterator_range<Iter>( r, r )
{
//
// Remark: by storing the same iterator
// twice, we can still allow
// comparison to execute without leading to
// operations on singular iterators
//
}
private:
bool empty() const
{
return false;
}
//
// Hide members that are illegal to use.
//
/*
void end() const;
void size() const;
void empty() const;
void equal() const;
operator bool() const;
bool operator==( unbounded_iterator_range );
bool operator!=( unbounded_iterator_range );
template< class S >
void operator[]( S s ) const;
template< class D >
void advance_end( D d ) const;
void back() const;
*/
};
template< class Iter >
inline unbounded_iterator_range<Iter> unbounded_range( Iter r )
{
return unbounded_iterator_range<Iter>(r);
}
namespace detail
{
char is_unbounded_range( ... );
template< class Iter >
long is_unbounded_range( const unbounded_iterator_range<Iter>* );
}
template< class T >
struct is_unbounded_range
{
private:
static T* ptr_;
public:
BOOST_STATIC_CONSTANT( bool,
value = sizeof(long) == sizeof(detail::is_unbounded_range(ptr_) ) );
};
}
#endif