SpECTRE  v2024.02.05
gsl::not_null< T > Class Template Reference

Require a pointer to not be a nullptr More...

#include <Gsl.hpp>

Public Member Functions

template<typename U , Requires< std::is_convertible< U, T >::value > = nullptr>
constexpr not_null (U &&u)
 
template<typename U , Requires< std::is_convertible< U, T >::value > = nullptr>
constexpr not_null (const not_null< U > &other)
 
 not_null (const not_null &other)=default
 
not_nulloperator= (const not_null &other)=default
 
constexpr T get () const
 
constexpr operator T () const
 
constexpr T operator-> () const
 
constexpr decltype(auto) operator* () const
 
 not_null (std::nullptr_t)=delete
 
not_nulloperator= (std::nullptr_t)=delete
 
not_nulloperator++ ()=delete
 
not_nulloperator-- ()=delete
 
not_null operator++ (int)=delete
 
not_null operator-- (int)=delete
 
not_nulloperator+= (std::ptrdiff_t)=delete
 
not_nulloperator-= (std::ptrdiff_t)=delete
 
void operator[] (std::ptrdiff_t) const =delete
 

Detailed Description

template<class T>
class gsl::not_null< T >

Require a pointer to not be a nullptr

Restricts a pointer or smart pointer to only hold non-null values.

Has zero size overhead over T.

If T is a pointer (i.e. T == U*) then

  • allow construction from U*
  • disallow construction from nullptr_t
  • disallow default construction
  • ensure construction from null U* fails
  • allow implicit conversion to U*

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