![]() |
A Range Adaptor delivers an altered presentation of one or more underlying ranges. Range Adaptors are lazy, meaning that their elements are only computed on demand. A Range Adaptor meets the following requirements unless otherwise specified:
O(1)
; it returns
in constant time.
adjacent_filtered
skips elements
while a predicate applied to adjacent pairs doesn't satisfy.
<pstade/oven/adjacent_filtered.hpp>
{a1,...,aN}
is _rng
.
{b1,...,bM}
is a subsequence
of {a1,...,aN}
.
_prd(b1, b2)
,
_prd(b2, b3)
,
..., _prd(b(M-1),
bM)
are true
.
bI
to
bJ
is minimum for all
(bI, bJ)
.
_rng
is Readable
or Lvalue.
_prd(*_begin(_rng), *_begin(_rng))
is well-formed.
_prd
is Assignable
and Default
Constructible.
_prd
shall not modify referents.
distance(_rng)
applications of the corresponding _prd
.
adjacent_transformed
is considered
as the adaptor version of std::adjacent_difference
.
It passes adjacent pairs to a function to transform repeatedly.
<pstade/oven/adjacent_transformed.hpp>
{a1,...,aN}
is _rng
.
Valid expression |
Semantics |
---|---|
|
A Major Function Object type |
|
|
|
|
|
|
_rng
is not Forward,
_value_of<_typeof(_rng)>::type
is Assignable.
!boost::empty(_rng)
_fun(*_begin(_rng), *_begin(_rng))
is well-formed.
_fun
is Assignable
and Default
Constructible.
_fun
shall not modify referents.
_cal
meets the preconditions
of _fun
.
always
returns a range which
does not change as the base range varies.
<pstade/oven/always.hpp>
Valid expression |
Semantics |
---|---|
|
|
BOOST_CHECK( equals( std::string("labor") | jointed(std::string("will be")) | always("lost"), std::string("lost") ) );
applied
, given a function
object which represents an algorithm, creates an adaptor.
<pstade/oven/applied.hpp>
Valid expression |
Semantics |
---|---|
|
|
|
|
_fun1
, _fun2
and _fun3
.
namespace lambda = boost::lambda; std::string src("abcdefghijk"); std::string s1("efg"); BOOST_CHECK( equals( std::string("efghijk"), src|applied(lambda::bind(search, lambda::_1, s1), end) ) );
checked
adds the bounds checking
ability to the base range.
<pstade/oven/checked.hpp>
Valid expression |
Semantics |
---|---|
|
|
|
|
|
|
std::out_of_range
if iterators go out of
_fwdrng
.
std::string in("012345"); std::string out("01234"); try { copy(in, boost::begin(out|checked)); } catch (std::out_of_range const& ) { return; } BOOST_CHECK(false);
cleared
lets the base range
viewed as empty.
<pstade/oven/cleared.hpp>
Valid expression |
Semantics |
---|---|
|
|
BOOST_CHECK( boost::empty( std::string("labor") | jointed(std::string("lost")) | cleared ) );
concatenated
, given a range
whose values are ranges, concatenates them.
<pstade/oven/concatenated.hpp>
SegmentIterator
is _iter_of<_typeof(_rng)>::type
.
LocalRange
is _value_of<_typeof(_rng)>::type
.
LocalIterator
is _iter_of<LocalRange>::type
.
{aI1,aI2,...,aIMI}
is *boost::next(_begin(_rng), I)
.
Valid expression |
Semantics |
---|---|
|
An up-to-Bidirectional
|
![]() |
Important |
---|---|
The last precondition implies that
|
std::string input("This is his face"); boost::regex re("\\w+"); BOOST_CHECK( equals( input|tokenized(re)|concatenated, std::string("Thisishisface") ) );
const_refs
converts the base
range into a range of const reference, then pretends
to be a range of Forward
Iterator.
![]() |
Tip |
---|---|
Strictly speaking, an iterator obtained is not a conforming Forward Iterator.
|
<pstade/oven/const_refs.hpp>
Valid expression |
Semantics |
---|---|
|
A Readable
non-Lvalue
Constant |
_value_of<_typeof(_rng)>::type
is Assignable
and Copy
Constructible.
constants
converts the base
range into a Constant
Range.
<pstade/oven/constants.hpp>
Valid expression |
Semantics |
---|---|
|
A Constant |
converted
changes range referents
to specified type.
<pstade/oven/converted.hpp>
f_
is an imaginary Function Object
which behaves as if it were v
-> boost::implicit_cast<To>(v)
.
Valid expression |
Semantics |
---|---|
|
A Major Function Object type |
|
|
|
|
|
A Pipable Function Object type |
|
|
copied_to
makes a side-effect
that copies the base range to an Output
Iterator.
<pstade/oven/copied_to.hpp>
Valid expression |
Semantics |
---|---|
|
|
std::copy(_begin(_fwdrng), _end(_fwdrng), _outit)
std::copy(_begin(_fwdrng), _end(_fwdrng), _outit)
is a valid expression.
std::copy
.
cycled
creates a circular
range from the base range.
<pstade/oven/cycled.hpp>
{a1,...,aN}
is _rng
.
Valid expression |
Semantics |
---|---|
|
A non-Swappable
|
_typeof(c)
is
convertible to boost::range_difference<_typeof(_rng)>::type
.
0 <=
c
BOOST_CHECK( equals( std::string("xyz")|cycled(3), std::string("xyzxyzxyz") ) );
delimited
, given a range
of range, adds a delimiter.
<pstade/oven/delimited.hpp>
join
is regular(boost::lambda::bind(make_jointed, _rng2, boost::lambda::_1))
.
Valid expression |
Semantics |
---|---|
|
|
make_jointed(_rng2, *_begin(_rng1))
is well-formed.
_rng1|transformed(join)|concatenated
is a valid expression.
![]() |
Tip |
---|---|
|
BOOST_CHECK( equals( std::string("abcde")|transformed(single)| delimited("--"|as_literal)|dropped(2), std::string("a--b--c--d--e") ) );
dropped
returns the suffix
of the base range after the first n
elements.
<pstade/oven/dropped.hpp>
Valid expression |
Semantics |
---|---|
|
|
_typeof(n)
is
convertible to boost::range_difference<typeof(_rng)>::type
.
0 <=
n
O(1)
if _rng
is Random
Access, and O(n)
otherwise.
BOOST_CHECK( equals( std::string("hello, dropped!")|dropped(7), std::string("dropped!") ) );
dropped_while
drops elements
from the base range while a predicate satisfies.
<pstade/oven/dropped_while.hpp>
not_
is an imaginary function
to nagate a predicate.
Valid expression |
Semantics |
---|---|
|
|
distance(_rng)
applications of the corresponding _prd
.
std::string src("11111234516313!"); BOOST_CHECK( equals( src|dropped_while(boost::lambda::_1 == '1'), std::string("234516313!") ) );
elements
is considered as
a generalization of map_keys
and map_values
.
<pstade/oven/elements.hpp>
Tup
is _value_of<_typeof(_rng)>::type
.
to_Nth
is an imaginary
function object to get the Nth element of Boost.Fusion
Sequence.
Valid expression |
Semantics |
---|---|
|
A Major Function Object type |
|
|
|
|
|
A Pipable Function Object type |
|
|
_rng
is Readable
or Lvalue.
Tup
is Fusion
Forward Sequence.
N
is a MPL
Integral Constant.
Ref
specifies boost::range_reference
type of an adapted range.
If Ref
is boost::use_default
, Ref
is determined by the following:
boost::range_reference<_typeof(_rng)>::type
is a reference type,
it is a reference type.
boost::fusion::result_of::value_of
is used to specify it.
<pstade/oven/elements.hpp>
Valid expression |
Semantics |
---|---|
|
|
|
|
|
|
filtered
returns a filter_iterator
range.
<pstade/oven/filtered.hpp>
Valid expression |
Semantics |
---|---|
|
|
T
is boost::filter_iterator<_typeof(_prd), _typeof(_begin(_rng))>
such that T(_prd, _begin(_rng), _end(_rng))
is a valid expression.
_prd
is Assignable
and Default
Constructible.
_prd
shall not modify referents.
distance(_rng)
applications of the corresponding _prd
.
identities
returns the base
range as is, but can change the traversal category.
<pstade/oven/identities.hpp>
traversal
is an imaginary
metafunction which returns a traversal tag type known as boost::xxx_traversal_tag
.
Valid expression |
Semantics |
---|---|
|
|
|
|
xxx
such that
_typeof(t)
is
boost::xxx_traversal_tag
.
traversal<_typeof(_rng)>::type
is convertible to _typeof(t)
.
indirected
adapts the base
range by applying an extra dereference inside of operator*()
.
<pstade/oven/indirected.hpp>
Valid expression |
Semantics |
---|---|
|
A Major Function Object type |
|
|
|
|
T
is boost::indirect_iterator<_iter_of<_typeof(_rng)>::type, X1,...,XN>
such that T(_begin(_rng))
is a valid expression.
int src[] = { 1,2,0,4,5 }; int answer[] = { 1,2,3,4,5 }; int *ptrs[] = {&src[0],&src[1],&src[2],&src[3],&src[4]}; BOOST_FOREACH (int& i, ptrs|indirected) { if (i == 0) i = 3; } BOOST_CHECK( equals(src, answer) );
outdirected
returns a range
whose values are iterators of the base range.
<pstade/oven/outdirected.hpp>
Valid expression |
Semantics |
---|---|
|
|
std::string const str("gefadcb"); std::string const answer("abcdefg"); std::vector<std::string::const_iterator> iters; copy(str|outdirected, std::back_inserter(iters)); sort( iters, boost::make_indirect_fun(::less_than()) ); BOOST_CHECK( equals(iters|indirected, answer) );
outplaced
provides a Random
Access view through the base range iterators.
<pstade/oven/outplaced.hpp>
iK =
boost::next(boost::begin(_fwdrng), K-1)
N
is distance(_fwdrng)
.
Valid expression |
Semantics |
---|---|
|
A Random
Access Writable
Lvalue
|
O(N)
std::list<int> lst = initial_values(6,1,3,2,5,4); sort(lst|outplaced|indirected); BOOST_CHECK( equals(lst, initial_values(1,2,3,4,5,6)) );
jointed
returns a range which
is jointed with its argument.
<pstade/oven/jointed.hpp>
{a1,...,aN}
is _rng1
.
{b1,...,bM}
is _rng2
.
cK =
a1
for all K
such that 1 <=
K &&
K <=
N
.
cK =
boost::implicit_cast<boost::range_reference<_typeof(_rng1)>::type>(b(K-N))
for all K
such that N+1
<= K
&& K
<= N+M
.
Valid expression |
Semantics |
---|---|
|
|
std::string str0("every range"); std::vector<char> str1 = std::string(" is")|copied; std::list<char> str2 = std::string(" string!?")|copied; BOOST_CHECK( equals( str0|jointed(str1)|jointed(str2), std::string("every range is string!?") ) );
map_keys
returns a range
whose values are the keys of the base associative container.
<pstade/oven/map_keys.hpp>
Valid expression |
Semantics |
---|---|
|
|
_rng|elements_c<0>()
is
a valid expression.
std::map<int, std::string> m; m[12] = "hello"; m[4] = "map"; m[99] = "keys"; BOOST_FOREACH (int k, m|map_keys) { BOOST_CHECK( k != 12 || m[k] == "hello" ); BOOST_CHECK( k != 4 || m[k] == "map" ); BOOST_CHECK( k != 99 || m[k] == "keys" ); }
map_values
returns a range
whose values are the mapped values of the base associative container.
<pstade/oven/map_values.hpp>
Valid expression |
Semantics |
---|---|
|
|
_rng|elements_c<1>()
is
a valid expression.
std::map<int, std::string> m; m[12] = "hello"; m[4] = "map"; m[99] = "keys"; BOOST_FOREACH (std::string& v, m|map_values) { if (v == "keys") v = "values"; } BOOST_CHECK( m[12] == "hello" ); BOOST_CHECK( m[4] == "map" ); BOOST_CHECK( m[99] == "values" );
memoized
returns a range
whose values are cached for speed, preparing for repeated dereferences.
<pstade/oven/memoized.hpp>
Valid expression |
Semantics |
---|---|
|
|
|
|
![]() |
Note |
---|---|
|
_rng
is Readable.
_value_of<_typeof(_rng)>::type
is Assignable.
_rng
is a recursive
range, memo_table
object
t
must be passed.
memoized
range is not Parallel Safe.
std::stringstream ss; ss << "hello, memoized!"; ::very_complicated_algorithm( oven::stream_read<char>(ss) | memoized | directed | indirected | sorted | memoized );
<pstade/oven/offset.hpp>
Valid expression |
Semantics |
---|---|
|
|
boost::next(_begin(_fwdrng), n)
is
a valid expression.
boost::next(_end(_fwdrng), m)
is
a valid expression.
n <=
distance(_fwdrng) + m
O(1)
if _fwdrng
is a Random
Access, and O(n)+O(m)
otherwise.
permuted
provides a permuted
view of a given range. That is, the view includes every element of the given
range but in a potentially different order.
<pstade/oven/permuted.hpp>
Valid expression |
Semantics |
---|---|
|
|
T
is boost::permutation_iterator<_iter_of<_typeof(_rng1)>::type, _iter_of<_typeof(_rng2)>::type>
such that T(_begin(_rng1), _begin(_rng2))
is a valid expression.
pointed
, by returning a pointer
range, provides an interface to have a conversation with legacy APIs. Also,
you can expect STL to choose optimized implementation by passing raw pointers.
<pstade/oven/pointed.hpp>
Valid expression |
Semantics |
---|---|
|
|
|
|
r
is a ContiguousRange
such that !boost::empty(r)
.
q
is a ContiguousRange
such that boost::empty(q)
.
std::string const src("hello, pointed"); std::vector<char> vec; vec.resize(distance(src) + 1); std::strcpy(boost::begin(vec|pointed), src.c_str()); BOOST_CHECK(( equals(vec|as_c_str, src) ));
popped
returns a range without
the last element.
<pstade/oven/popped.hpp>
Valid expression |
Semantics |
---|---|
|
|
!boost::empty(_rng)
_rng
is not Forward,
_value_of<_typeof(_rng)>::type
is Assignable.
A range returned from reversed
iterates in the opposite direction.
<pstade/oven/reversed.hpp>
Valid expression |
Semantics |
---|---|
|
|
T
is boost::reverse_iterator<boost::_iter_of<_typeof(_bidrng)>::type>
such that T(_begin(_bidrng))
is a valid expression.
rotated
provides a rotated
view of a given range.
<pstade/oven/rotated.hpp>
mid
is _fun(_fwdrng)
.
Valid expression |
Semantics |
---|---|
|
|
rvalues
returns a range whose
boost::range_reference
type is the same as boost::range_value
type.
<pstade/oven/rvalues.hpp>
to_v
is an imaginary function
object to convert the argument to _value_of<_typeof(_rng>)>::type
.
Valid expression |
Semantics |
---|---|
|
|
_rng
is Readable.
scanned
is similar to std::accumulate
,
but returns a range of successive reduced values from the base range.
<pstade/oven/scanned.hpp>
{a1,a2,...,aN}
is
_rng
.
{b1,b2,...,bM}
is
_rng1
.
S1
is _value_of<_typeof(_rng1)>::type
.
Valid expression |
Semantics |
---|---|
|
An up-to-Forward
Readable
non-Lvalue
Constant |
|
An up-to-Forward
Readable
non-Lvalue
Constant |
![]() |
Note |
---|---|
|
_rng
is Readable
or Lvalue.
s
is Assignable
and Copy
Constructible.
a =
_fun(_fun(s, a), a)
is well-formed, where _value_of<_typeof(_rng)>::type
a =
*_begin(_rng))
.
_rng1
is Readable
or Lvalue.
S1
is Assignable
and Copy
Constructible.
b =
_fun1(_fun1(b, b), b)
is well-formed, where _value_of<_typeof(_rng1)>::type
b =
*_begin(_rng1))
.
!boost::empty(_rng1)
_fun
and _fun1
are Assignable
and Default
Constructible.
int const src[] = { 1,2,3,4,5 }; std::string null; BOOST_FOREACH (std::string str, src|scanned(null, &::stringize)) { std::cout << "\"" << str << "\" "; } // outputs: "" "1" "12" "123" "1234" "12345"
sliced
provides a column
view of the base range.
![]() |
Important |
---|---|
This name comes from
|
<pstade/oven/sliced.hpp>
f
is _begin(_rndrng)
.
Valid expression |
Semantics |
---|---|
|
|
_typeof(s)
and
_typeof(t)
are
convertible to boost::range_difference<typeof(_rndrng)>::type
.
n
is distance(_rndrng) / t
such that n ==
0 || n % t == 0
.
0 <=
s &&
s <
t
int const answer[] = { 2,6,10,14 }; BOOST_CHECK( equals(answer, counting(0, 16)|sliced(2, 4) ) );
sorted
provides a sorted
view of the base range.
![]() |
Caution |
---|---|
Though
|
<pstade/oven/sorted.hpp>
less
is boost::lambda::_1 < boost::lambda::_2
.
Valid expression |
Semantics |
---|---|
|
A Range
which behaves as it were made by |
|
|
_prd
shall not modify referents.
O(N) +
O(NlogN)
,
where N
is distance(_fwdrng)
.
std::stringstream in; in << "cefabd"; BOOST_CHECK( equals(oven::stream_read<char>(in)|memoized|sorted, std::string("abcdef")) );
steps
, though it can't return
Bidirectional
Range,
relaxes the preconditions of sliced
and accepts a Single
Pass Range.
<pstade/oven/steps.hpp>
iK =
boost::next(boost::begin(_rng), w*K-1))
M
is the largest number
such that iM <
_end(_rng)
.
Valid expression |
Semantics |
---|---|
|
An up-to-Forward
|
_typeof(w)
is
convertible to boost::range_difference<_typeof(_rng)>::type
.
1 <=
w
int const answer[] = { 0, 40, 80 }; BOOST_CHECK( equals( counting(0, 100)|steps(10)|steps(4), answer ) );
taken
, applied to the base
range, returns the prefix of the range of length n
.
<pstade/oven/taken.hpp>
Valid expression |
Semantics |
---|---|
|
An up-to-Forward
|
![]() |
Note |
---|---|
|
_typeof(n)
is
convertible to range_difference<_typeof(_rng)>::type
.
taken_while
, applied to a
predicate and the base range, returns the longest prefix (possibly empty)
of the range of elements that satisfy the predicate.
<pstade/oven/taken_while.hpp>
not_
is an imaginary function
to nagate a predicate.
Valid expression |
Semantics |
---|---|
|
An up-to-Forward
|
_rng
is Readable
or Lvalue.
_prd
is Assignable
and Default
Constructible.
_prd
shall not modify referents.
transformed
returns a transform_iterator
range.
<pstade/oven/transformed.hpp>
Valid expression |
Semantics |
---|---|
|
A Major Function Object type |
|
|
|
|
R
specifies boost::range_reference
type of an adapted range.
T
is boost::transform_iterator<_typeof(_fun), _typeof(_begin(_rng)), R>
such that T(_begin(_rng), _fun)
is a valid expression.
R
is boost::use_default
,
_fun
must be a Polymorphic
Function Object. Then R
is regarded as boost::result_of<_typeof(_fun)(boost::range_reference<_typeof(_rng)>::type)>::type
.
_fun
is Assignable
and Default
Constructible.
_fun
and _cal
shall not modify referents.
<pstade/oven/uniqued.hpp>
not_
is an imaginary function
to nagate a predicate.
eq
is regular(boost::lambda::_1 == boost::lambda::_2)
.
Valid expression |
Semantics |
---|---|
|
|
|
|
_rng|adjacent_filtered(not_(_prd))
is a valid expression.
distance(_rng)
applications of the corresponding _prd
.
<pstade/oven/window.hpp>
Valid expression |
Semantics |
---|---|
|
|
boost::next(_begin(_fwdrng), n)
is
a valid expression.
boost::next(_begin(_fwdrng), m)
is
a valid expression.
n <=
m
O(1)
if _fwdrng
is Random
Access, and O(m)
otherwise.
Copyright © 2005 -2007 Shunsuke Sogame |