blob: 9ab83dfb2f53aea6bd3fa1f4866d10e5bb2a8317 [file] [log] [blame]
Marshall Clow053d81c2016-07-21 05:31:24 +00001//===----------------------------------------------------------------------===//
2//
Chandler Carruth57b08b02019-01-19 10:56:40 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Marshall Clow053d81c2016-07-21 05:31:24 +00006//
7//===----------------------------------------------------------------------===//
8
9
10// <string_view>
11
12// constexpr const _CharT* data() const noexcept;
13
14#include <string_view>
15#include <cassert>
16
17#include "test_macros.h"
18
19template <typename CharT>
20void test ( const CharT *s, size_t len ) {
21 std::basic_string_view<CharT> sv ( s, len );
22 assert ( sv.length() == len );
23 assert ( sv.data() == s );
Marshall Clowaafb3152018-01-30 00:47:43 +000024#if TEST_STD_VER > 14
25// make sure we pick up std::data, too!
26 assert ( sv.data() == std::data(sv));
27#endif
Marshall Clow053d81c2016-07-21 05:31:24 +000028 }
29
JF Bastien2df59c52019-02-04 20:31:13 +000030int main(int, char**) {
Marshall Clow053d81c2016-07-21 05:31:24 +000031 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. Lavavej0f901c72016-11-04 20:26:59 +000045#if TEST_STD_VER > 11
Marshall Clow053d81c2016-07-21 05:31:24 +000046 {
47 constexpr const char *s = "ABC";
48 constexpr std::basic_string_view<char> sv( s, 2 );
49 static_assert( sv.length() == 2, "" );
50 static_assert( sv.data() == s, "" );
51 }
52#endif
JF Bastien2df59c52019-02-04 20:31:13 +000053
54 return 0;
Marshall Clow053d81c2016-07-21 05:31:24 +000055}