[libcxx-commits] [libcxx] r372909 - Add forward declaration of operator<< in <string_view> as required.
Eric Fiselier via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Sep 25 11:56:54 PDT 2019
Author: ericwf
Date: Wed Sep 25 11:56:54 2019
New Revision: 372909
URL: http://llvm.org/viewvc/llvm-project?rev=372909&view=rev
Log:
Add forward declaration of operator<< in <string_view> as required.
This declaration was previously missing despite appearing in the
synopsis. Users are still required to include <ostream> to get the
definition of the streaming operator.
Added:
libcxx/trunk/test/std/strings/string.view/string.view.io/stream_insert_decl_present.pass.cpp
Modified:
libcxx/trunk/include/ostream
libcxx/trunk/include/string_view
Modified: libcxx/trunk/include/ostream
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/ostream?rev=372909&r1=372908&r2=372909&view=diff
==============================================================================
--- libcxx/trunk/include/ostream (original)
+++ libcxx/trunk/include/ostream Wed Sep 25 11:56:54 2019
@@ -1055,7 +1055,7 @@ operator<<(basic_ostream<_CharT, _Traits
template<class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os,
- const basic_string_view<_CharT, _Traits> __sv)
+ basic_string_view<_CharT, _Traits> __sv)
{
return _VSTD::__put_character_sequence(__os, __sv.data(), __sv.size());
}
Modified: libcxx/trunk/include/string_view
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string_view?rev=372909&r1=372908&r2=372909&view=diff
==============================================================================
--- libcxx/trunk/include/string_view (original)
+++ libcxx/trunk/include/string_view Wed Sep 25 11:56:54 2019
@@ -173,6 +173,7 @@ namespace std {
#include <__config>
#include <__string>
+#include <iosfwd>
#include <algorithm>
#include <iterator>
#include <limits>
@@ -767,6 +768,12 @@ bool operator>=(typename common_type<bas
return __lhs.compare(__rhs) >= 0;
}
+
+template<class _CharT, class _Traits>
+basic_ostream<_CharT, _Traits>&
+operator<<(basic_ostream<_CharT, _Traits>& __os,
+ basic_string_view<_CharT, _Traits> __str);
+
typedef basic_string_view<char> string_view;
#ifndef _LIBCPP_NO_HAS_CHAR8_T
typedef basic_string_view<char8_t> u8string_view;
Added: libcxx/trunk/test/std/strings/string.view/string.view.io/stream_insert_decl_present.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/string.view/string.view.io/stream_insert_decl_present.pass.cpp?rev=372909&view=auto
==============================================================================
--- libcxx/trunk/test/std/strings/string.view/string.view.io/stream_insert_decl_present.pass.cpp (added)
+++ libcxx/trunk/test/std/strings/string.view/string.view.io/stream_insert_decl_present.pass.cpp Wed Sep 25 11:56:54 2019
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <string>
+
+// template<class charT, class traits, class Allocator>
+// basic_ostream<charT, traits>&
+// operator<<(basic_ostream<charT, traits>& os,
+// const basic_string_view<charT,traits> str);
+
+#include <string_view>
+#include <iosfwd>
+
+template <class SV, class = void>
+struct HasDecl : std::false_type {};
+template <class SV>
+struct HasDecl<SV, decltype(static_cast<void>(std::declval<std::ostream&>() << std::declval<SV&>()))> : std::true_type {};
+
+int main() {
+ static_assert(HasDecl<std::string_view>::value, "streaming operator declaration not present");
+}
More information about the libcxx-commits
mailing list