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
vector<auto_ptr<MyClass> >
No! See: Why is using std :: auto_ptr <> with STL containers wrong?
, , boost::shared_ptr .
boost::shared_ptr
, , STL- , ( , )
: vector<int> ( vector<size_t>, ). , ( : C/++, shared_ptr, iterator ..) , .
vector<int>
vector<size_t>
shared_ptr
iterator
: "" , , "" . , STL , ( ).
, . , (, ).
, , , .
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 ...
Source: https://habr.com/ru/post/1781488/More articles:https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1781483/how-to-add-characters-to-reach-the-maximum-size-of-a-char&usg=ALkJrhjO3_dXSBO25afUUWSt2bCWkHw-dAlooking for a clean PHP code editor - editorA common way to get a reference to the calling method? - actionscript-3С# Process Exited Event Help - c#Javascript reg ex требуется целое число от 1 до 999999? - javascriptJQuery - problem with .css ('display') - jqueryHow to get into python by pressing a key without pressing the enter key? - pythonHow to get a list of uncommitted files from a turtle or svn - c #Многопроцессорность Python и сокеты не закрываются - pythonJQuery UI and maxHeight dialog box in Internet Explorer - javascriptAll Articles