From: Arkadiy Vertleyb (vertleyb_at_[hidden])
Date: 2004-09-02 08:41:06


"Daniel James" <daniel_at_[hidden]> wrote

> Using mpl views might be better. Currently the implementation works by
> passing a list/vector to encode and adding to it. Instead encode could
> just return the sequence for it's sub-type, which can then be combined
> using mpl::joint_view, or similar.

Note that push_back<mpl::vector<...> > requires just one template
instantiation. I am not sure why views are better. And views definitely
don't provide constant-time lookup.

>
> For example, in the current implementation:
>
> template<class V, class T> struct encode_type_impl<V, const T>
> {
> typedef
> typename encode_type<
> typename detail::push_back<
> V
> , mpl::int_<CONST_ID> >::type
> , T>::type
> type;
> };
>
> Would become something like:
>
> template<class T> struct encode_type_impl<const T>
> {
> typedef boost::mpl::joint_view<
> boost::mpl::single_view<mpl::int_<CONST_ID> >,
> encode_type<T>
> >;
> };
>
> The big advantage here is that if T has already been encoded (even as
> part of a completely different type) it can be reused. For example if
> the following were encoded:
>
> std::pair<int, int>
> std::pair<std::pair<int, int>, std::pair<int, int> >
>
> The existing versions would encode std::pair<int, int> 3 times, this
> would do it once.

Agreed, but this should be weighted against not having direct access.

Regards,
Arkadiy