1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // NOTE: Older versions of clang have a bug where they fail to evaluate
11 // string_view::at as a constant expression.
12 // XFAIL: clang-3.4, clang-3.3
17 // constexpr const _CharT& at(size_type _pos) const;
19 #include <string_view>
23 #include "test_macros.h"
25 template <typename CharT>
26 void test ( const CharT *s, size_t len ) {
27 std::basic_string_view<CharT> sv ( s, len );
28 assert ( sv.length() == len );
29 for ( size_t i = 0; i < len; ++i ) {
30 assert ( sv.at(i) == s[i] );
31 assert ( &sv.at(i) == s + i );
34 #ifndef TEST_HAS_NO_EXCEPTIONS
35 try { (void)sv.at(len); } catch ( const std::out_of_range & ) { return ; }
47 #if TEST_STD_VER >= 11
55 #if TEST_STD_VER >= 11
57 constexpr std::basic_string_view<char> sv ( "ABC", 2 );
58 static_assert ( sv.length() == 2, "" );
59 static_assert ( sv.at(0) == 'A', "" );
60 static_assert ( sv.at(1) == 'B', "" );