diff options
author | Ville Voutilainen <ville.voutilainen@gmail.com> | 2017-06-21 22:53:26 +0300 |
---|---|---|
committer | Ville Voutilainen <ville@gcc.gnu.org> | 2017-06-21 22:53:26 +0300 |
commit | 5e88d2d08d464d80bbe5dfd64db954f2dd516b7e (patch) | |
tree | 682442a25a4dfb8a09356142015098db8fe62801 /libstdc++-v3/include/std/ostream | |
parent | cb8d1b01b3a2198c67d04a3a077bc7c55aaaa31c (diff) | |
download | gcc-5e88d2d08d464d80bbe5dfd64db954f2dd516b7e.zip gcc-5e88d2d08d464d80bbe5dfd64db954f2dd516b7e.tar.gz gcc-5e88d2d08d464d80bbe5dfd64db954f2dd516b7e.tar.bz2 |
PR libstdc++/80675, PR libstdc++/80940
* include/std/istream:
(__is_convertible_to_basic_istream_test(basic_istream<_Ch, _Up>*)): New.
(__do_is_convertible_to_basic_istream_impl): Likewise.
(__is_convertible_to_basic_istream_impl): Likewise.
(__is_convertible_to_basic_istream): Use the new base.
(__rvalue_istream_type): New.
(operator>>(_Istream&&, _Tp&&)): Use the new helper alias
for the SFINAE check, convert to the helper alias type before
doing the actual extraction.
* include/std/ostream:
(__is_convertible_to_basic_ostream_test(basic_ostream<_Ch, _Up>*)): New.
(__do_is_convertible_to_basic_ostream_impl): Likewise.
(__is_convertible_to_basic_ostream_impl): Likewise.
(__is_convertible_to_basic_ostream): Use the new base.
(__rvalue_ostream_type): New.
(operator<<(_Ostream&&, const _Tp&)): Use the new helper alias
for the SFINAE check, convert to the helper alias type before
doing the actual insertion.
* testsuite/27_io/rvalue_streams-2.cc: Add new tests.
From-SVN: r249468
Diffstat (limited to 'libstdc++-v3/include/std/ostream')
-rw-r--r-- | libstdc++-v3/include/std/ostream | 59 |
1 files changed, 43 insertions, 16 deletions
diff --git a/libstdc++-v3/include/std/ostream b/libstdc++-v3/include/std/ostream index 50b70a5..f7cab03 100644 --- a/libstdc++-v3/include/std/ostream +++ b/libstdc++-v3/include/std/ostream @@ -613,19 +613,39 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __os.flush(); } #if __cplusplus >= 201103L + template<typename _Ch, typename _Up> + basic_ostream<_Ch, _Up>& + __is_convertible_to_basic_ostream_test(basic_ostream<_Ch, _Up>*); + + template<typename _Tp, typename = void> + struct __is_convertible_to_basic_ostream_impl + { + using __ostream_type = void; + }; + + template<typename _Tp> + using __do_is_convertible_to_basic_ostream_impl = + decltype(__is_convertible_to_basic_ostream_test + (declval<typename remove_reference<_Tp>::type*>())); + + template<typename _Tp> + struct __is_convertible_to_basic_ostream_impl + <_Tp, + __void_t<__do_is_convertible_to_basic_ostream_impl<_Tp>>> + { + using __ostream_type = + __do_is_convertible_to_basic_ostream_impl<_Tp>; + }; + template<typename _Tp> struct __is_convertible_to_basic_ostream - { - template<typename _Ch, typename _Up> - static basic_ostream<_Ch, _Up>& __check(basic_ostream<_Ch, _Up>*); - - static void __check(...); - public: - using ostream_type = - decltype(__check(declval<typename remove_reference<_Tp>::type*>())); - using type = __not_<is_same<ostream_type, void>>; - constexpr static bool value = type::value; - }; + : __is_convertible_to_basic_ostream_impl<_Tp> + { + public: + using type = __not_<is_void< + typename __is_convertible_to_basic_ostream_impl<_Tp>::__ostream_type>>; + constexpr static bool value = type::value; + }; template<typename _Ostream, typename _Tp, typename = void> struct __is_insertable : false_type {}; @@ -636,6 +656,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION << declval<const _Tp&>())>> : true_type {}; + template<typename _Ostream> + using __rvalue_ostream_type = + typename __is_convertible_to_basic_ostream< + _Ostream>::__ostream_type; + /** * @brief Generic inserter for rvalue stream * @param __os An input stream. @@ -650,13 +675,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline typename enable_if<__and_<__not_<is_lvalue_reference<_Ostream>>, __is_convertible_to_basic_ostream<_Ostream>, - __is_insertable<_Ostream&, const _Tp&>>::value, - typename __is_convertible_to_basic_ostream< - _Ostream>::ostream_type>::type + __is_insertable< + __rvalue_ostream_type<_Ostream>, + const _Tp&>>::value, + __rvalue_ostream_type<_Ostream>>::type operator<<(_Ostream&& __os, const _Tp& __x) { - __os << __x; - return __os; + __rvalue_ostream_type<_Ostream> __ret_os = __os; + __ret_os << __x; + return __ret_os; } #endif // C++11 |