* include/std/functional (invoke): Add constexpr for C++20.
* include/std/version (__cpp_lib_constexpr_invoke): Define.
* testsuite/20_util/function_objects/invoke/constexpr.cc: New test.
From-SVN: r277343
2019-10-23 Jonathan Wakely <jwakely@redhat.com>
+ * include/std/functional (invoke): Add constexpr for C++20.
+ * include/std/version (__cpp_lib_constexpr_invoke): Define.
+ * testsuite/20_util/function_objects/invoke/constexpr.cc: New test.
+
PR c++/91369 Implement P0784R7 changes to allocation and construction
* include/bits/alloc_traits.h: Include <bits/stl_construct.h>.
(allocator_traits::_S_allocate, allocator_traits::_S_construct)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
-#if __cplusplus > 201402L
-# define __cpp_lib_invoke 201411
+#if __cplusplus >= 201703L
+# define __cpp_lib_invoke 201411L
+# if __cplusplus > 201703L
+# define __cpp_lib_constexpr_invoke 201907L
+# endif
/// Invoke a callable object.
template<typename _Callable, typename... _Args>
- inline invoke_result_t<_Callable, _Args...>
+ inline _GLIBCXX20_CONSTEXPR invoke_result_t<_Callable, _Args...>
invoke(_Callable&& __fn, _Args&&... __args)
noexcept(is_nothrow_invocable_v<_Callable, _Args...>)
{
return std::__invoke(std::forward<_Callable>(__fn),
std::forward<_Args>(__args)...);
}
-#endif
+#endif // C++17
template<typename _MemFunPtr,
bool __is_mem_fn = is_member_function_pointer<_MemFunPtr>::value>
#endif
#define __cpp_lib_constexpr 201711L
#define __cpp_lib_constexpr_algorithms 201806L
+#define __cpp_lib_constexpr_invoke 201907L
#if __cpp_impl_destroying_delete
# define __cpp_lib_destroying_delete 201806L
#endif
--- /dev/null
+// Copyright (C) 2019 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.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <functional>
+
+#ifndef __cpp_lib_constexpr_invoke
+# error "Feature test macro for constexpr invoke is missing"
+#elif __cpp_lib_constexpr_invoke < 201907L
+# error "Feature test macro for constexpr invoke has wrong value"
+#endif
+
+constexpr int inc(int i) { return i + 1; }
+constexpr auto inc_f = &inc;
+static_assert( std::invoke(inc_f, 2) == 3);
+
+struct Dec
+{
+ constexpr int operator()(int i) const { return i - 1; }
+};
+
+static_assert( std::invoke(Dec{}, 5) == 4 );