Gromacs  2025-dev-20241003-bd59e46
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Member Functions
gmx::compat::not_null< T > Class Template Reference

#include <gromacs/compat/pointers.h>

Description

template<class T>
class gmx::compat::not_null< T >

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

Todo:
Eliminate this when we require a version of C++ that supports std::not_null.

Public Member Functions

template<typename U , typename = std::enable_if_t<std::is_convertible<U, T>::value>>
constexpr not_null (U &&u)
 Move constructor. Asserts in debug mode if is nullptr.
 
template<typename = std::enable_if_t<!std::is_same<std::nullptr_t, T>::value>>
constexpr not_null (T u)
 Simple constructor. Asserts in debug mode if u is nullptr.
 
template<typename U , typename = std::enable_if_t<std::is_convertible<U, T>::value>>
constexpr not_null (const not_null< U > &other)
 Copy constructor.
 
 not_null (not_null &&other) noexcept=default
 Default constructors and assignment.
 
 not_null (const not_null &other)=default
 
not_nulloperator= (const not_null &other)=default
 
constexpr T get () const
 Getters.
 
constexpr operator T () const
 
constexpr T operator-> () const
 
 not_null (std::nullptr_t)=delete
 Deleted to prevent compilation when someone attempts to assign a null pointer constant.
 
not_nulloperator= (std::nullptr_t)=delete
 
not_nulloperator++ ()=delete
 Deleted unwanted operators because pointers only point to single objects.
 
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
 

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