|
Boost Users :
|
The previous message reminded me of something I wanted to ask.
I wrote an extension for Boost.Tuple that, given a type T and a Boost
N-tuple, computes the N+1 tuple (this turns out to be handy for my
application). The basic definition looks like this:
template
<
typename
R,
typename
T,
int
N = 0 >
struct
add_type {
typedef
typename
add_type<
typename R,
typename
T,
length<
typename T>::value >::type
type;
};
There's a bunch of specializations that handle the actual implementation
that are obvious specializations for non-zero values of N.
It's used like this:
typedef
typename
add_type<interval,
typename
super::region>::type region
where "interval" is the type we want to prepend in to the tuple
and "super::region" is the existing tuple. So if super::region
is tuple<A,B> then region is tuple<interval, A, B>.
Now, the actual style question: Should I have made the add_type be
(stylistically) a Boost.MPL metafunction instead? E.g., a metafunction of
two arguments (type, tuple) that produces the result tuple? Is that the
common practice? Or is that only done when intending to use Boost.MPL?
That would mean tthe usage (regardless of whether Boost.MPL itself was in
use) would be
typedef typename add_type_mf::apply<interval, super::region>::type
region;
Is that preferred (as in, a little more wordy but much clearer because of
the convention)?
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net