2019-11-17 Jonathan Wakely <jwakely@redhat.com>
+ * include/std/string_view (basic_string_view(It, End)): Add range
+ constructor and deduction guide from P1391R4.
+ * testsuite/21_strings/basic_string_view/cons/char/range.cc: New test.
+
* include/bits/regex.h (match_results): Specialize __enable_view_impl.
* include/bits/stl_set.h (set): Likewise.
* include/bits/unordered_set.h (unordered_set, unordered_multiset):
: _M_len{__len}, _M_str{__str}
{ }
+#if __cplusplus > 201703L && __cpp_lib_concepts
+ template<contiguous_iterator _It, sized_sentinel_for<_It> _End>
+ requires same_as<iter_value_t<_It>, _CharT>
+ && (!convertible_to<_End, size_type>)
+ constexpr
+ basic_string_view(_It __first, _End __last)
+ : _M_len(__last - __first), _M_str(std::to_address(__first))
+ { }
+#endif
+
constexpr basic_string_view&
operator=(const basic_string_view&) noexcept = default;
const _CharT* _M_str;
};
+#if __cplusplus > 201703L && __cpp_lib_concepts && __cpp_deduction_guides
+ template<contiguous_iterator _It, sized_sentinel_for<_It> _End>
+ basic_string_view(_It, _End) -> basic_string_view<iter_value_t<_It>>;
+#endif
+
// [string.view.comparison], non-member basic_string_view comparison function
// Several of these functions use type_identity_t to create a non-deduced
--- /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 run { target c++2a } }
+
+#include <string_view>
+#include <vector>
+#include <testsuite_hooks.h>
+
+constexpr char str[] = "abcdefg";
+constexpr std::basic_string_view s(std::begin(str), std::cend(str) - 1);
+static_assert( s == str );
+static_assert( s.data() == str );
+
+void
+test01()
+{
+ std::vector<char> v{'a', 'b', 'c'};
+ std::basic_string_view s(v.begin(), v.end());
+ VERIFY( s.data() == v.data() );
+}
+
+int
+main()
+{
+ test01();
+}