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

Lazy-locking cast proxy for a wrapper or plain value reference. More...

#include <wrapper_cast.h>

Public Member Functions

 wrapper_caster (Refer ref)
 Constructs the proxy, capturing references to every executor in the wrapper chain via an internal value_lock. No guard is acquired.
 ~wrapper_caster ()
 Releases all guards acquired during conversion.
 operator Refer () &&
 Implicit conversion to the reference type Refer.
template<typename T>
requires ::scl::feature::concepts::convertible_from<T, Refer>
T to () &&
 Acquires the guards needed to reach T and returns the value.

Detailed Description

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

Lazy-locking cast proxy for a wrapper or plain value reference.

wrapper_caster<Refer> holds a value_lock (all executor references captured, no guard acquired yet) and exposes implicit conversion operators for every reachable level in the wrapper chain. Guards are activated only at the moment of conversion.

The proxy must be used as an rvalue; all conversion operators are &&-qualified.

Warning
The proxy borrows a reference to its argument and does not extend the argument's lifetime. Consume it within the same full-expression; do not store the proxy, especially from a temporary — auto p = wrapper_cast(makeW()); leaves p referring to a destroyed wrapper once that full-expression ends.
Template Parameters
ReferReference type passed to wrapper_cast().
int x = wrapper_cast(w); // value copied; guard active during copy
auto proxy = wrapper_cast(w);
int & r = std::move(proxy); // guard active until proxy is destroyed
Composable proxy wrapper that delegates to Value through executors.
Definition wrapper.h:72
constexpr decltype(auto) wrapper_cast(Wrapper &&w)
Returns a lazy-locking cast proxy for a wrapper reference.

Constructor & Destructor Documentation

◆ wrapper_caster()

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

Constructs the proxy, capturing references to every executor in the wrapper chain via an internal value_lock. No guard is acquired.

Parameters
refReference to the outermost wrapper or plain value.

◆ ~wrapper_caster()

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

Releases all guards acquired during conversion.

If a conversion operator was invoked, the internal value_lock releases all held guards in reverse order (innermost first). If no conversion was performed, no guards are released.

Member Function Documentation

◆ operator Refer()

template<typename Refer>
scl::wrapper_caster< Refer >::operator Refer ( ) &&
nodiscard

Implicit conversion to the reference type Refer.

Activates guards for all wrapper layers needed to reach the target type and returns the value. The proxy must be an rvalue at the call site.

One overload is available for each type reachable in the wrapper chain (the wrapper itself, its value_type, and so on recursively).

Note
Acquired guards remain held until the wrapper_caster is destroyed, not until the end of the conversion expression.

◆ to()

template<typename Refer>
template<typename T>
requires ::scl::feature::concepts::convertible_from<T, Refer>
T scl::wrapper_caster< Refer >::to ( ) &&
nodiscard

Acquires the guards needed to reach T and returns the value.

Template Parameters
TTarget reference type — must be reachable from Refer via concepts::convertible_from.

The proxy must be an rvalue at the call site.

Note
Acquired guards remain held until the wrapper_caster is destroyed.

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