Boost logo

Boost Users :

Subject: Re: [Boost-users] Ranges to Collections
From: Akira Takahashi (faithandbrave_at_[hidden])
Date: 2011-06-07 12:13:50


> your project is an effort to add those remaining
> features to Boost Ranges?

I mean to.

> I don't understand the "|+" usage at all.

"|+" is oven::regular() function's syntax sugar version.
regular() is needed when using lambda(C++0x and BLL) in Range adaptor.
Lambda is NonDefaultConstructible and NonCopyAssignable. regular()
convert lambda into DefaultConstructible and CopyAssignable.
Lambda becomes a problem in the following case:

template <class Iterator, class F>
F for_each(Iterator first, Iterator last, F f)
{
    Iterator it; // DefaultConstruct
    it = first; // CopyAssign
    for (; it != last; ++it)
        f(*it);
    return f;
}

template <class Range, class F>
F for_each(const Range& r, F f)
{
    return for_each(boost::begin(r), boost::end(r), f);
}

for_each(v | filtered(_1 % 2 == 0)); // error! filter_iterator is
NonDefaultConstructible and NonCopyAssignable

This problem solve by regular() :

for_each(v | filtered(regular(_1 % 2 == 0))); // OK, but verbose...

But since regular() was verbose, it prepared the short notation: "operator|+"

for_each(v |+ filtered(_1 % 2 == 0)); // OK

>>========================
Akira Takahashi
mailto : faithandbrave_at_[hidden]
blog : http://d.hatena.ne.jp/faith_and_brave/


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net