blob: b1e0542dab4d481b292e016f963d03684acf3b3c [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
18template <typename CharT>
19bool test ( const CharT *s, size_t len ) {
20 std::experimental::basic_string_view<CharT> sv ( s, len );
21 assert ( sv.length() == len );
22 assert ( sv.front() == s[0] );
23 return &sv.front() == s;
24 }
Eric Fiselierd04c6852016-06-01 21:35:39 +000025
Marshall Clow5aa8fa22014-06-11 16:44:55 +000026int main () {
27 assert ( test ( "ABCDE", 5 ));
28 assert ( test ( "a", 1 ));
29
30 assert ( test ( L"ABCDE", 5 ));
31 assert ( test ( L"a", 1 ));
32
33#if __cplusplus >= 201103L
34 assert ( test ( u"ABCDE", 5 ));
35 assert ( test ( u"a", 1 ));
36
37 assert ( test ( U"ABCDE", 5 ));
38 assert ( test ( U"a", 1 ));
39#endif
40
Marshall Clow35af19a2014-07-02 15:45:57 +000041#if __cplusplus >= 201103L
Marshall Clow5aa8fa22014-06-11 16:44:55 +000042 {
43 constexpr std::experimental::basic_string_view<char> sv ( "ABC", 2 );
44 static_assert ( sv.length() == 2, "" );
45 static_assert ( sv.front() == 'A', "" );
46 }
47#endif
48}