Skip to content

Ref[Mut]

sarah edited this page Jan 31, 2022 · 3 revisions
#include <veg/ref.hpp>
namespace veg {

template <typename T>
struct Ref { /*...*/ };
template <typename T>
struct RefMut { /*...*/ };

template <typename T>
auto ref(T const&) noexcept -> Ref<T>;
template <typename T>
auto mut(T&&) noexcept -> RefMut<remove_cvref_t<T>>;

} // namespace veg

Lightweight wrapper around a dereferenceable pointer.

Example:

#include <veg/ref.hpp>

auto main() -> int {
  using namespace veg;
  auto x = 3;
  ref(x); // Ref<int>
  mut(x); // RefMut<int>
}

Interface

auto RefMut<T>::as_const() const noexcept -> Ref<T>;

Get a const reference from a mutable one.


auto Ref<T>::get() const noexcept -> T&;
auto Ref<T>::operator*() const noexcept -> T&;
auto Ref<T>::operator->() const noexcept -> T*;

auto RefMut<T>::get() noexcept -> T&;
auto RefMut<T>::operator*() noexcept -> T&;
auto RefMut<T>::operator->() noexcept -> T*;

Get the inner pointer as a reference.

Traits

Implements the fmt::Debug<Ref<T>> trait: prints the pointed-to value.
Implements the cmp::Ord<Ref<T>, Ref<U>> trait and operator==: compares the pointed-to values.

Clone this wiki locally