"ScL Feature"/
ScL Feature 0.0.1
C++20 composable proxy wrapper with pluggable executor strategy
Loading...
Searching...
No Matches
scl::wrapper_lock< Refer > Class Template Reference

Lazy RAII lock for a single wrapper layer. More...

#include <wrapper_lock.h>

Public Member Functions

 wrapper_lock (Refer ref)
 Constructs the lock storing ref. No guard is acquired.
 ~wrapper_lock ()
 Releases the guard if it was acquired.
void lock ()
 Acquires the guard on the executor (idempotent).
void unlock ()
 Releases the guard on the executor (idempotent).
decltype(auto) value () const noexcept
 Returns the inner value through the executor.
Refer wrapper_value () const noexcept
 Returns the wrapper reference itself without requiring the lock.

Detailed Description

template<typename Refer>
class scl::wrapper_lock< Refer >

Lazy RAII lock for a single wrapper layer.

Stores the wrapper reference and a reference to its executor, but does not call guard() at construction. The guard is activated only when lock() is called explicitly, and released when unlock() is called or the object is destroyed.

For non-wrapper types lock() / unlock() are no-ops and value() returns the reference unchanged.

Template Parameters
ReferReference type — either wrapper<V,E> cv-ref or a plain value cv-ref.
wrapper_lock<decltype(w) &> lk{w};
lk.lock();
auto& val = lk.value(); // safe: guard held
lk.unlock();
Lazy RAII lock for a single wrapper layer.
Definition wrapper_lock.h:46
void lock()
Acquires the guard on the executor (idempotent).
Composable proxy wrapper that delegates to Value through executors.
Definition wrapper.h:72

Constructor & Destructor Documentation

◆ wrapper_lock()

template<typename Refer>
scl::wrapper_lock< Refer >::wrapper_lock ( Refer ref)
explicit

Constructs the lock storing ref. No guard is acquired.

Parameters
refReference to the wrapper or plain value to lock.

◆ ~wrapper_lock()

template<typename Refer>
scl::wrapper_lock< Refer >::~wrapper_lock ( )

Releases the guard if it was acquired.

Calls unlock(). noexcept if executor_type::unguard() does not exist or is noexcept (see is_unguard_noexcept_v).

Member Function Documentation

◆ lock()

template<typename Refer>
void scl::wrapper_lock< Refer >::lock ( )

Acquires the guard on the executor (idempotent).

For wrapper types calls executor_type::guard() on the first call; subsequent calls are no-ops. For non-wrapper types always a no-op. noexcept if executor_type::guard() does not exist or is noexcept (see is_guard_noexcept_v).

◆ unlock()

template<typename Refer>
void scl::wrapper_lock< Refer >::unlock ( )

Releases the guard on the executor (idempotent).

For wrapper types calls executor_type::unguard() if the guard is held, then clears the locked flag. Subsequent calls are no-ops. For non-wrapper types always a no-op. noexcept if executor_type::unguard() does not exist or is noexcept (see is_unguard_noexcept_v).

◆ value()

template<typename Refer>
decltype(auto) scl::wrapper_lock< Refer >::value ( ) const
nodiscardnoexcept

Returns the inner value through the executor.

For wrapper types delegates to executor_type::access(). For non-wrapper types returns the held reference unchanged.

Precondition
For wrapper types lock() must have been called beforehand.

◆ wrapper_value()

template<typename Refer>
Refer scl::wrapper_lock< Refer >::wrapper_value ( ) const
nodiscardnoexcept

Returns the wrapper reference itself without requiring the lock.

Only available for wrapper types.


The documentation for this class was generated from the following file: