libmesh_nullptr_t Class Reference

#include <libmesh_nullptr.h>

Public Member Functions

template<class T >
 operator T * () const
 
template<class C , class T >
 operator T C::* () const
 

Private Member Functions

void operator& () const
 

Detailed Description

A C++03-compatible nullptr type implemented as a library solution rather than a language keyword. Originally due to Scott Meyers, Effective C++, 2nd Edition, Item 25. The main benefits of using this type over NULL are 1.) Expressiveness: 2.) Disambiguating overloads, e.g. void f(int); void f(double *); f(NULL); // ambiguous f(nullptr); // unambiguous - calls the version of f taking a pointer

We are specifically not attempting to redefine the 'nullptr' keyword itself – that can lead to issues when C++11 is disabled, yet the compiler still has 'nullptr' defined. Therefore, client code that wishes to be more expressive/correct should use 'libmesh_nullptr' for maximum backwards compatibility.

Note
The leading const applies to the following nullptr instance.

Code originally coped from: https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/nullptr#Solution_and_Sample_Code

Definition at line 53 of file libmesh_nullptr.h.

Member Function Documentation

template<class T >
libmesh_nullptr_t::operator T * ( ) const
inline

Definition at line 58 of file libmesh_nullptr.h.

58 { return 0; }
template<class C , class T >
libmesh_nullptr_t::operator T C::* ( ) const
inline

Definition at line 62 of file libmesh_nullptr.h.

References libmesh_nullptr, and operator&().

62 { return 0; }
void libmesh_nullptr_t::operator& ( ) const
private

Referenced by operator T C::*().


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