Closed diegohavenstein closed 5 years ago
Access (with default template parameter) is not movable because std::lock_guard is not movable. The default Access class has a member std::lock_guard variable, which makes it also not movable. To make the Access class movable, you can use std::unique_lock instead if you don't mind.
There's an issue with the code you posted: it returns an rvalue reference to a temporary. As a general rule, you should not std::move something out of a function.
To get what you want, I see three possibilities.
Cheers!
Thanks!
I would like to create accessors with a helper. This will not work because Access class is not movable
template <typename T, typename... AccessArgs> auto read(safe::Lockable<T> const& obj, AccessArgs&&... accessArgs) { return std::move(safe::ReadAccess<safe::Lockable<T>>{obj, std::forward<AccessArgs> accessArgs)...}); }
Is there any particular reason not to have this?