Boost logo

Boost :

Subject: [boost] [Boost.Lambda] Some new features are suggested: return, iterating yield, & local var
From: Huang Huan (mr.huanghuan_at_[hidden])
Date: 2012-01-03 07:05:50


Hi boosters,
   I'm intrested in Lambda, so I have worked out some new features, and
suggest boost lib add them. What can I do next?

NEW features:
1. return. why lambda lib do not include this?
 2. generate iterator/iteration by lambda using yield return/yield break.
3. local/global var declare and using.

1. return
e.g.
    boost::function<char(int)> f =
        (
            if_ ( _1 >= 0 )
            [
                return_('a')
            ],
            return_('b')
        );
p.s. return should be supported.

2. iterator/iteration generation by lambda using yield return/yield break
    const char* p; // we shuld use the local var inside lambda instead of
this var p. refer to section 3
    iteration<char> it =
        (
            for_(var(p) = _1, *var(p), var(p)++) [
                if_(*var(p) != ' ') [ yield_return(*var(p)) ]
                if_(*var(p) == ';') [ yield_break() ]
            ]
        ) ("I love this game; no use");
p.s.
The packing iteration interface is very like the yield keyword in C#
IEnumeable

3.local/global var declare and using
e.g.
    char a;
    var_name x, y, z;
    global_var<int>(y); // put this line inside lambda is ok, just before
use it
    (
        (
            local_var<int>(x), // local var declare
            // global_var<int>(y),
            var(a) = 'a',
            var<int>(x) = _2, // using local var x
        ),
        (
            local_var<char>(z),
            var(a),
            var<int>(x) = _1, // error! x is not local var here.
            var<int>(y), // ok for global even if another lambda
            var<char>(z) = 'b',
         )
    )
p.s.
Now, in my work. It's hard to simplify var<T>(x) to var(x). It's a hard
template working.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk