Reference

#include <actl/meta/Reference.hpp>
template<typename T>
concept Reference

Reference is an opt-in concept for types that don’t own data and only reference it, for example:

  • built-in reference T&;

  • std::span<T>, which references a contiguous array of T;

  • single bit reference like the one used in a bitset.

Types can opt in by specializing ac::is_reference struct to contain static constexpr bool value = true;, for example

template<typename T>
struct is_reference<T&> : std::true_type {};
If a type isn’t correctly recognized as a Reference, then the header with this specialization should be included, for example
#include <actl/std/span.hpp>

Note

Pointer isn’t considered to be a Reference and it’s not recommended to use raw pointers overall, because there are less error-prone alternatives for the two most popular use cases for pointers:

  1. To reference a single optional value, std::optional<T&> is better, because it disallows pointer arithmetic that makes no sense in such case.

  2. To reference a contiguous array, std::span<T> is better, because it keeps information about the array size, which prevents accidental use of incorrect size and enables checks for out-of-bounds access.

See tests at tests/meta/Reference.cpp