pstade

PrevUpHomeNext

Utilities

adapted_to/to_base
expression
FOREACH
io.hpp
optional.hpp
regex.hpp
xpressive.hpp
nonstop
pack
partitioned
regular
regular_ref
shared_regular
split_at
zipped
unzipped
fuzipped
unfuzipped
zipped_with

Some helper function objects are given to fill the gap between Oven and other libraries.

Description

adapted_to pulls the base iterator from the adapted one.

Header
  • <pstade/oven/adapted_to_base.hpp>
Model of
Valid expressions

Valid expression

Semantics

oven::adapted_to<B>(a)

Returns the shortest a.base().base() ... .base() such that _typeof(a.base().base() ... .base()) is convertible to B.

B b = to_base(a);

B b = oven::adapted_to<B>(a);

Preconditions
  • B is Copy Constructible.
  • _typeof(a) correctly works with boost::is_convertible.
  • There is a (possibly empty) sequence { base(), ..., base() } such that _typeof(a.base().base() ... .base()) is B.
Example
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' );
Description

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.

Header
  • <pstade/oven/expression.hpp>
Model of
Valid expressions

Valid expression

Semantics

expression(_rng)

[_begin(_rng), _end(_rng)) which can be used with Boost.Typeof macros.

Preconditions
  • _typeof(*boost::begin(_rng)) is the same as _value_of<_typeof(_rng)>::type.
  • _value_of<_typeof(_rng)>::type is registered to Boost.Typeof.
[Note] Note

As far as the precondition met, expression with Boost.Typeof macros is portable even where native typeof isn't available.

Example
BOOST_AUTO(factorials,
    expression(counting(1, max_count)|scanned(1, regular(boost::lambda::_1 * boost::lambda::_2))) );
See also
Description

PSTADE_OVEN_FOREACH is similar to BOOST_FOREACH, but there is no need to write the referent type of iterating.

Header
  • <pstade/oven/foreach.hpp>
Notation
  • auto is an imaginary operator such that auto x = y; is the same as _typeof(y) x = y;
Valid expression and Semantics
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] Important

The semantics implies that the range referents must outlive the PSTADE_OVEN_FOREACH statement. Unlike BOOST_FOREACH, it doens't copy a rvalue _rng.

Preconditions
  • The preconditions of expression(_rng).
  • The corresponding semantics behavior is well-defined.
  • If _rng is a dependent name, PSTADE_OVEN_FOREACH_TPL must be used instead.
Example
std::string hello("Hello, world!");
PSTADE_OVEN_FOREACH (ch, hello) {
    std::cout << ch;
}
See also
Description

The header <pstade/oven/io.hpp> lets Oven ranges be Input Streamable and Output Streamable.

Header
  • <pstade/oven/io.hpp>
Effects
Example
std::string src("abc");
std::stringstream ss;
ss << (src|identities);
BOOST_CHECK( ss.str() == "{a,b,c}" );
Description

The header <pstade/oven/optional.hpp> lets boost::optional be a model of Range, meaning that it can be used as "one element range".

Header
  • <pstade/oven/optional.hpp>
Effects
Invariants
  • An uninitialized boost::optional is an empty range.
See also
Description

The header <pstade/oven/regex.hpp> lets boost::sub_match be a model of Range.

Header
  • <pstade/oven/regex.hpp>
Effects
  • boost::sub_match becomes a Range.
See also
Description

The header <pstade/oven/xpressive.hpp> lets boost::xpressive::sub_match be a model of Range.

Header
  • <pstade/oven/xpressive.hpp>
Effects
  • boost::xpressive::sub_match becomes a Range.
See also
Description

The Stoppable Generator concept which generation requires is slightly different from the Generator concept. nonstop turns a Generator into a generation conforming one.

Header
  • <pstade/oven/generation.hpp>
Model of
Valid expressions

Valid expression

Semantics

nonstop(g)

Converts g into a Stoppable Generator.

Preconditions
Example
BOOST_FOREACH (long x, generation(nonstop(&std::rand))|taken(30)) {
    std::cout << "," << x;
}
See also
Description

pack makes a tuple of iterator ranges, which is useful for zipped.

Header
  • <pstade/oven/pack.hpp>
Model of
Notation
Valid expressions

Valid expression

Semantics

pack(_rng1,...,_rngN)

boost::make_tuple(make_range(_rng1),...,make_range(_rngN))

Preconditions
  • 1 <= N && N <= 5
  • The corresponding semantics is a valid expression.
Example
See also
Description

partitioned serves as a lazy std::partition.

Header
  • <pstade/oven/partitioned.hpp>
Model of
Notation
  • not_ is an imaginary function to negate a predicate.
Valid expressions

Valid expression

Semantics

_fwdrng|partitioned(_prd)

