Christian Ridderström <[EMAIL PROTECTED]> writes:

| On Sun, 4 Jan 2004, Lars Gullik Bjønnes wrote:
>
>> >> Where is the obfuscation?
>
| I found 
>
|       list.remove_if(bind2nd(match(), s));
>
| easier to understand on a high level compared to
>
|       list.remove_if(bind(equal_to<string>(),
|                             bind(&Branch::getBranch, _1),
|                             s));
>
| but I've never written C++ code with functors...

match is a functor...

So to understand the first variant you have to inspect what match is
doing. The first variant would be ok if match had a proper name.

but regardless it should IMHO be written like:

list.remove_if(bind(match(), _1, s));
(but I am not sure that it is allowed)

| I think this is a case of 
| hiding v.s. showing the details respectively. In this case, I get a
| bit of an information overload when I have to decipher all the
| levels of () etc. 
| Another problem is that I don't know what the purpose is of 
>
|       bind(&Branch::getBranch, _1)

What can I say... bind is going to be part of TR1.
And it is easy to learn this construct.
 
>
| so I have to guess that, but with only 'match()' I immediately
| understand that it's about matching. Of course, I don't know _how_
| it works, to get an idea of what it does that's not necessary.

So you have no idea _what_ it matches and find still find it nice.

| Anyway, looking at it a bit, I see how it works and it's not that 
| difficult, it's just a bit much in one statement.
>
| Maybe it would be more readable if a local variable was used for 
|                               bind(&Branch::getBranch, _1)...  )
| Perhaps like this (and remember that I don't know how to use
| functors): 

Remember that a functor is just a class that has a operator().

|    // Temporary operator that returns branch of element.
|    ??? getBranchOperator = bind(&Branch::getBranch, _1);

Nah..

what this is:

     _1->getBranch()

>> >> | Would boost::lambda help here?
>
| Just guessing from the name 'lambda'... isn't it like the lambda
| operator in lisp etc? 

A little bit.

I am not sure of the lambda syntax, but it might look like:

  _1->getBranch() == name

| If so, it'd probably help me (but then I like using lambda
| constructors...). 

I have not dared to try to introduce those...

-- 
        Lgb

Reply via email to