Angus Leeming <[EMAIL PROTECTED]> writes: | Lars Gullik Bjønnes wrote: >>>> bool BranchList::remove(string const & s) >>>> { >>>> List::size_type const size = list.size(); >>>> - list.remove_if(bind2nd(match(), s)); >>>> + list.remove_if(bind(equal_to<string>(), >>>> + bind(&Branch::getBranch, _1), >>>> + s)); >>>> return size != list.size(); >>>> } >>> >> | Lars! Be nice to us! Add comments explaining what this stuff is >> | equivalent to. If you're not careful, your fellow developers will >> | start to view you as the evil genius who obfuscates their >> | perfectly reasonable code and then laughs at their confusion, "Mu >> | hah hah hah!" >> >> Where is the obfuscation?
This is the Q I'd like to have answered. >> >> Actually I find the new version a lot clearer than the old one. Now >> you can actually see what "match" is doing: equal_to. std::equal_to >> takes to parameters, the elements to be compared, in this case: >> Branch::getBranch() and s. >> >> So: remove the element if equal_to is true when supplied with the >> parameters Branch::getBranc() (for each element of the list) and s. > | Yes, I understand that, because I have used bind a lot myself. | However, a comment to this effect would be good too. Why? To learn C++ programmers how to read C++? (and I am not trying to sound elitist) >> | Would boost::lambda help here? >> >> The code would probably be even clearer with boost::lambda. > | Try me. I've never actually used it, so would like to see a real-world | example I have never used it. (among the reasons: it is not getting standarized now, it is really a new paradigm for C++ programmers) >> PS. To get the more "obfuscated" stuff you should have picked the >> make_function_output_iterator stuff. Or the operator-> stuff... > | I wasn't trying to start a competition on who can write the most | obfuscated code. I was complaining that you are in danger of being | viewed in such a light. Unfair to you and unfair to the rest of us. My problem is that I cannot see how I can write a comment that is clearer than the code present. I do expect c++ programmers to understand the standard functors, and in a little while I also expect them to know of/understand std::tr1::bind. So what should the comment say? And did I say that I don't think this kind of code is obfuscated? -- Lgb