blob: acb00a46a2e54af5c04aafe3b4a0035b848c42ab [file] [log] [blame]
Marshall Clow5aa8fa22014-06-11 16:44:55 +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& back();
14
15#include <experimental/string_view>
16#include <cassert>
17
Eric Fiselierf2f2a632016-06-14 21:31:42 +000018#include "test_macros.h"
19
Marshall Clow5aa8fa22014-06-11 16:44:55 +000020template <typename CharT>
21bool test ( const CharT *s, size_t len ) {
22 std::experimental::basic_string_view<CharT> sv ( s, len );
23 assert ( sv.length() == len );
24 assert ( sv.front() == s[0] );
25 return &sv.front() == s;
26 }
Eric Fiselierd04c6852016-06-01 21:35:39 +000027
Marshall Clow5aa8fa22014-06-11 16:44:55 +000028int 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
Eric Fiselierf2f2a632016-06-14 21:31:42 +000035#if TEST_STD_VER >= 11
Marshall Clow5aa8fa22014-06-11 16:44:55 +000036 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
Eric Fiselierf2f2a632016-06-14 21:31:42 +000043#if TEST_STD_VER >= 11
Marshall Clow5aa8fa22014-06-11 16:44:55 +000044 {
45 constexpr std::experimental::basic_string_view<char> sv ( "ABC", 2 );
46 static_assert ( sv.length() == 2, "" );
47 static_assert ( sv.front() == 'A', "" );
48 }
49#endif
50}