7dcc645ccd
* include/bits/invoke.h (__invoke): Use __invoke_result instead of result_of, and __is_nothrow_invocable instead of __is_nothrow_callable. * include/bits/shared_ptr_base.h (__shared_ptr): Use __is_invocable instead of __is_callable. * include/std/functional (invoke): use invoke_result_t instead of result_of_t and is_nothrow_invocable instead of is_nothrow_callable. (_Not_fn): Use __invoke_result instead of result_of. * include/std/type_traits (__result_of_memobj, __result_of_memfun): Remove partial specializations for reference_wrapper types. (__result_of_impl): Use __inv_unwrap to strip reference_wrapper. (__invoke_result): Define replacement for result_of and then use it to define result_of. (__is_callable_impl, __is_callable, __is_nothrow_callable): Replace with __is_invocable_impl, __is_invocable, and __is_nothrow_invocable respectively. (invoke_result, invoke_result_t): Define for C++17. (is_callable, is_nothrow_callable): Replace with is_invocable, is_invocable_r, is_nothrow_invocable, and is_nothrow_invocable_r. (is_callable_v, is_nothrow_callable_v): Replace with is_invocable_v, is_invocable_r_v, is_nothrow_invocable_v, and is_nothrow_invocable_r_v. * include/std/variant (hash<variant<T...>>): Use is_nothrow_invocable_v instead of is_nothrow_callable_v. * testsuite/20_util/function_objects/invoke/59768.cc: Remove unused main function. * testsuite/20_util/function_objects/not_fn/1.cc: Use is_invocable instead of is_callable. * testsuite/20_util/is_callable/*: Rename directory and adjust tests to use new traits. * testsuite/20_util/is_notjrow_callable/*: Likewise. * testsuite/20_util/optional/hash.cc: Use is_invocable_v instead of is_callable. * testsuite/20_util/variant/hash.cc: Likewise. From-SVN: r246036
105 lines
3.6 KiB
C++
105 lines
3.6 KiB
C++
// Implementation of INVOKE -*- C++ -*-
|
|
|
|
// Copyright (C) 2016-2017 Free Software Foundation, Inc.
|
|
//
|
|
// This file is part of the GNU ISO C++ Library. This library is free
|
|
// software; you can redistribute it and/or modify it under the
|
|
// terms of the GNU General Public License as published by the
|
|
// Free Software Foundation; either version 3, or (at your option)
|
|
// any later version.
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// Under Section 7 of GPL version 3, you are granted additional
|
|
// permissions described in the GCC Runtime Library Exception, version
|
|
// 3.1, as published by the Free Software Foundation.
|
|
|
|
// You should have received a copy of the GNU General Public License and
|
|
// a copy of the GCC Runtime Library Exception along with this program;
|
|
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
// <http://www.gnu.org/licenses/>.
|
|
|
|
/** @file include/bits/invoke.h
|
|
* This is an internal header file, included by other library headers.
|
|
* Do not attempt to use it directly. @headername{functional}
|
|
*/
|
|
|
|
#ifndef _GLIBCXX_INVOKE_H
|
|
#define _GLIBCXX_INVOKE_H 1
|
|
|
|
#pragma GCC system_header
|
|
|
|
#if __cplusplus < 201103L
|
|
# include <bits/c++0x_warning.h>
|
|
#else
|
|
|
|
#include <type_traits>
|
|
|
|
namespace std _GLIBCXX_VISIBILITY(default)
|
|
{
|
|
_GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|
|
|
/**
|
|
* @addtogroup utilities
|
|
* @{
|
|
*/
|
|
|
|
// Used by __invoke_impl instead of std::forward<_Tp> so that a
|
|
// reference_wrapper is converted to an lvalue-reference.
|
|
template<typename _Tp, typename _Up = typename __inv_unwrap<_Tp>::type>
|
|
constexpr _Up&&
|
|
__invfwd(typename remove_reference<_Tp>::type& __t) noexcept
|
|
{ return static_cast<_Up&&>(__t); }
|
|
|
|
template<typename _Res, typename _Fn, typename... _Args>
|
|
constexpr _Res
|
|
__invoke_impl(__invoke_other, _Fn&& __f, _Args&&... __args)
|
|
{ return std::forward<_Fn>(__f)(std::forward<_Args>(__args)...); }
|
|
|
|
template<typename _Res, typename _MemFun, typename _Tp, typename... _Args>
|
|
constexpr _Res
|
|
__invoke_impl(__invoke_memfun_ref, _MemFun&& __f, _Tp&& __t,
|
|
_Args&&... __args)
|
|
{ return (__invfwd<_Tp>(__t).*__f)(std::forward<_Args>(__args)...); }
|
|
|
|
template<typename _Res, typename _MemFun, typename _Tp, typename... _Args>
|
|
constexpr _Res
|
|
__invoke_impl(__invoke_memfun_deref, _MemFun&& __f, _Tp&& __t,
|
|
_Args&&... __args)
|
|
{
|
|
return ((*std::forward<_Tp>(__t)).*__f)(std::forward<_Args>(__args)...);
|
|
}
|
|
|
|
template<typename _Res, typename _MemPtr, typename _Tp>
|
|
constexpr _Res
|
|
__invoke_impl(__invoke_memobj_ref, _MemPtr&& __f, _Tp&& __t)
|
|
{ return __invfwd<_Tp>(__t).*__f; }
|
|
|
|
template<typename _Res, typename _MemPtr, typename _Tp>
|
|
constexpr _Res
|
|
__invoke_impl(__invoke_memobj_deref, _MemPtr&& __f, _Tp&& __t)
|
|
{ return (*std::forward<_Tp>(__t)).*__f; }
|
|
|
|
/// Invoke a callable object.
|
|
template<typename _Callable, typename... _Args>
|
|
constexpr typename __invoke_result<_Callable, _Args...>::type
|
|
__invoke(_Callable&& __fn, _Args&&... __args)
|
|
noexcept(__is_nothrow_invocable<_Callable, _Args...>::value)
|
|
{
|
|
using __result = __invoke_result<_Callable, _Args...>;
|
|
using __type = typename __result::type;
|
|
using __tag = typename __result::__invoke_type;
|
|
return std::__invoke_impl<__type>(__tag{}, std::forward<_Callable>(__fn),
|
|
std::forward<_Args>(__args)...);
|
|
}
|
|
|
|
_GLIBCXX_END_NAMESPACE_VERSION
|
|
} // namespace std
|
|
|
|
#endif // C++11
|
|
|
|
#endif // _GLIBCXX_INVOKE_H
|