A reference to a subset of the container object

I have a quick question about a link to a subset of a collection. Consider that I have a vector of objects. Now I want to create another vector, which is a subset of this vector, and I do not want to create a copy of a subset of objects.

One of the ways I was thinking about is to create vector<auto_ptr<MyClass> >. Is this a good approach? Please suggest if you think any other containers or idioms or templates will help in this case. Thanks you

+3
source share
4 answers
+7

, , STL- , ( , )

+2

: vector<int> ( vector<size_t>, ). , ( : C/++, shared_ptr, iterator ..) , .

: "" , , "" . , STL , ( ).

, . , (, ).

0

, , , .

A sensible way to do this would be to create a kind of template template that you could build using a container reference and two indexes, and let the class do all the evaluations and error checking, although I'm not sure d be able to tell if the main container still existed at a later time ...

0
source

Source: https://habr.com/ru/post/1781488/


All Articles