#801 closed Bugs (None)
guard_impl objects should store references
Reported by: | braden | Owned by: | joaquintides |
---|---|---|---|
Milestone: | Component: | multi_index | |
Version: | None | Severity: | |
Keywords: | Cc: |
Description
In multi_index::detail::scope_guard, it seems to me that the guard_impl objects should store references to their parameters rather than copies. Consider the following code: T * obj = 0; scope_guard guard = make_guard(delete_T, obj); obj = create_T(); if (obj) { // do stuff } else { guard.dismiss(); } Since make_guard passes obj by copy (and the guard_impl holds a copy), the value passed to delete_T is always 0. This behavior can be defeated by explicitly giving make_guard a reference parameter: make_guard<void (*)(T*), T*&>(delete_T, obj) However, that obviously gets quite verbose; and I don't see a downside to storing the parameters as references consistently.
Change History (2)
comment:2 by , 16 years ago
Logged In: NO You're right, of course. For some reason I thought boost::ref wouldn't work here; but indeed it does. With regard to using stuff in a "detail" namespace, it's my understanding that boost doesn't make any guarantees about the consistency of its API between releases. Unless/until that changes, I think the practical value of the hint "detail" provides is only to segregate the intentional interface from the incidental one.
Note:
See TracTickets
for help on using tickets.