microsoft / GSL

Guidelines Support Library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`not_null` should support `std::function`.

BenFrantzDale opened this issue · comments

std::function default-constructs to null, making gsl::not_null<std::function<R(A)>> desirable.

I think just adding operator() like https://en.cppreference.com/w/cpp/utility/functional/reference_wrapper/operator() would allow for things like gsl::not_null<void(*)()> or gsl::not_null<std::function<void()>>.

Maybe it's just

    template<class... Args>
    std::invoke_result_t<T, Args...> operator()(Args&&... args) const {
        return std::invoke(ptr_, std::forward<Args>(args)...);
    }

https://godbolt.org/z/vh69jsEez

Hi @BenFrantzDale thanks for the proposal. I'll bring this up in the next maintainers' sync.

Closing, as per the CoreGuideline Editors' call in isocpp/CppCoreGuidelines#1901

Thanks for considering it. I’ll probably roll my own.