c++ - Validity of pointers after moving a std::set -


i have structure conceptually has following

class c {/* expensive class */}; struct mapping {     std::map<std::pair<c,c>, c> the_map; }; 

this less ideal large number of copies of c end being stored. current solution create set of c , store pointers (or iterators) in map.

struct mapping {     std::set<c> all_cs;     std::map<std::pair<c*, c*>, c*> the_map; }; 

this should safe the_map destructed before all_cs pointers valid.

copy construction can done copies set , reconstructing map possible efficiently implement move construction?

from understand, moving set same allocator required constant operation (i assume) forces implementation maintain validity of pointers objects in set cannot find in standard. using should able implement move constructor moving both set , map , of pointers correctly owned new object.

is this reasoning correct , can rely on behaviour in portable way?

move construction guaranteed preserve objects in container, table 99 (allocator-aware container requirements). in addition constant complexity requirement (which precludes reallocating elements), post-condition x u(rv) states:

u shall have same elements rv had before construction;

move assignment not give same guarantee. allocate new elements if allocator's traits tell not propagate allocator, , not explicitly state won't otherwise.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -