summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include
diff options
context:
space:
mode:
authoremsr <emsr@138bc75d-0d04-0410-961f-82ee72b054a4>2013-11-21 12:30:37 +0000
committeremsr <emsr@138bc75d-0d04-0410-961f-82ee72b054a4>2013-11-21 12:30:37 +0000
commit7f8a3f4983825df08d845b7093beb81ecd7bb320 (patch)
tree2c8203853e473a685d088ab1bfe274e96e46d383 /libstdc++-v3/include
parent94612be7a540d99c1996776706c2d3c45f5f8e62 (diff)
downloadgcc-7f8a3f4983825df08d845b7093beb81ecd7bb320.tar.gz
2013-11-21 Edward Smith-Rowland <3dw4rd@verizon.net>
* include/experimental/string_view: Rep empty string with unit-length static constexpr string. Uncomment _GLIBCXX_VISIBILITY. Enforce invariant of no nullptr string pointer. * include/experimental/string_view.tcc: Ditto. * testsuite/experimental/string_view/cons/char/1.cc: data() for empty string_view is no longer nullptr. * testsuite/experimental/string_view/cons/wchar_t/1.cc: Ditto. * testsuite/experimental/string_view/operations/data/char/1.cc: Ditto. * testsuite/experimental/string_view/operations/data/wchar_t/1.cc: Ditto. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@205213 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r--libstdc++-v3/include/experimental/string_view24
-rw-r--r--libstdc++-v3/include/experimental/string_view.tcc6
2 files changed, 23 insertions, 7 deletions
diff --git a/libstdc++-v3/include/experimental/string_view b/libstdc++-v3/include/experimental/string_view
index 6a95e8d0bd0..000d317c5c5 100644
--- a/libstdc++-v3/include/experimental/string_view
+++ b/libstdc++-v3/include/experimental/string_view
@@ -43,7 +43,7 @@
#include <string>
#include <limits>
-namespace std //_GLIBCXX_VISIBILITY(default)
+namespace std _GLIBCXX_VISIBILITY(default)
{
namespace experimental
{
@@ -66,6 +66,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* _CharT* _M_str
* size_t _M_len
* @endcode
+ *
+ * A basic_string_view represents an empty string with a static constexpr
+ * length one string:
+ *
+ * @code
+ * static constexpr value_type _S_empty_str[1]{0};
+ * @endcode
*/
template<typename _CharT, typename _Traits = char_traits<_CharT>>
class basic_string_view
@@ -92,7 +99,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
constexpr
basic_string_view() noexcept
- : _M_len{0}, _M_str{nullptr}
+ : _M_len{0}, _M_str{_S_empty_str}
{ }
constexpr basic_string_view(const basic_string_view&) noexcept = default;
@@ -104,11 +111,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ }
constexpr basic_string_view(const _CharT* __str)
- : _M_len{__str == nullptr ? 0 : traits_type::length(__str)}, _M_str{__str}
+ : _M_len{__str == nullptr ? 0 : traits_type::length(__str)},
+ _M_str{__str == nullptr ? _S_empty_str : __str}
{ }
constexpr basic_string_view(const _CharT* __str, size_type __len)
- : _M_len{__len}, _M_str{__str}
+ : _M_len{__str == nullptr ? 0 :__len},
+ _M_str{__str == nullptr || __len == 0 ? _S_empty_str : __str}
{ }
basic_string_view&
@@ -185,7 +194,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
"(which is %zu) >= this->size() "
"(which is %zu)"),
__pos, this->size()),
- *static_cast<pointer>(nullptr));
+ _S_empty_str[0]);
}
constexpr const _CharT&
@@ -211,7 +220,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
clear() noexcept
{
this->_M_len = 0;
- this->_M_str = nullptr;
+ this->_M_str = _S_empty_str;
}
void
@@ -408,6 +417,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
private:
+
static constexpr const int
_S_compare(size_type __n1, size_type __n2) noexcept
{
@@ -418,6 +428,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
: static_cast<int>(difference_type{__n1 - __n2});
}
+ static constexpr value_type _S_empty_str[1]{};
+
size_t _M_len;
const _CharT* _M_str;
};
diff --git a/libstdc++-v3/include/experimental/string_view.tcc b/libstdc++-v3/include/experimental/string_view.tcc
index af334b456ca..eeccb026344 100644
--- a/libstdc++-v3/include/experimental/string_view.tcc
+++ b/libstdc++-v3/include/experimental/string_view.tcc
@@ -40,13 +40,17 @@
# include <bits/c++14_warning.h>
#else
-namespace std //_GLIBCXX_VISIBILITY(default)
+namespace std _GLIBCXX_VISIBILITY(default)
{
namespace experimental
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _CharT, typename _Traits>
+ constexpr _CharT
+ basic_string_view<_CharT, _Traits>::_S_empty_str[1];
+
+ template<typename _CharT, typename _Traits>
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