Created
September 6, 2012 23:17
-
-
Save erincandescent/3661195 to your computer and use it in GitHub Desktop.
C++ with
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename TObj, typename TFn, typename... TArgs> | |
typename std::result_of<TFn(TArgs...)>::type with(TObj&& obj_, TFn fn, TArgs... args) | |
{ | |
TObj obj(std::move(obj_)); | |
return fn(std::foward(args)...); | |
} | |
template<typename TMutex> | |
std::lock_guard<TMutex>&& locked(TMutex& mtx) | |
{ | |
return std::move(std::lock_guard<TMutex>(mtx)); | |
} | |
// use | |
with(locked(mutex), [&]{ | |
// do locked stuff | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment