|
Boost : |
Subject: Re: [boost] traits classes vs. metafunctions
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2013-03-06 16:10:19
On Wed, Mar 6, 2013 at 11:36 AM, Stefan Strasser <strasser_at_[hidden]>wrote:
> Hi everyone,
>
> are there any guidelines for boost libraries on when to use traits classes
> and when to use a metafunction for each member of a would-be traits class?
>
I'd say use your best judgment.
I've seen both in boost libraries. c++11 uses traits classes
> (iterator_traits, pointer traits, ...), but Abrahams and Gurtovoy [1] argue
> that traits classes ("traits blobs") should be avoided "at all costs"
> because they are an unnecessary concatenation of multiple metafunctions
> into one metafunction with multiple return values.
>
> in practice, this means that if a single 'traits class member' aka
> 'metafunction result' ought to differ from the defaults, the entire traits
> class has to be reimplemented by the user, not only the metafunction whose
> result ought to differ from the default.
>
One way to mitigate that is to provide a standard, default implementation
of the traits class from which specializations can inherit and override
only that which is needed.
on the other hand, asking a user to implement 5 or more metafunctions is
> much more tedious than implementing a traits class.
>
Agreed. If this is a likely scenario, I'd think an interface that allows
you to specialize a traits class should at least be considered.
[...]
- Jeff
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk