Commit 2be7a166 by Jonathan Wakely Committed by Jonathan Wakely

PR libstdc++/70483 make std::experimental::string_view fully constexpr

	PR libstdc++/70483
	* include/experimental/bits/string_view.tcc (basic_string_view::find)
	(basic_string_view::rfind, basic_string_view::find_first_of)
	(basic_string_view::find_last_of, basic_string_view::find_first_not_of)
	(basic_string_view::find_last_not_of): Add constexpr specifier.
	* include/experimental/string_view (basic_string_view::remove_prefix)
	(basic_string_view::remove_suffix, basic_string_view::swap)
	(basic_string_view::compare, basic_string_view::find)
	(basic_string_view::rfind, basic_string_view::find_first_of)
	(basic_string_view::find_last_of, basic_string_view::find_first_not_of)
	(basic_string_view::find_last_not_of, operator==, operator!=)
	(operator<, operator>, operator<=, operator>=): Likewise.
	* testsuite/experimental/string_view/operations/compare/char/70483.cc:
	New.

From-SVN: r252017
parent c43f4279
2017-09-12 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/70483
* include/experimental/bits/string_view.tcc (basic_string_view::find)
(basic_string_view::rfind, basic_string_view::find_first_of)
(basic_string_view::find_last_of, basic_string_view::find_first_not_of)
(basic_string_view::find_last_not_of): Add constexpr specifier.
* include/experimental/string_view (basic_string_view::remove_prefix)
(basic_string_view::remove_suffix, basic_string_view::swap)
(basic_string_view::compare, basic_string_view::find)
(basic_string_view::rfind, basic_string_view::find_first_of)
(basic_string_view::find_last_of, basic_string_view::find_first_not_of)
(basic_string_view::find_last_not_of, operator==, operator!=)
(operator<, operator>, operator<=, operator>=): Likewise.
* testsuite/experimental/string_view/operations/compare/char/70483.cc:
New.
2017-09-11 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/70483
......
......@@ -49,7 +49,7 @@ namespace experimental
inline namespace fundamentals_v1
{
template<typename _CharT, typename _Traits>
typename basic_string_view<_CharT, _Traits>::size_type
constexpr typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find(const _CharT* __str, size_type __pos, size_type __n) const noexcept
{
......@@ -70,7 +70,7 @@ inline namespace fundamentals_v1
}
template<typename _CharT, typename _Traits>
typename basic_string_view<_CharT, _Traits>::size_type
constexpr typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find(_CharT __c, size_type __pos) const noexcept
{
......@@ -86,7 +86,7 @@ inline namespace fundamentals_v1
}
template<typename _CharT, typename _Traits>
typename basic_string_view<_CharT, _Traits>::size_type
constexpr typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
rfind(const _CharT* __str, size_type __pos, size_type __n) const noexcept
{
......@@ -106,7 +106,7 @@ inline namespace fundamentals_v1
}
template<typename _CharT, typename _Traits>
typename basic_string_view<_CharT, _Traits>::size_type
constexpr typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
rfind(_CharT __c, size_type __pos) const noexcept
{
......@@ -123,7 +123,7 @@ inline namespace fundamentals_v1
}
template<typename _CharT, typename _Traits>
typename basic_string_view<_CharT, _Traits>::size_type
constexpr typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find_first_of(const _CharT* __str, size_type __pos, size_type __n) const
{
......@@ -139,7 +139,7 @@ inline namespace fundamentals_v1
}
template<typename _CharT, typename _Traits>
typename basic_string_view<_CharT, _Traits>::size_type
constexpr typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find_last_of(const _CharT* __str, size_type __pos, size_type __n) const
{
......@@ -160,7 +160,7 @@ inline namespace fundamentals_v1
}
template<typename _CharT, typename _Traits>
typename basic_string_view<_CharT, _Traits>::size_type
constexpr typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find_first_not_of(const _CharT* __str, size_type __pos, size_type __n) const
{
......@@ -172,7 +172,7 @@ inline namespace fundamentals_v1
}
template<typename _CharT, typename _Traits>
typename basic_string_view<_CharT, _Traits>::size_type
constexpr typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find_first_not_of(_CharT __c, size_type __pos) const noexcept
{
......@@ -183,7 +183,7 @@ inline namespace fundamentals_v1
}
template<typename _CharT, typename _Traits>
typename basic_string_view<_CharT, _Traits>::size_type
constexpr typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find_last_not_of(const _CharT* __str, size_type __pos, size_type __n) const
{
......@@ -204,7 +204,7 @@ inline namespace fundamentals_v1
}
template<typename _CharT, typename _Traits>
typename basic_string_view<_CharT, _Traits>::size_type
constexpr typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find_last_not_of(_CharT __c, size_type __pos) const noexcept
{
......
// Copyright (C) 2017 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-do compile { target c++14 } }
#include <experimental/string_view>
struct constexpr_char_traits : std::char_traits<char>
{
static constexpr size_t
length(const char* val)
{
size_t res = 0;
for (; val[res] != '\0'; ++res)
;
return res;
}
static constexpr int
compare(const char* lhs, const char* rhs, std::size_t count)
{
for (size_t pos = 0; pos < count; ++pos)
{
if (lhs[pos] != rhs[pos])
return lhs[pos] - rhs[pos];
}
return 0;
}
static constexpr const char*
find(const char* p, std::size_t n, char c)
{
for (size_t pos = 0; pos < n; ++pos)
if (p[pos] == c)
return p + pos;
return nullptr;
}
};
using string_view
= std::experimental::basic_string_view<char, constexpr_char_traits>;
constexpr
string_view get()
{
string_view res = "x::";
string_view start_pattern = "x";
res = res.substr(res.find(start_pattern) + start_pattern.size());
res = res.substr(0, res.find_first_of(";]"));
res = res.substr(res.rfind("::"));
return res;
}
static_assert( get() == get() );
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment