Skip to content

Instantly share code, notes, and snippets.

@jesseschalken
Created July 16, 2020 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesseschalken/1b5602380ecb9704926664daae12d4bd to your computer and use it in GitHub Desktop.
Save jesseschalken/1b5602380ecb9704926664daae12d4bd to your computer and use it in GitHub Desktop.
C++ pointer alternatives
C C++
T* owning a single object T
T* borrowing a single object T&
T* owning a single object, nullable std::optional<T>
T* owning a single object, polymorphic std::unique_ptr<T>
T* owning an array (dynamic size) std::vector<T>
T[N] owning an array (static size) std::array<T, N>
T* borrowing an array (dynamic size) std::vector<T>& or std::span<T> (gsl::span<T> in C++17)
T* borrowing an array (static size) std::array<T, N>& or std::span<T, N> (gsl::span<T, N> in C++17)
char* owning a string std::string
char* borrowing a string std::string& or std::string_view
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment