Template Struct init#

Struct Documentation#

template<typename ...Args>
struct init#

Helper class to register a constructor method for object types, and (in its zero-argument specialization) an InfoTrait to control whether a field participates in the auto-generated init.

When used with one or more template arguments, init<Args...> is passed to ObjectDef::def() to register an __init__ method that constructs an object with the specified argument types:

refl::ObjectDef<ExampleObject>()
    .def(refl::init<int64_t, int32_t>());

When used without template arguments (via CTAD), init(false) marks a field to be excluded from the auto-generated __ffi_init__ constructor, or suppresses auto-init entirely when passed to ObjectDef’s constructor:

// Per-field opt-out:
refl::ObjectDef<Foo>()
    .def_rw("hidden", &Foo::hidden, refl::init(false), refl::default_value(42));

// Class-level opt-out:
refl::ObjectDef<Bar>(refl::init(false))
    .def_rw("x", &Bar::x);

Note

The object type is automatically deduced from the ObjectDef context.

Template Parameters:

Args – The argument types for the constructor.

Public Functions

constexpr init() noexcept = default#

Constructor.

Friends

friend class ObjectDef
friend class OverloadObjectDef