How to figure out if a boost class does lazy copy or not?

Hi, I need to construct some container in a function and return it. I think that some container in boost follow lazy copy sematics but some don't. For example, if tr1::unordered_map uses lazy copy, then I can return an object of tr1::unordered_map. Otherwise, I should return boost::shared_ptrtr1::unordered_map. Although this information may be documented for any container that I will use, I still think that it is still worthwhile to having my own test case to figure it out, because it may not easy to find such information in the document. I'm wondering if there is a generic way to test if a container use lazy copy or not without reading the actual implementation of the class? -- Regards, Peng

AMDG Peng Yu wrote:
I need to construct some container in a function and return it. I think that some container in boost follow lazy copy sematics but some don't.
Meaning copy on write? I don't think that any containers in Boost use copy on write.
For example, if tr1::unordered_map uses lazy copy, then I can return an object of tr1::unordered_map. Otherwise, I should return boost::shared_ptrtr1::unordered_map.
Are you sure that RVO isn't enough?
Although this information may be documented for any container that I will use, I still think that it is still worthwhile to having my own test case to figure it out, because it may not easy to find such information in the document. I'm wondering if there is a generic way to test if a container use lazy copy or not without reading the actual implementation of the class?
In Christ, Steven Watanabe

On Sat, Jun 12, 2010 at 6:43 PM, Steven Watanabe
AMDG
Peng Yu wrote:
I need to construct some container in a function and return it. I think that some container in boost follow lazy copy sematics but some don't.
Meaning copy on write? I don't think that any containers in Boost use copy on write.
For example, if tr1::unordered_map uses lazy copy, then I can return an object of tr1::unordered_map. Otherwise, I should return boost::shared_ptrtr1::unordered_map.
Are you sure that RVO isn't enough?
I don't know. Does anybody know if RVO is enough? If tr1::unordered_map is returned from a function A, and the function A is called by function B, which does something on the returned tr1::unordered_map and returned it as well. Considering this chain continues many levels, Z->...->B->A. Does RVO work for this case? -- Regards, Peng
participants (2)
-
Peng Yu
-
Steven Watanabe