Boost logo

Boost :

Subject: Re: [boost] [lclcontext] Any interest in Pythonesque "with-as" statement in C++.
From: Sam Kellett (samkellett_at_[hidden])
Date: 2015-08-17 12:48:55


> 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.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk