
Thorsten Ottosen <nesotto <at> cs.aau.dk> writes:
Thorsten Ottosen skrev:
Joaquin M Lopez Munoz skrev:
Thorsten Ottosen <nesotto <at> cs.aau.dk> writes: Additionally, why are you doing the guard selection on run time? boost::has_nothrow_copy<T>::value is a compile-time value so you can select the exact type of the guard (null or otherwise) with some Boost.MPL.
Well, I'm lazy, so I didn't want to implement the functionality twice with and without the guard. IMO the code is very clear with this macro. I think the optimizer has no problem removing the empty guard.
It seems to me that creating a null-guard conditioned on some compile-time value is quite common in containers that copy elements around.
Would it not be possible to add a bool template parameter to make_obj_guard() such we can simply write
scope_guard g = make_obj_guard<some_condition<T>::value>(...);
Yep, this seems like a general enough functionality to be included in scope_guard.hpp. I'd prefer to leave make_obj_guard like it is and add an additional make_obj_guard_if<...> (note the _if) for your use case, which creates a null_guard if the condition is not true. Would you like to do the addition yourself and commit the changes to the trunk? I'm quite busy these days to do it myself. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo