forked from boostorg/range
Boost.RangeEx merged into Boost.Range
[SVN r60897]
This commit is contained in:
255
include/boost/range/adaptor/adjacent_filtered.hpp
Normal file
255
include/boost/range/adaptor/adjacent_filtered.hpp
Normal 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
|
80
include/boost/range/adaptor/argument_fwd.hpp
Executable file
80
include/boost/range/adaptor/argument_fwd.hpp
Executable 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
|
68
include/boost/range/adaptor/copied.hpp
Executable file
68
include/boost/range/adaptor/copied.hpp
Executable 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
|
117
include/boost/range/adaptor/define_adaptor.hpp
Normal file
117
include/boost/range/adaptor/define_adaptor.hpp
Normal 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
|
102
include/boost/range/adaptor/filtered.hpp
Executable file
102
include/boost/range/adaptor/filtered.hpp
Executable 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
|
173
include/boost/range/adaptor/indexed.hpp
Executable file
173
include/boost/range/adaptor/indexed.hpp
Executable 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
|
88
include/boost/range/adaptor/indirected.hpp
Normal file
88
include/boost/range/adaptor/indirected.hpp
Normal 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
|
188
include/boost/range/adaptor/map.hpp
Executable file
188
include/boost/range/adaptor/map.hpp
Executable 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
|
134
include/boost/range/adaptor/replaced.hpp
Normal file
134
include/boost/range/adaptor/replaced.hpp
Normal 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
|
136
include/boost/range/adaptor/replaced_if.hpp
Normal file
136
include/boost/range/adaptor/replaced_if.hpp
Normal 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
|
90
include/boost/range/adaptor/reversed.hpp
Executable file
90
include/boost/range/adaptor/reversed.hpp
Executable 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
|
92
include/boost/range/adaptor/sliced.hpp
Executable file
92
include/boost/range/adaptor/sliced.hpp
Executable 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
|
149
include/boost/range/adaptor/strided.hpp
Executable file
149
include/boost/range/adaptor/strided.hpp
Executable 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
|
137
include/boost/range/adaptor/tokenized.hpp
Executable file
137
include/boost/range/adaptor/tokenized.hpp
Executable 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
|
103
include/boost/range/adaptor/transformed.hpp
Executable file
103
include/boost/range/adaptor/transformed.hpp
Executable 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
|
90
include/boost/range/adaptor/uniqued.hpp
Executable file
90
include/boost/range/adaptor/uniqued.hpp
Executable 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
|
Reference in New Issue
Block a user