* [patch] libstdc++/66998 Make std::experimental::not_fn SFINAE-friendly.
@ 2015-09-03 14:36 Jonathan Wakely
2015-09-03 15:14 ` Jonathan Wakely
0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Wakely @ 2015-09-03 14:36 UTC (permalink / raw)
To: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 48 bytes --]
Tested powerpc64le-linux, committed to trunk.
[-- Attachment #2: patch2.txt --]
[-- Type: text/plain, Size: 3977 bytes --]
commit dd64ea78da1f6e92ba011605ece7cc4bb08e41cc
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Thu Sep 3 12:26:55 2015 +0100
Make std::experimental::not_fn SFINAE-friendly.
PR libstdc++/66998
* include/experimental/functional (_Not_fn): Add exception
specifications and non-deduced return types.
(not_fn): Add exception specification and wrap pointer-to-member.
* testsuite/experimental/functional/not_fn.cc: Test in SFINAE context
and test pointer-to-member.
diff --git a/libstdc++-v3/include/experimental/functional b/libstdc++-v3/include/experimental/functional
index c6b9800..9db5fef 100644
--- a/libstdc++-v3/include/experimental/functional
+++ b/libstdc++-v3/include/experimental/functional
@@ -376,8 +376,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
/// Generalized negator.
template<typename _Fn>
- struct _Not_fn
+ class _Not_fn
{
+ _Fn _M_fn;
+
+ public:
template<typename _Fn2>
explicit
_Not_fn(_Fn2&& __fn) : _M_fn(std::forward<_Fn2>(__fn)) { }
@@ -389,34 +392,43 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
~_Not_fn() = default;
template<typename... _Args>
- decltype(auto)
+ auto
operator()(_Args&&... __args)
+ noexcept(noexcept(!_M_fn(std::forward<_Args>(__args)...)))
+ -> decltype(!_M_fn(std::forward<_Args>(__args)...))
{ return !_M_fn(std::forward<_Args>(__args)...); }
template<typename... _Args>
- decltype(auto)
+ auto
operator()(_Args&&... __args) const
+ noexcept(noexcept(!_M_fn(std::forward<_Args>(__args)...)))
+ -> decltype(!_M_fn(std::forward<_Args>(__args)...))
{ return !_M_fn(std::forward<_Args>(__args)...); }
template<typename... _Args>
- decltype(auto)
+ auto
operator()(_Args&&... __args) volatile
+ noexcept(noexcept(!_M_fn(std::forward<_Args>(__args)...)))
+ -> decltype(!_M_fn(std::forward<_Args>(__args)...))
{ return !_M_fn(std::forward<_Args>(__args)...); }
template<typename... _Args>
- decltype(auto)
+ auto
operator()(_Args&&... __args) const volatile
+ noexcept(noexcept(!_M_fn(std::forward<_Args>(__args)...)))
+ -> decltype(!_M_fn(std::forward<_Args>(__args)...))
{ return !_M_fn(std::forward<_Args>(__args)...); }
-
- private:
- _Fn _M_fn;
};
/// [func.not_fn] Function template not_fn
- template <class _Fn>
+ template<typename _Fn>
inline auto
not_fn(_Fn&& __fn)
- { return _Not_fn<std::decay_t<_Fn>>{std::forward<_Fn>(__fn)}; }
+ noexcept(std::is_nothrow_constructible<std::decay_t<_Fn>, _Fn&&>::value)
+ {
+ using __maybe_type = _Maybe_wrap_member_pointer<std::decay_t<_Fn>>;
+ return _Not_fn<typename __maybe_type::type>{std::forward<_Fn>(__fn)};
+ }
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace fundamentals_v2
diff --git a/libstdc++-v3/testsuite/experimental/functional/not_fn.cc b/libstdc++-v3/testsuite/experimental/functional/not_fn.cc
index 8285ec4..4c137e8 100644
--- a/libstdc++-v3/testsuite/experimental/functional/not_fn.cc
+++ b/libstdc++-v3/testsuite/experimental/functional/not_fn.cc
@@ -20,6 +20,8 @@
#include <experimental/functional>
#include <testsuite_hooks.h>
+using std::experimental::not_fn;
+
int func(int, char) { return 0; }
struct F
@@ -33,8 +35,6 @@ struct F
void
test01()
{
- using std::experimental::not_fn;
-
auto f1 = not_fn(func);
VERIFY( f1(1, '2') == true );
@@ -50,8 +50,36 @@ test01()
VERIFY( f5(1) == false );
}
+template<typename F, typename Arg>
+auto foo(F f, Arg arg) -> decltype(not_fn(f)(arg)) { return not_fn(f)(arg); }
+
+template<typename F, typename Arg>
+auto foo(F f, Arg arg) -> decltype(not_fn(f)()) { return not_fn(f)(); }
+
+struct negator
+{
+ bool operator()(int) const { return false; }
+ void operator()() const {}
+};
+
+void
+test02()
+{
+ foo(negator{}, 1); // PR libstdc++/66998
+}
+
+void
+test03()
+{
+ struct X { bool b; };
+ X x{ false };
+ VERIFY( not_fn(&X::b)(x) );
+}
+
int
main()
{
test01();
+ test02();
+ test03();
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [patch] libstdc++/66998 Make std::experimental::not_fn SFINAE-friendly.
2015-09-03 14:36 [patch] libstdc++/66998 Make std::experimental::not_fn SFINAE-friendly Jonathan Wakely
@ 2015-09-03 15:14 ` Jonathan Wakely
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2015-09-03 15:14 UTC (permalink / raw)
To: libstdc++, gcc-patches
On 03/09/15 15:35 +0100, Jonathan Wakely wrote:
>Tested powerpc64le-linux, committed to trunk.
And gcc-5-branch.
>commit dd64ea78da1f6e92ba011605ece7cc4bb08e41cc
>Author: Jonathan Wakely <jwakely@redhat.com>
>Date: Thu Sep 3 12:26:55 2015 +0100
>
> Make std::experimental::not_fn SFINAE-friendly.
>
> PR libstdc++/66998
> * include/experimental/functional (_Not_fn): Add exception
> specifications and non-deduced return types.
> (not_fn): Add exception specification and wrap pointer-to-member.
> * testsuite/experimental/functional/not_fn.cc: Test in SFINAE context
> and test pointer-to-member.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-09-03 15:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-03 14:36 [patch] libstdc++/66998 Make std::experimental::not_fn SFINAE-friendly Jonathan Wakely
2015-09-03 15:14 ` Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).