#ifndef BOOST_COMPAT_INVOKE_HPP_INCLUDED #define BOOST_COMPAT_INVOKE_HPP_INCLUDED // Copyright 2024 Peter Dimov // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt #include #include #include #include #include #include namespace boost { namespace compat { // invoke template constexpr auto invoke( F&& f, A&&... a ) BOOST_COMPAT_RETURNS( std::forward(f)(std::forward(a)...) ) template constexpr auto invoke( M T::* pm, A&&... a ) BOOST_COMPAT_RETURNS( compat::mem_fn(pm)(std::forward(a)...) ) // invoke_result_t template using invoke_result_t = decltype( compat::invoke( std::declval(), std::declval()... ) ); // is_invocable namespace detail { template struct is_invocable_: std::false_type {}; template struct is_invocable_< void_t>, F, A... >: std::true_type {}; } // namespace detail template struct is_invocable: detail::is_invocable_ {}; // is_nothrow_invocable #if BOOST_WORKAROUND(BOOST_MSVC, < 1910) template struct is_nothrow_invocable: std::false_type {}; #else namespace detail { template struct is_nothrow_invocable_ { using type = std::integral_constant(), std::declval()... ) )>; }; } // namespace detail template struct is_nothrow_invocable: conditional_t< is_invocable::value, detail::is_nothrow_invocable_, std::false_type >::type {}; #endif // invoke_r template::value && is_invocable::value >> constexpr R invoke_r( F&& f, A&&... a ) noexcept( noexcept( static_cast( compat::invoke( std::forward(f), std::forward(a)... ) ) ) ) { return static_cast( compat::invoke( std::forward(f), std::forward(a)... ) ); } template::value && std::is_convertible< invoke_result_t, R >::value >> constexpr R invoke_r( F&& f, A&&... a ) noexcept( noexcept( static_cast( compat::invoke( std::forward(f), std::forward(a)... ) ) ) ) { return compat::invoke( std::forward(f), std::forward(a)... ); } // is_invocable_r namespace detail { template struct is_invocable_r_: std::is_convertible< invoke_result_t, R > {}; } // namespace detail template struct is_invocable_r: conditional_t< !is_invocable::value, std::false_type, conditional_t< std::is_void::value, std::true_type, detail::is_invocable_r_ >> {}; // is_nothrow_invocable_r #if BOOST_WORKAROUND(BOOST_MSVC, < 1910) template struct is_nothrow_invocable_r: std::false_type {}; #else namespace detail { template struct is_nothrow_invocable_r_ { using type = std::integral_constant( std::declval(), std::declval()... ) )>; }; } // namespace detail template struct is_nothrow_invocable_r: conditional_t< is_invocable_r::value, detail::is_nothrow_invocable_r_, std::false_type >::type {}; #endif } // namespace compat } // namespace boost #endif // BOOST_COMPAT_INVOKE_HPP_INCLUDED