35. safe_addr macro

The safe_addr module implements safe_addr pattern, which returns temporary address of local expression.

All functions and symbols are in “safe_addr” module, use require to get access to it.

require daslib/safe_addr

35.1. Function annotations

SafeAddrMacro

This macro reports an error if safe_addr is attempted on the object, which is not local to the scope. I.e. if the object can expire while in scope, with delete, garbage collection, or on the C++ side.

SharedAddrMacro

|function_annotation-safe_addr-SharedAddrMacro|

35.2. Safe temporary address

safe_addr(x: auto(T)& ==const)

safe_addr returns T?#

argument

argument type

x

auto(T)&!

returns temporary pointer to the given expression

safe_addr(x: auto(T) const& ==const)

safe_addr returns T? const#

argument

argument type

x

auto(T) const&!

returns temporary pointer to the given expression

shared_addr(tab: table<auto(KEY);auto(VAL)> const; k: KEY const)

shared_addr returns auto

argument

argument type

tab

table<auto(KEY);auto(VAL)> const

k

KEY const

returns address of the given shared variable. it’s safe because shared variables never go out of scope

shared_addr(val: auto(VALUE) const&)

shared_addr returns auto

argument

argument type

val

auto(VALUE) const&

returns address of the given shared variable. it’s safe because shared variables never go out of scope

35.3. Temporary pointers

temp_ptr(x: auto(T)? const implicit ==const)

temp_ptr returns T? const#

argument

argument type

x

auto(T)? const implicit!

returns temporary pointer from a given pointer

temp_ptr(x: auto(T)? implicit ==const)

temp_ptr returns T?#

argument

argument type

x

auto(T)? implicit!

returns temporary pointer from a given pointer