![]() |
Some helper function objects are given to fill the gap between Oven and other libraries.
adapted_to
pulls the base
iterator from the adapted one.
<pstade/oven/adapted_to_base.hpp>
to_base
is an AmbiStatic
Function Object.
Valid expression |
Semantics |
---|---|
|
Returns the shortest |
|
|
B
is Copy
Constructible.
_typeof(a)
correctly
works with boost::is_convertible
.
{
base(),
..., base() }
such
that _typeof(a.base().base() ... .base())
is B
.
std::string src("cjaigvwzenqhe"); std::string::const_iterator it = max_element( src | filtered(regular(boost::lambda::_1 != 'z')) | filtered(regular(boost::lambda::_1 != 'w')) )|to_base; BOOST_CHECK( *it == 'v' );
any_range incurs an overhead
for calling a virtual
function
every iterator operation. The overhead can be removed with the help of Boost.Typeof if
your compiler supports the native typeof. expression
converts a range into Boost.Typeof
compatible one, then removes the overhead if possible.
<pstade/oven/expression.hpp>
Valid expression |
Semantics |
---|---|
|
|
_typeof(*boost::begin(_rng))
is the same as _value_of<_typeof(_rng)>::type
.
_value_of<_typeof(_rng)>::type
is registered to Boost.Typeof.
![]() |
Note |
---|---|
As far as the precondition met,
|
BOOST_AUTO(factorials, expression(counting(1, max_count)|scanned(1, regular(boost::lambda::_1 * boost::lambda::_2))) );
PSTADE_OVEN_FOREACH
is similar
to BOOST_FOREACH
, but there
is no need to write the referent type of iterating.
<pstade/oven/foreach.hpp>
auto
is an imaginary operator
such that auto x
= y;
is the same as _typeof(y)
x =
y;
PSTADE_OVEN_FOREACH(var, _rng) statement
is conceptually equivalent to
auto __rng = expression(_rng); for (auto __begin = boost::begin(__rng), __end = boost::end(__rng); __begin != __end; ++__begin) { boost::iterator_reference<_typeof(__begin)>::type var = *__begin; statement }
, where __rng
, __begin
and __end
are variables defined for exposition only.
![]() |
Important |
---|---|
The semantics implies that the range referents must outlive the
|
expression(_rng)
.
_rng
is a dependent
name, PSTADE_OVEN_FOREACH_TPL
must be used instead.
std::string hello("Hello, world!"); PSTADE_OVEN_FOREACH (ch, hello) { std::cout << ch; }
The header <pstade/oven/io.hpp>
lets Oven ranges be Input
Streamable and Output
Streamable.
<pstade/oven/io.hpp>
std::string src("abc"); std::stringstream ss; ss << (src|identities); BOOST_CHECK( ss.str() == "{a,b,c}" );
The header <pstade/oven/optional.hpp>
lets boost::optional
be a model of Range,
meaning that it can be used as "one element range".
<pstade/oven/optional.hpp>
boost::optional
becomes a Random
AccessRange.
boost::optional
is an empty range.
The header <pstade/oven/regex.hpp>
lets boost::sub_match
be a model of Range.
<pstade/oven/regex.hpp>
boost::sub_match
becomes a Range.
The header <pstade/oven/xpressive.hpp>
lets boost::xpressive::sub_match
be a model of Range.
<pstade/oven/xpressive.hpp>
boost::xpressive::sub_match
becomes a Range.
The Stoppable Generator
concept which generation requires
is slightly different from the Generator
concept. nonstop
turns a
Generator
into a generation conforming
one.
<pstade/oven/generation.hpp>
Valid expression |
Semantics |
---|---|
|
Converts |
g
is a both Generator
and Polymorphic
Function Object.
BOOST_FOREACH (long x, generation(nonstop(&std::rand))|taken(30)) { std::cout << "," << x; }
pack
makes a tuple of iterator
ranges, which is useful for zipped.
<pstade/oven/pack.hpp>
Valid expression |
Semantics |
---|---|
|
|
1 <=
N &&
N <=
5
partitioned
serves as a lazy
std::partition
.
<pstade/oven/partitioned.hpp>
not_
is an imaginary function
to negate a predicate.
Valid expression |
Semantics |
---|---|
|
|
_fwdrng|filtered(_prd)
is a valid expression.
A Boost.Lambda
functor is neither Default
Constructible nor Assignable.
An iterator holding such a functor can't conform to even Input
Iterator. regular
converts it into comfortable one for iterators.
<pstade/oven/regular.hpp>
Valid expression |
Semantics |
---|---|
|
Converts |
f
is a Boost.Lambda
functor or Polymorphic
Function Object.
BOOST_CHECK( equals( std::string("abcdefg") | filtered(regular(boost::lambda::_1 != 'c')) | filtered(regular(boost::lambda::_1 != 'f')), std::string("abdeg") ) );
A Polymorphic
Function Object like a random number generator may not be copyable,
while many algorithms require to be. regular_ref
,
holding a reference to noncopyable Polymorphic
Function Object, behaves as copyable one.
<pstade/oven/regular.hpp>
Valid expression |
Semantics |
---|---|
|
A copyable Major
Function Object. All the calls are forwarded to |
f
is a Polymorphic
Function Object but may be noncopyable.
f
is not destructed as
long as regular_ref(f)
is
called.
shared_regular
is similar
to regular_ref
. It takes
a pointer to heap allocated Function
Object, whereas regular_ref
takes an object.
<pstade/oven/shared_regular.hpp>
Valid expression |
Semantics |
---|---|
|
A copyable Major
Function Object. All the calls are forwarded to |
_typeof(*pf)
is
a Polymorphic
Function Object but may be noncopyable.
boost::shared_ptr<_typeof(*pf)>(pf)
is
a valid expression.
<pstade/oven/split_at.hpp>
rng2
is _fwdrng|dropped(n)
.
Valid expression |
Semantics |
---|---|
|
|
_fwdrng|dropped(n)
is
a valid expression.
typedef any_range<int const&, boost::forward_traversal_tag> range; range merge_sort(range rng) { typedef boost::result_of<T_distance(range&)>::type diff_t; diff_t const d = distance(rng); if (d < 2) return rng; else { boost::result_of<T_make_split_at(range&, diff_t)>::type xs_ys = make_split_at(rng, d/2); return make_merged( merge_sort(xs_ys.first), merge_sort(xs_ys.second) ); } }
zipped
takes a tuple of ranges
and returns a range of corresponding tuples.
<pstade/oven/zipped.hpp>
(_rng1
_rng2 ...
_rngN)
is u
.
Valid expression |
Semantics |
---|---|
|
|
T
is boost::zip_iterator<_typeof(boost::make_tuple(_begin(_rng1),...,_begin(_rngN)))>
such that T(boost::make_tuple(_begin(_rng1),...,_begin(_rngN)))
is a valid expression.
std::cout << ( boost::make_tuple( boost::assign::list_of(1)(2)(3), boost::assign::list_of(2)(3)(4) ) | zipped ); // output> {(1 2),(2 3),(3 4)}
unzipped
reverses zipped
.
<pstade/oven/unzipped.hpp>
{(a11
a12 ...
a1N),(a21 a22
... a2N),...,(aM1
aM2 ...
aMN)}
is _rng
.
Valid expression |
Semantics |
---|---|
|
|
_value_of<_typeof(_rng)>::type
is a boost::tuple
.
std::cout << ( boost::assign::list_of (boost::make_tuple(1,2)) (boost::make_tuple(2,3)) (boost::make_tuple(3,4)) | unzipped ); // output> ({1,2,3} {2,3,4})
fuzipped
takes a Fusion
Sequence of ranges and returns a range of corresponding Fusion
Sequence.
<pstade/oven/fuzipped.hpp>
(_rng1
_rng2 ...
_rngN)
is u
.
fuzip_iterator
is an imaginary
iterator which works like boost::zip_iterator
but whose value_type
is
a Fusion
Random Access Sequence.
Valid expression |
Semantics |
---|---|
|
|
T
is fuzip_iterator<_typeof(boost::make_tuple(_begin(_rng1),...,_begin(_rngN)))>
such that T(boost::fusion::make_vector(_begin(_rng1),...,_begin(_rngN)))
is a valid expression.
unfuzipped
reverses fuzipped
.
<pstade/oven/unfuzipped.hpp>
{a1,...,aN}
is _rng
.
at<RefSeq, I>::type
is boost::mpl::at_c<RefSeq, I>::type
.
Valid expression |
Semantics |
---|---|
|
A Major Function Object type |
|
A Fusion
Random Access Sequence |
|
|
Though zipped
accepts a function
taking a boost::tuple
as the parameter, such a function
is not so common. zipped_with
accepts a "normal" function, then turns it into comfortable one
for zipped
before passing.
<pstade/oven/zipped_with.hpp>
fuse
is an imaginary function
to turn the argument into the one taking a boost::tuple
as the parameter.
Valid expression |
Semantics |
---|---|
|
A Major Function Object type |
|
|
|
|
|
|
u
is a boost::tuple
or Fusion
Forward Sequence.
u|zipped|X_make_transformed<R>(fuse(_fun))
or u|fuzipped|X_make_transformed<R>(fuse(_fun))
is a valid expressin.
u|zipped|transformed(fuse(_cal))
or u|fuzipped|transformed(fuse(_cal))
is a valid expressin.
Copyright © 2005 -2007 Shunsuke Sogame |