toon-members
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Toon-members] Re: STL containers with TooN


From: E. Rosten
Subject: Re: [Toon-members] Re: STL containers with TooN
Date: Tue, 12 Jan 2010 14:14:01 +0000 (GMT)
User-agent: Alpine 2.00 (LSU 1167 2008-08-23)

On Tue, 12 Jan 2010, Gerhard Reitmayr wrote:

Hi,
On 11 Jan 2010, at 22:05, Gabriel Nützi wrote:

This code works:

list<Vector<Dynamic,double> > la;
        la.push_back(makeVector(3,1,2,3,4));
        la.push_back(makeVector(3,1,3,4));
        la.push_back(makeVector(4,2,1,2,3,4));
        la.push_back(makeVector(4,3,4));
        la.push_back(makeVector(4,2,1,2,3,4,9,2,1));
        la.push_back(makeVector(3,1,2,3,4));
        la.push_back(makeVector(3,1,3,4));
        la.push_back(makeVector(4,2,1,2,3,4));
        la.push_back(makeVector(4,3,4));
        la.push_back(makeVector(4,2,1,2,3,4,9,2,1));

        list<Vector<Dynamic,double> >::iterator it;

        for(it = la.begin();it!=la.end();it++){
                cout << *it <<endl;
        }

        advance(it,8);
        it = la.erase(la.begin(),it);
        cout <<"erase"<<endl;
        for(it = la.begin();it!=la.end();it++){
                cout << *it <<endl;
        }

but the code from Gerhard, gives the fallowing error (resizable works):
/Users/gabrielnutzi/Desktop/TooNTest/TooN/internal/vbase.hh:96: error: no matching 
function for call to 'TooN::Internal::VectorAlloc<-0x00000000000000001, 
double>::VectorAlloc()'
/Users/gabrielnutzi/Desktop/TooNTest/TooN/internal/allocator.hh:167: note: candidates 
are: TooN::Internal::VectorAlloc<-0x00000000000000001, 
Precision>::VectorAlloc(int) [with Precision = double]
/Users/gabrielnutzi/Desktop/TooNTest/TooN/internal/allocator.hh:160: note:                 
TooN::Internal::VectorAlloc<-0x00000000000000001, Precision>::VectorAlloc(const 
TooN::Internal::VectorAlloc<-0x00000000000000001, Precision>&) [with Precision = 
double]

What is the difference in allocation when it comes to a resizable ?


most likely list.push_back uses a copy constructor (creates a new list element that 
has as a member a Vector<Dynamic>) then the size is set at construction time 
and everything works.

push_back should not work for a vector as typically elements are already 
allocated and constructed and only assigned...

They're allocated, but not constructed. I think they're generally constructed in-place with placement new, or whatever passes for that in an STL allocator.


actually my code seems to fail, as there is no default constructor for 
Vector<Dynamic>, is that right ?

That's correct.

but another list implementation might work differently...

A passable solution is to use a vector<shared_ptr<Vector<> > >. Of course, C++0x will fix all our woes with its move constructors when it finally arrives...

-Ed

--
(You can't go wrong with psycho-rats.)(http://mi.eng.cam.ac.uk/~er258)

/d{def}def/f{/Times s selectfont}d/s{11}d/r{roll}d f 2/m{moveto}d -1
r 230 350 m 0 1 179{ 1 index show 88 rotate 4 mul 0 rmoveto}for/s 12
    d f pop 235 420 translate 0 0 moveto 1 2 scale show showpage

reply via email to

[Prev in Thread] Current Thread [Next in Thread]