Skip to content

Const semantics for read-only access to RealtimeObject (from the thread that can mutate it)? #22

Description

@why-trv

It seems that currently I can't use a const reference to initialize ScopedAccess if e.g. I only need read access in some method that's to be called on the mutating thread. This, in turn, doesn't allow marking the method const even though it's only reading from the RealtimeObject, messing with const-correctness. Could this be addressed?

Example:

struct Coeffs {
    double a, b, c, d;
};

class Foo {
public:
    using RealtimeCoeffs 
        = RealtimeObject<Coeffs, RealtimeObjectOptions::nonRealtimeMutatable>; 

    const RealtimeCoeffs& getCoeffs() const noexcept { return coeffs; }
    RealtimeCoeffs&       getCoeffs() noexcept       { return coeffs; } 

    // bar() should be const, but it's not possible because ScopedAccess can't take
    // a const reference
    void bar /* const */ {
        RealtimeCoeffs::ScopedAccess<ThreadType::nonRealtime> c(getCoeffs());

        // Doing something with coeffs, but not modifying them
    }
	
private:
    RealtimeCoeffs coeffs;
};

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions