Boost logo

Boost :

From: Douglas Gregor (gregod_at_[hidden])
Date: 2001-08-07 11:27:19


On Tuesday 07 August 2001 10:42, you wrote:
[relative size discussion snipped]
>
> Good point. The naming advantage is small. There is still utility in
> having a standard name, so a reader unfamiliar with the pattern can
> cross-reference the name and look up pre-written documentation on what
> is being accomplished. There is no easy way to accomplish this with a
> hand-coded class. I consider this a small advantage only. And on the
> other hand, since this situation is somewhat rare, an advanced reader
> may not be familiar with the boost class, and looking it up may take
> longer than figuring out the hand-written code.

I would hope that a comment would be used to identify the pattern used in the
hand-coded version.

> > - You can add the exact constructors (for base_from_member) that you
> > require. The generic base_from_member cannot catch all possibilities
>
> (should
>
> > each parameter be a ref/const ref/value?)
>
> If the template type deduction is ever different from what you want, you
> can always specify the template parameters yourself. Yes, more typing,
> but no worse than putting the same in the constructor of the
> hand-written version.

For a constructor?

> > I'm not seeing that it is a savings at all. If at each use we need
>
> towrite
>
> > "meaningful_name::member" instead of "meaningful_name", how long
>
> before we
>
> > have actually no savings? The above example could be hand-coded very
>
> easily:
> > struct base_initializer_bar {
> > base_initializer_bar(const bar_type& b) : bar(b) {}
> >
> > bar_type bar;
> > };
>
> Indeed, hand-coding as such is pretty small, but is the above snippet
> always adequet? In some circles, the following would be preferred:
>
> namespace detail
> {
> class base_initializer_bar
> {
> protected:
> explicit base_initializer_bar(bar_type const& b): bar(b) {}
>
> bar_type bar;
> };
> } // namespace detail
>
> So it's not quite so small. Even so, if the member is referenced
> commonly, it may well still be worth hand coding, since doing so avoids
> the need for specifying "::member". On the other hand, if the member is
> referenced rarely, then base_from_member would be a convenient shortcut.

So in some cases it saves typing and in others it requires more typing, so I
don't think this makes a good case either way :).

The method of referring to the member still bothers me (i.e.,
meaningful_name::member), but not because of the typing. Using this idiom
with the base_from_member base class makes the change pervasive: every
reference to that member must be written differently because of the use of
the base class. Hand coding doesn't suffer from this drawback, so the trick
is localized to the only places it really matters: initialization.

        Doug


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