Boost logo

Boost :

From: Ross Smith (ross.s_at_[hidden])
Date: 2001-08-15 17:26:43


Darin Adler wrote:
>
> We're about halfway through the formal review period for Peter Dimov's
> Bind library (ends Sunday, August 19th), and so far I've only seen one set
> of comments (from Daryle Walker). Please take the time to review the
> library this week if you can.

I think the Bind library should be approved. It generalises the standard
binders in a useful way. I have a few minor nitpicks, mostly with the
documentation rather than the code, but no showstoppers.

There's an example under "Using bind with function pointers" that I'm
pretty sure contains a typo:

> bind covers the functionality of std::bind2nd as well:
>
> std::bind2nd(std::ptr_fun(f), 5)(x); // f(5, x)
> bind(f, 5, _2)(x); // f(5, x)

Unless I've completely misunderstood the way the placeholders are
supposed to work, the third argument in the last line should be _1.

Under "Using bind with member function pointers", I don't understand one
of the examples:

> bind(&X::f, &x, _1)(i); // (&x)->f(i)

Is this meant to imply that a pointer passed where the object is
expected will automatically be dereferenced when the function is called?
If so, why bother with the ref/cref stuff, which (as far as I can see)
seems to be accomplishing the same end (keeping a reference instead of a
copy) with more complication? Or am I missing something here? Either
way, this example definitely needs more explanation.

I really dislike the "_number" notation for placeholders. First, it
doesn't stand out -- it looks too much like an ordinary integer
argument. (This is particularly confusing in the examples in the
documentation, where most of the arguments _are_ integers.) In addition
to the visual confusion, this also means that they're only one very
small typo away from a bug that could be very hard to track down.

Second, leading underscores are dangerous. Practically everyone agrees
on that. Strictly speaking there are some uses that are legal, and I
think the bind placeholders are on the right side of the line, but I've
heard too many horror stories about compilers and libraries that play
fast and loost with this particular convention to ever trust leading
underscores to be safe, even when a strict reading of the standard says
they should be. And short, cryptic names like _1 are exactly the sort of
thing that far too many implementors tend to define as macros.

That applies to the implementation as well; a quick look at bind.hpp
revealed far too many leading underscores for my peace of mind. If they
were long names it wouldn't be quite so bad, but they include names like
_bi and _int -- again, exactly the sort of thing that some idiot is
likely to have used as a macro somewhere deep in the bowels of
<windows.h> or <unistd.h>. Please, _please_ do something about this.

As for the placeholders, I'd suggest arg1, arg2, etc., in the boost
namespace rather than (as the _1 placeholders are now) in an anonymous
namespace. Using the likes of boost::arg1 as a placeholder in user code
is much clearer. I don't think the extra verbosity should be an issue;
the C++ standard library sets (I've always thought) an excellent example
of encouraging clear naming over lazy typing.

-- 
Ross Smith <ross.s_at_[hidden]> The Internet Group, Auckland, New Zealand
========================================================================
"Unix has always lurked provocatively in the background of the operating
system wars, like the Russian Army."                  -- Neal Stephenson

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