Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScopedAccess classes are unwieldy #2

Open
reuk opened this issue Dec 4, 2019 · 0 comments
Open

ScopedAccess classes are unwieldy #2

reuk opened this issue Dec 4, 2019 · 0 comments

Comments

@reuk
Copy link

reuk commented Dec 4, 2019

To use a ScopedAccess object, you have to know its full type, which is pretty awkward to spell out, especially inside template classes:

using ScopedReader = typename farbot::RealtimeMutatable<Data<T>>::template ScopedAccess<false>;

The client has to remember what true and false mean, which isn't obvious. An enum class IsRealtime { no, yes }; instead of a plain bool would help greatly here, as would inner using declarations for ScopedReader and ScopedWriter.

Even better, though, would be to have a [[nodiscard]] auto scopedRead() const noexcept member function directly on the RealtimeMutatable class, so that the user can just do something like this.

// no need to utter the inner typename at all!
const auto reader = realtimeMutatable.scopedRead();
std::cout << *reader << '\n'; // or whatever other slow thing we're doing on the non-realtime thread

In C++17, guaranteed copy elision should mean that you can return one of these non-copyable ScopedAccess objects from a function like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant