Boost logo

Boost :

Subject: Re: [boost] rationale for aux_/vector0.hpp
From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2009-04-12 02:55:48


On Mon, 06 Apr 2009 08:11:06 -0500, Larry Evans
<cppljevans_at_[hidden]> wrote:

> Thank you Aleksey; however, I'm not sure I made myself clear.
> I'm not wondering why vector has a push_back, 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

Personally, I also find the first formulation more intuitive.

HTH,

-- 
Aleksey Gurtovoy
MetaCommunications Engineering

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk