blob: 73f7737265d50043a9f81fe7f7f9e678eb0233e5 [file] [log] [blame]
Marshall Clow053d81c2016-07-21 05:31:24 +00001//===----------------------------------------------------------------------===//
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& front();
14
15#include <string_view>
16#include <cassert>
17
18#include "test_macros.h"
19
20template <typename CharT>
21bool test ( const CharT *s, size_t len ) {
22 std::basic_string_view<CharT> sv ( s, len );
23 assert ( sv.length() == len );
24 assert ( sv.back() == s[len-1] );
25 return &sv.back() == s + len - 1;
26 }
27
28int main () {
29 assert ( test ( "ABCDE", 5 ));
30 assert ( test ( "a", 1 ));
31
32 assert ( test ( L"ABCDE", 5 ));
33 assert ( test ( L"a", 1 ));
34
35#if TEST_STD_VER >= 11
36 assert ( test ( u"ABCDE", 5 ));
37 assert ( test ( u"a", 1 ));
38
39 assert ( test ( U"ABCDE", 5 ));
40 assert ( test ( U"a", 1 ));
41#endif
42
43#if TEST_STD_VER >= 11
44 {
45 constexpr std::basic_string_view<char> sv ( "ABC", 2 );
46 static_assert ( sv.length() == 2, "" );
47 static_assert ( sv.back() == 'B', "" );
48 }
49#endif
50}