In gsl::not_null, objects of types smaller than two pointers can be returned by value, but when the size equals to the size of two pointers, returning by reference is forced:
template<typename T>
using value_or_reference_return_t = std::conditional_t<
sizeof(T) < 2*sizeof(void*) && std::is_trivially_copy_constructible<T>::value,
const T,
const T&>;
I think returning by value should also be allowed for types whose size equals to the size of two pointers:
template<typename T>
using value_or_reference_return_t = std::conditional_t<
sizeof(T) <= 2*sizeof(void*) && std::is_trivially_copy_constructible<T>::value,
const T,
const T&>;
This is the threshold used in the current cppfront and is also compliant with C++ Core Guidelines.
In
gsl::not_null, objects of types smaller than two pointers can be returned by value, but when the size equals to the size of two pointers, returning by reference is forced:I think returning by value should also be allowed for types whose size equals to the size of two pointers:
This is the threshold used in the current cppfront and is also compliant with C++ Core Guidelines.