Boost logo

Boost Users :

Subject: Re: [Boost-users] Does boost have something like this, or does it need one?
From: dhruva (dhruva_at_[hidden])
Date: 2009-03-05 21:56:37


Hello, IMO, yours is a very specific need. Ideally in a container, the begin() and end() gives you an iterator. It is not as simple as it looks. I had a similar requirement. We have a perl array like container implemented in C. Since most of the code we develop now has STL containers, I wrote a wrapper around the perl like array to behave like a STL container. Another reason I say it is not generic is because the way you traverse your internal data container may vary. I would be interested if there is some abstract interface in boost that I derive from and implement the functions to get a more standard container and iterator. -dhruva ----- Original Message ---- > From: Roberto Gimenez <chilabot_at_[hidden]> > To: boost-users_at_[hidden] > Sent: Friday, 6 March, 2009 6:09:08 AM > Subject: [Boost-users] Does boost have something like this, or does it need one? > > I need something like this: > > template > struct Array > { > private: > Type *data; > int size; > > public: > explicit Array(Type *data, int size) : data(data), size(size) > { > assert(size > 0); > } > > Type &operator[](int index) const { return data[index]; } > > Type &at(int index) const > { > assert(index > 0 && index < size); > return data[index]; > } > > Type *getData() const { return data; } > > Type *begin() const { return data; } > Type *end() const { return data + size; } > > int getSize() const { return size; } > }; > > But I think boost doesn't have it. boost::array also takes an std::size_t > template parameter but that doesn't work for what I want to do because > I want to be able to pass a function something like this: > > void myFunction(const Array&a) { ... } > > void main() > { > > int myVec1[6] = { 1,2,3,4,5,6 }; > int myVec2[2] = { 7,8 }; > > myFunction(Array(myVec1, 6)); > myFunction(Array(myVec2, 2)); > > } > > I can't do this with boost::array and std::vector allocates and I don't want > that too. Any help? > > > > > _______________________________________________ > Boost-users mailing list > Boost-users_at_[hidden] > http://lists.boost.org/mailman/listinfo.cgi/boost-users Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net