|
Boost : |
From: Ed Brey (edbrey_at_[hidden])
Date: 2001-08-07 08:26:37
From: "Douglas Gregor" <gregod_at_[hidden]>
> Without the ability for a user to specify the name of the data member
(which
> would require either macro tricks or a core language change), I think
that
> this particular idiom does not lend itself well to being translated
into a
> reusable, generic library.
It certainly would be nice to have a nicely named member. For some
small classes it is not important, but in general a meaningful name is
needed. Fortunately, a meaningful name can be attached to the member by
typedefing the base class and using the qualified access to the member.
The user code would look like:
class foo: base_from_member<bar_type> {
typedef base_from_member<bar_type> meaningful_name;
void fn() {
meaningful_name::member.whatever();
}
};
The cost is an extra line of code, but that is still a nice savings over
an entirely separate class. Using base_from_member also avoids the
problem of the obfuscation that the hand-coded extra class causes: it
appears that there is a an is-implemented-in-terms-of relation, which
isn't really the intent. Base_from_member makes the intent clear, which
is just to work around an initialization ordering limitation.
So overall, even though a perfect solution isn't available, I think that
a base_from_member class would be the best of the alternatives, and
would be a useful addition to boost.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk