Subject: Re: [boost] traits classes vs. metafunctions
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2013-03-06 14:50:55


On Wednesday 06 March 2013 20:36:20 Stefan Strasser 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'm not aware of any guidelines but I typically use traits when the result
types are related and may be used together by the user.

Consider iterator_traits, which provides several properties of an iterator.
Algorithm and iterator adapter implementors will likely use value_type,
reference and category typedefs of iterator_traits. If it was divided into
several distinct metafunctions one would have to instantiate several templates
which would have a compile time impact.

OTOH, when metafunctions are rarely used together or unrelated it is better to
keep them separated.