|
Boost : |
From: Arkadiy Vertleyb (vertleyb_at_[hidden])
Date: 2006-01-25 21:47:07
"Eric Niebler" <eric_at_[hidden]> wrote
> Arkadiy Vertleyb wrote:
> >
> > I don't think we have Eric's opinion about the scheme... Eric, have you
> > seen the discussion about consistent type registration?
> >
>
> I skimmed it and it seems over-engineered to me. IMO, the libraries that
> will want typeof support are those which have complicated intermediate
> types -- the expression template libraries. And for those libraries,
> you'll need to register all the types that could show up in the
> resulting expression. Those can all go in one file. Done. I don't see a
> compelling reason to make it more complicated.
I think it depends. The approach you are using relies on forward
declarations, and those will not work well with the default parameters.
Consider the following:
template<class T, class Pred = std::less<T>, class A = std::allocator<T> >
class set;
BOOST_TYPEOF_REGISTER_TEMPLATE(std::set, 1) // error
BOOST_TYPEOF_REGISTER_TEMPLATE(std::set, 2) // error
BOOST_TYPEOF_REGISTER_TEMPLATE(std::set, 3) // OK
In this case you can only use the third form (as opposed to all three if the
template was defined instead of forward-declared), and so, such type as
set<int> will be encoded with five integral values instead of two, and
set<set<int> > with 17 instead of 3. And I think, if
BOOST_MPL_LIMIT_VECTOR_SIZE=50, mpl::vector<int, char> would be encoded with
51 integral values instead of 3.
I think, if you have default template parameters, and want typeof to take
advantage of them, you have to include instead of forward declare, and in
this case the approach with one registration file per header is more natural
(although not the only) option. The alternative would be to use include
guards defined in your headers to decide what to register.
Regards,
Arkadiy
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk