Why does hana is_valid_t use the SFINAE test std :: declval <F &&> () not use std :: declval <F> ()?

here is the hana is_void impl code:

 namespace type_detail {
        template <typename F, typename ...Args, typename = decltype(
            std::declval<F&&>()(std::declval<Args&&>()...)
        )>
        constexpr auto is_valid_impl(int) { return hana::true_c; }

        template <typename F, typename ...Args>
        constexpr auto is_valid_impl(...) { return hana::false_c; }

        template <typename F>
        struct is_valid_fun {
            template <typename ...Args>
            constexpr auto operator()(Args&& ...) const
            { return is_valid_impl<F, Args&&...>(int{}); }
        };
    }

    //! @cond
    template <typename F>
    constexpr auto is_valid_t::operator()(F&&) const
    { return type_detail::is_valid_fun<F&&>{}; }

since is_void_t accepts F & &, type_detail::is_valid_fun<F&&>then the is_valid_fun arg template is F & &, then the is_valid_impl template arg is F &&

... so why use std::declval<F&&>()(std::declval<Args&&>()...)not just use std::declval<F>()(std::declval<Args>()...)?

+6
source share

All Articles