On this page
  1. Ref
  2. operator bool
  3. operator*, operator->, operator==

rmp::Ref

class #include <rmp/object.h> include/rmp/object.h:383
template <class T> class Ref

An optional reference: something that may not be there, and is not yours.

if (auto health = player.get<Health>()) health->hp -= 1;

What Object::get<B>() and Handle::get() hand back. It is empty, or it refers to something; it owns nothing, and asking it is the if above — true when there is something, and then -> and * reach it. Keep it within the frame, like the reference spawn() returns; across frames, keep the Handle.

Not a T *: a pointer cannot say whether it may be null or whose it is, and this type says both. Not std::optional<std::reference_wrapper<T>> either, which says the same for the price of <functional> in every file with an object in it, and reads as health->get().hp.

REACHING INTO AN EMPTY ONE is a mistake in the game, and is said once, per type: * and -> then reach a stand-in, a default T made for the purpose and made again on every use, so the line that forgot the if writes to nothing instead of taking the player's game down with it. ([dev] strict stops a debug build there instead.) A type with no default constructor has no stand-in, and that one mistake ends the program — with the same message.

Ref

explicit Ref(T &target)

Refers to target, which stays whoever's it was.

operator bool

explicit operator bool() const

True when it refers to something.

operator*, operator->, operator==

T &operator*() const
T *operator->() const
bool operator==(const Ref &ref, std::nullptr_t)

What it refers to — or, empty, the stand-in above, and a line in the log.