I
ittium
Group,
I have a class that contains (STL) map of maps. This Class has a getMap
function that return one map out of the map of maps. I need to avoid
copies while extracting the map. There are two approaches
1. I pass a "map" reference in getMap function, the getMap method
extract appropriate map and put it in the passed map reference. It seems
copy will be made while doing
map=Extracted Map; //map is reference parameter in getMap function
2. Second option is to return a reference from the getMap function
(please ignore dangling pointer issue since this class is likely to live
forever). My doubt is
- Can I return a iterator->second as reference
- If I can return it, how can caller save it (without making a copy).
Please note that maps to be returned are big and copying them is going
to be a big overhead.'
Is there a better solution to handle this.
thanks
Ittium
I have a class that contains (STL) map of maps. This Class has a getMap
function that return one map out of the map of maps. I need to avoid
copies while extracting the map. There are two approaches
1. I pass a "map" reference in getMap function, the getMap method
extract appropriate map and put it in the passed map reference. It seems
copy will be made while doing
map=Extracted Map; //map is reference parameter in getMap function
2. Second option is to return a reference from the getMap function
(please ignore dangling pointer issue since this class is likely to live
forever). My doubt is
- Can I return a iterator->second as reference
- If I can return it, how can caller save it (without making a copy).
Please note that maps to be returned are big and copying them is going
to be a big overhead.'
Is there a better solution to handle this.
thanks
Ittium