
17 Aug
2015
17 Aug
'15
11:37 p.m.
On Mon, 17 Aug 2015 09:48:55 -0700, Sam Kellett <samkellett@gmail.com> wrote:
I didn't know that. I was only targeting C++03/C++11.
This should work with C++11:
template <typename T, typename F> void with(T &&t, F &&fn) { fn(std::forward<T>(t)); }
with(make_foo(), [](foo &&f) { // do things with foo. }); // foo is destroyed.
Don't think I can help w/r/t C++03 though, the lack of lambdas is a killer.
One thing this method doesn't do is automatically determine if the scope exit prematurely.