libcvd-members
[Top][All Lists]
Advanced

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

[libcvd-members] Image creation input iterator.


From: Edward Rosten
Subject: [libcvd-members] Image creation input iterator.
Date: Wed, 5 Jul 2006 19:02:46 -0600 (MDT)


consider this:

vector<Image<byte> > v;

You want v to have 6 32x32 images. If you do this:

vector<Image<byte> > v(6, ImageRef(32,32));

you get 6 references to the same data, since if first constructs one 32x32 image (the argument to the vector constructor) and then copy-constructs 6 images from that, so they all share the same data.

A vector can take two iterators in the constructor, so with the ImageCreatorIterator input iterator, you can do this:


ImageCreatorIterator<ImageRef> begin(ImageRef(32, 32)), end(6);
vector<Image<byte> >  v(begin, end);

Or, the one line version (ie for use in constructors)

vector<Image<byte> > v(CreateImagesBegin(ImageRef(32, 32)), 
CreateImagesEnd<ImageRef>(6));
Unfortunately, this is rather ugly, especially this part     
^^^^^^^^^^^^^^^^^^^^^

The trouble is that the constructor for v is templated (simplified):

template<class C> class vector
{
        public:
                template<class I> vector(I& begin, I& end);
};


so it can't figure out in this case:

vector<Image<byte> > v(CreateImagesBegin(ImageRef(32, 32)), 6);

that it could use the templated constructor, and then construct a new iterator from the int.

Can anyone think of a nicer way of doing this (ie constructing an STL container so it starts with N distinct images).


-Ed





reply via email to

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