std::make_pair(_fwdrng|filtered(_prd), _fwdrng|filtered(not_(_prd)))

Preconditions
  • _fwdrng|filtered(_prd) is a valid expression.
Example
See also
Description

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.

Header
  • <pstade/oven/regular.hpp>
Model of
Valid expressions

Valid expression

Semantics

regular(f)

Converts f into a Major Function Object which is Default Constructible and Assignable.

Preconditions
Example
BOOST_CHECK( equals(
    std::string("abcdefg")
        | filtered(regular(boost::lambda::_1 != 'c'))
        | filtered(regular(boost::lambda::_1 != 'f')),
    std::string("abdeg")
) );
See also
Description

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.

Header
  • <pstade/oven/regular.hpp>
Model of
Valid expressions

Valid expression

Semantics

regular_ref(f)

A copyable Major Function Object. All the calls are forwarded to f.

Preconditions
See also
Description

shared_regular is similar to regular_ref. It takes a pointer to heap allocated Function Object, whereas regular_ref takes an object.

Header
  • <pstade/oven/shared_regular.hpp>
Model of
Valid expressions

Valid expression

Semantics

shared_regular(pf)

A copyable Major Function Object. All the calls are forwarded to *pf.

Preconditions
See also
Description
Header
  • <pstade/oven/split_at.hpp>
Model of
Notation
  • rng2 is _fwdrng|dropped(n).
Valid expressions

Valid expression

Semantics

_fwdrng|split_at(n)

std::make_pair([_begin(_fwdrng), _begin(rng2)), rng2)

Preconditions
  • _fwdrng|dropped(n) is a valid expression.
Example
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)
        );
    }
}
See also
Description

zipped takes a tuple of ranges and returns a range of corresponding tuples.

Header
  • <pstade/oven/zipped.hpp>
Model of
Notation
  • (_rng1 _rng2 ... _rngN) is u.
Valid expressions

Valid expression

Semantics

u|zipped

[T(boost::make_tuple(_begin(_rng1),...,_begin(_rngN))), T(boost::make_tuple(_end(_rng1),...,_end(_rngN))))

Preconditions
  • 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.
Example
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)}
See also
Description

unzipped reverses zipped.

Header
  • <pstade/oven/unzipped.hpp>
Model of
Notation
  • {(a11 a12 ... a1N),(a21 a22 ... a2N),...,(aM1 aM2 ... aMN)} is _rng.
Valid expressions

Valid expression

Semantics

_rng|unzipped

({a11,a21,...,aM1} {a12,a22,...,aM2} ... {a1N,a2N,...,aMN})

Preconditions
  • _value_of<_typeof(_rng)>::type is a boost::tuple.
Example
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})
See also
Description

fuzipped takes a Fusion Sequence of ranges and returns a range of corresponding Fusion Sequence.

Header
  • <pstade/oven/fuzipped.hpp>
Model of
Notation
  • (_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 expressions

Valid expression

Semantics

u|fuzipped

[T(boost::fusion::make_vector(_begin(_rng1),...,_begin(_rngN))), T(boost::fusion::make_vector(_end(_rng1),...,_end(_rngN))))

Preconditions
  • 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.
Example
See also
Description

unfuzipped reverses fuzipped.

Header
  • <pstade/oven/unfuzipped.hpp>
Model of
Notation
  • {a1,...,aN} is _rng.
  • at<RefSeq, I>::type is boost::mpl::at_c<RefSeq, I>::type.
Valid expressions

Valid expression

Semantics

X_make_unfuzipped<RefSeq = boost::use_default>

A Major Function Object type

X_make_unfuzipped<RefSeq = boost::use_default>()(_rng)

A Fusion Random Access Sequence (X_make_elements_c<0, at<RefSeq, 0>::type>()(a1) ... X_make_elements_c<N-1, at<RefSeq, N-1>::type>()(aN))

_rng|unfuzipped

X_make_unfuzipped<>()(_rng)

Preconditions
  • The corresponding semantics is a valid expression.
See also
Description

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.

Header
  • <pstade/oven/zipped_with.hpp>
Model of
Notation
  • fuse is an imaginary function to turn the argument into the one taking a boost::tuple as the parameter.
Valid expressions

Valid expression

Semantics

X_make_zipped_with<R>

A Major Function Object type

X_make_zipped_with<R>()(u, _fun)

u|fuzipped|X_make_transformed<R>()(fuse(_fun))

X_make_zipped_with<>()(u, _cal)

u|fuzipped|X_make_transformed<>()(fuse(_cal))

u|zipped_with(_cal)

X_make_zipped_with<>()(u, _cal)

Preconditions
  • 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.
See also
Copyright 2005 -2007 Shunsuke Sogame

PrevUpHomeNext