welder 0.1.0
Bindings for annotated C++ types, from C++26 reflection
Loading...
Searching...
No Matches
welder::detail::no_reassign_spec Struct Reference

The stored form of a no_reassign mark: the languages a data member is bound read-only** for, independent of whether its C++ type is const. More...

#include <welder/annotations.hpp>

Public Member Functions

template<class... Ls>
consteval no_reassign_spec operator() (Ls... ls) const
 Scope the read-only binding to specific languages.

Public Attributes

unsigned mask = 0
 The languages to bind read-only for; 0 == all languages.

Detailed Description

The stored form of a no_reassign mark: the languages a data member is bound read-only** for, independent of whether its C++ type is const.

welder decides a data member's target-language mutability from its const-ness — a const member binds read-only, a mutable one read/write. no_reassign forces the read-only binding on an otherwise-mutable member: the target language may still mutate the object in place (a read-only binding hands out a live reference, so obj.items.append(x) writes through to the C++ object) but cannot rebind** the attribute to a different object (obj.items = [...] is rejected). It is exactly the binding a const member already gets — pybind11 def_readonly, nanobind def_ro, sol2 sol::readonly, LuaBridge3 a getter-only addProperty, and a (read-only) note in the LuaCATS stub — asked for without making the C++ member const. The motivating case is a mutable STL container member (std::vector<Entity>): keep it appendable while forbidding a whole-list reassignment (which for an opaque container would otherwise need an ugly mangled type).

Usable bare (all languages) or called with languages to scope it, like exclude_spec:

[[=welder::mark::no_reassign]] // read-only everywhere
[[=welder::mark::no_reassign(welder::lang::py)]] // read-only in Python only
constexpr detail::no_reassign_spec no_reassign
@ py
Python (via the pybind11 and nanobind backends).
Definition lang.hpp:43

Repeated annotations union their languages. A no-op on an already-const member (which is read-only regardless).

Definition at line 274 of file annotations.hpp.

Member Function Documentation

◆ operator()()

template<class... Ls>
no_reassign_spec welder::detail::no_reassign_spec::operator() ( Ls... ls) const
inlineconsteval

Scope the read-only binding to specific languages.

Template Parameters
Lsthe language enum types (deduced).
Parameters
lsthe languages to bind the member read-only for.
Returns
a scoped no_reassign_spec.

Definition at line 282 of file annotations.hpp.

References welder::lang_mask().

Member Data Documentation

◆ mask

unsigned welder::detail::no_reassign_spec::mask = 0

The languages to bind read-only for; 0 == all languages.

Definition at line 275 of file annotations.hpp.


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