$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [boost] rationale for aux_/vector0.hpp
From: Larry Evans (cppljevans_at_[hidden])
Date: 2009-04-13 06:43:01
On 04/12/09 01:55, Aleksey Gurtovoy wrote:
 > On Mon, 06 Apr 2009 08:11:06 -0500, Larry Evans
 > <cppljevans_at_[hidden]> wrote:
 >
[snip]
 >> I'm wondering why the implementation here:
 >>
 >> 
https://svn.boost.org/trac/boost/browser/trunk/boost/mpl/vector/aux_/preprocessed/typeof_based/vector10.hpp#L43 
 >>
 >> adds from the back instead of the front.  IOW, instead of:
 >>
 >> 26    template<
 >> 27          typename T0, typename T1
 >> 28        >
 >> 29    struct vector2
 >> 30        : v_item<
 >> 31              T1
 >> 32            , vector1<T0>
 >> 33            >
 >> 34    {
 >> 35        typedef vector2 type;
 >> 36    };
 >>
 >> why not:
 >>
 >> 26    template<
 >> 27          typename T0, typename T1
 >> 28        >
 >> 29    struct vector2
 >> 30        : v_item<
 >> 31              T0
 >> 32            , vector1<T1>
 >> 33            >
 >> 34    {
 >> 35        typedef vector2 type;
 >> 36    };
 >
 > The former has potential for better compilation times due to
 > memoization gains on reusing a likely existing vector(n-1)
 > instantiation in vector(n), e.g.
 >
 >   vector2<T0,T1> -> vector2<T0,T1>, vector1<T0>
 >   vector3<T0,T1,T2> -> vector3<T0,T1,T2>, vector2<T0,T1>*, vector1<T0>*
 >
 > vs.
 >
 >   vector2<T0,T1> -> vector2<T0,T1>, vector1<T1>
 >   vector3<T0,T1,T2> -> vector3<T0,T1,T2>, vector2<T1,T2>, vector1<T2>
 >
 >   (*) reused instantiation
Ah!  I see.  Hmm... what about:
   vector2<T1,T2> -> vector2<T1,T2>, vector1<T2>
   vector3<T0,T1,T2> -> vector3<T0,T1,T2>, vector2<T1,T2>*, vector1<T2>*
   (*) reused instantiation
IOW, if the vector3 differs from the vector2 by push_front, then the
latter method (using v_item starting from the head,i.e. the proposed
method) would have the memoization advantage, but if the vector3
differs from the vector2 by a push_back then the former method (using
v_item starting from the tail,i.e., the existing method) would have
the memoization advantage.
If that's right, then maybe there should be a vec_back and vec_front
where vec_back is the existing vector and vec_front is the proposed
vector. Then the docs for vec_back and vec_front would highlight why
one might be preferred over the other.  But OOPS, vec_back couldn't
take advantage of a variadic compiler since (as mentioned previously)
the existing variadic compiler only allows parameter packs at the
end.  Instead, it would have to resort to the existing preprocessor
:(.
[snip]
 > HTH,
Yes, thanks very much.
-regards,
Larry