Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
nix::ref< T > Class Template Reference

#include <ref.hh>

Public Types

using element_type = T

Public Member Functions

 ref (const std::shared_ptr< T > &p)
 ref (std::shared_ptr< T > &&p)
 ref (T *p)
T * get () const
T * operator-> () const
T & operator* () const
std::shared_ptr< T > get_ptr () const &
std::shared_ptr< T > get_ptr () &&
 operator std::shared_ptr< T > (this auto &&self)
template<typename T2>
ref< T2 > cast () const
template<typename T2>
std::shared_ptr< T2 > dynamic_pointer_cast () const
template<typename T2>
requires RefImplicitlyUpcastableTo<T, T2>
 operator ref< T2 > () const
auto operator<=> (const ref< T > &other) const =default

Friends

template<typename T2, typename... Args>
ref< T2 > make_ref (Args &&... args)

Detailed Description

template<typename T>
class nix::ref< T >

A simple non-nullable reference-counted pointer. Actually a wrapper around std::shared_ptr that prevents null constructions.

Member Function Documentation

◆ operator ref< T2 >()

template<typename T>
template<typename T2>
requires RefImplicitlyUpcastableTo<T, T2>
nix::ref< T >::operator ref< T2 > ( ) const
inline

Implicit conversion to ref of base type (covariance). Downcasts are rejected; use .cast() (throws bad_ref_cast) or .dynamic_pointer_cast() (returns nullptr) instead.

◆ operator std::shared_ptr< T >()

template<typename T>
nix::ref< T >::operator std::shared_ptr< T > ( this auto && self)
inline

Convenience to avoid explicit get_ptr() call in some cases.


The documentation for this class was generated from the following file:
  • libutil/include/nix/util/ref.hh