Marshall Clow | 053d81c | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | |
| 11 | // <string_view> |
| 12 | |
| 13 | // constexpr const _CharT& operator[](size_type _pos) const; |
| 14 | |
| 15 | #include <string_view> |
| 16 | #include <cassert> |
| 17 | |
| 18 | #include "test_macros.h" |
| 19 | |
| 20 | template <typename CharT> |
| 21 | void test ( const CharT *s, size_t len ) { |
| 22 | std::basic_string_view<CharT> sv ( s, len ); |
| 23 | assert ( sv.length() == len ); |
| 24 | for ( size_t i = 0; i < len; ++i ) { |
| 25 | assert ( sv[i] == s[i] ); |
| 26 | assert ( &sv[i] == s + i ); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | int main () { |
| 31 | test ( "ABCDE", 5 ); |
| 32 | test ( "a", 1 ); |
| 33 | |
| 34 | test ( L"ABCDE", 5 ); |
| 35 | test ( L"a", 1 ); |
| 36 | |
| 37 | #if TEST_STD_VER >= 11 |
| 38 | test ( u"ABCDE", 5 ); |
| 39 | test ( u"a", 1 ); |
| 40 | |
| 41 | test ( U"ABCDE", 5 ); |
| 42 | test ( U"a", 1 ); |
| 43 | #endif |
| 44 | |
Stephan T. Lavavej | 0f901c7 | 2016-11-04 20:26:59 +0000 | [diff] [blame^] | 45 | #if TEST_STD_VER > 11 |
Marshall Clow | 053d81c | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 46 | { |
| 47 | constexpr std::basic_string_view<char> sv ( "ABC", 2 ); |
| 48 | static_assert ( sv.length() == 2, "" ); |
| 49 | static_assert ( sv[0] == 'A', "" ); |
| 50 | static_assert ( sv[1] == 'B', "" ); |
| 51 | } |
| 52 | #endif |
| 53 | } |