Skip to content

gsl::not_null should allow returning by value for the types whose size equals to the size of two pointers #1204

Description

@ozaktash

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions