string_view enhancements. Move to the correct namespace. Better constexpr support (thanks to Richard for the suggestions). Update the tests to match this. Add <experimental/__config for experimental macros/etc to live.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@212569 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
51349536aa
commit
484728789e
24
include/experimental/__config
Normal file
24
include/experimental/__config
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// -*- C++ -*-
|
||||||
|
//===--------------------------- __config ---------------------------------===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||||
|
// Source Licenses. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#ifndef _LIBCPP_EXPERIMENTAL_CONFIG
|
||||||
|
#define _LIBCPP_EXPERIMENTAL_CONFIG
|
||||||
|
|
||||||
|
#include <__config>
|
||||||
|
|
||||||
|
#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL namespace std { namespace experimental {
|
||||||
|
#define _LIBCPP_END_NAMESPACE_EXPERIMENTAL } }
|
||||||
|
#define _VSTD_EXPERIMENTAL std::experimental
|
||||||
|
|
||||||
|
#define _LIBCPP_BEGIN_NAMESPACE_LFTS _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v1 {
|
||||||
|
#define _LIBCPP_END_NAMESPACE_LFTS } } }
|
||||||
|
#define _VSTD_LFTS _VSTD_EXPERIMENTAL::fundamentals_v1
|
||||||
|
|
||||||
|
#endif
|
@ -174,7 +174,7 @@ namespace std {
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <__config>
|
#include <experimental/__config>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@ -186,9 +186,7 @@ namespace std {
|
|||||||
#pragma GCC system_header
|
#pragma GCC system_header
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace std {
|
_LIBCPP_BEGIN_NAMESPACE_LFTS
|
||||||
namespace experimental {
|
|
||||||
inline namespace library_fundamentals_v1 {
|
|
||||||
|
|
||||||
template<class _CharT, class _Traits = _VSTD::char_traits<_CharT> >
|
template<class _CharT, class _Traits = _VSTD::char_traits<_CharT> >
|
||||||
class _LIBCPP_TYPE_VIS_ONLY basic_string_view {
|
class _LIBCPP_TYPE_VIS_ONLY basic_string_view {
|
||||||
@ -276,12 +274,15 @@ namespace std {
|
|||||||
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
|
||||||
const_reference operator[](size_type __pos) const { return __data[__pos]; }
|
const_reference operator[](size_type __pos) const { return __data[__pos]; }
|
||||||
|
|
||||||
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
|
||||||
const_reference at(size_type __pos) const
|
const_reference at(size_type __pos) const
|
||||||
{
|
{
|
||||||
if (__pos >= size())
|
return __pos >= size()
|
||||||
throw out_of_range("string_view::at");
|
? throw out_of_range("string_view::at")
|
||||||
return __data[__pos];
|
: __data[__pos];
|
||||||
|
// if (__pos >= size())
|
||||||
|
// throw out_of_range("string_view::at");
|
||||||
|
// return __data[__pos];
|
||||||
}
|
}
|
||||||
|
|
||||||
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
|
||||||
@ -358,7 +359,8 @@ namespace std {
|
|||||||
return __rlen;
|
return __rlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
_LIBCPP_CONSTEXPR basic_string_view substr(size_type __pos = 0, size_type __n = npos) const
|
_LIBCPP_CONSTEXPR
|
||||||
|
basic_string_view substr(size_type __pos = 0, size_type __n = npos) const
|
||||||
{
|
{
|
||||||
// if (__pos > size())
|
// if (__pos > size())
|
||||||
// throw out_of_range("string_view::substr");
|
// throw out_of_range("string_view::substr");
|
||||||
@ -776,8 +778,7 @@ namespace std {
|
|||||||
typedef basic_string_view<char32_t> u32string_view;
|
typedef basic_string_view<char32_t> u32string_view;
|
||||||
typedef basic_string_view<wchar_t> wstring_view;
|
typedef basic_string_view<wchar_t> wstring_view;
|
||||||
|
|
||||||
}}} // close std::experimental::library_fundamentals_v1
|
_LIBCPP_END_NAMESPACE_LFTS
|
||||||
|
|
||||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||||
|
|
||||||
// [string.view.hash]
|
// [string.view.hash]
|
||||||
|
@ -43,7 +43,7 @@ int main () {
|
|||||||
test ( U"a", 1 );
|
test ( U"a", 1 );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if _LIBCPP_STD_VER > 11
|
#if __cplusplus >= 201103L
|
||||||
{
|
{
|
||||||
constexpr std::experimental::basic_string_view<char> sv ( "ABC", 2 );
|
constexpr std::experimental::basic_string_view<char> sv ( "ABC", 2 );
|
||||||
static_assert ( sv.length() == 2, "" );
|
static_assert ( sv.length() == 2, "" );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user