From 4513f0f0224fd34bbebfdc7aa6bb78a995a6ac7b Mon Sep 17 00:00:00 2001 From: Zhihao Yuan Date: Thu, 20 Jun 2019 22:09:40 +0000 Subject: [libc++] Recommit r363692 to implement P0608R3 Re-apply the change which was reverted in r363764 as-is after breakages being resolved. Thanks Eric Fiselier for working hard on this. See also: https://bugs.llvm.org/show_bug.cgi?id=42330 Differential Revision: https://reviews.llvm.org/D44865 llvm-svn: 363993 --- libcxx/include/variant | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'libcxx/include/variant') diff --git a/libcxx/include/variant b/libcxx/include/variant index 5d0722b6296..baf163050dd 100644 --- a/libcxx/include/variant +++ b/libcxx/include/variant @@ -1098,11 +1098,39 @@ struct __overload<> { void operator()() const; }; template struct __overload<_Tp, _Types...> : __overload<_Types...> { using __overload<_Types...>::operator(); - __identity<_Tp> operator()(_Tp) const; + + static auto __test(_Tp (&&)[1]) -> __identity<_Tp>; + + template + auto operator()(_Tp, _Up&& __t) const + -> decltype(__test({ _VSTD::forward<_Up>(__t) })); +}; + +template +struct __overload_bool : _Base { + using _Base::operator(); + + template > + auto operator()(bool, _Up&&) const + -> enable_if_t, __identity<_Tp>>; }; +template +struct __overload + : __overload_bool<__overload<_Types...>, bool> {}; +template +struct __overload + : __overload_bool<__overload<_Types...>, bool const> {}; +template +struct __overload + : __overload_bool<__overload<_Types...>, bool volatile> {}; +template +struct __overload + : __overload_bool<__overload<_Types...>, bool const volatile> {}; + template -using __best_match_t = typename result_of_t<__overload<_Types...>(_Tp&&)>::type; +using __best_match_t = + typename invoke_result_t<__overload<_Types...>, _Tp, _Tp>::type; } // __variant_detail -- cgit v1.2.3