1 //===----------------------------------------------------------------------===//
3 // 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
7 //===----------------------------------------------------------------------===//
11 // const_reference at(size_type pos) const; // constexpr since C++20
12 // reference at(size_type pos); // constexpr since C++20
18 #include "min_allocator.h"
20 #include "make_string.h"
21 #include "test_macros.h"
22 #include "type_algorithms.h"
25 TEST_CONSTEXPR_CXX20
void test(S s
, typename
S::size_type pos
) {
28 assert(s
.at(pos
) == s
[pos
]);
29 assert(cs
.at(pos
) == cs
[pos
]);
31 #ifndef TEST_HAS_NO_EXCEPTIONS
32 else if (!TEST_IS_CONSTANT_EVALUATED
) {
34 TEST_IGNORE_NODISCARD s
.at(pos
);
36 } catch (std::out_of_range
&) {
37 assert(pos
>= s
.size());
40 TEST_IGNORE_NODISCARD cs
.at(pos
);
42 } catch (std::out_of_range
&) {
43 assert(pos
>= s
.size());
50 TEST_CONSTEXPR_CXX20
void test_string() {
52 test(S(MAKE_CSTRING(typename
S::value_type
, "123")), 0);
53 test(S(MAKE_CSTRING(typename
S::value_type
, "123")), 1);
54 test(S(MAKE_CSTRING(typename
S::value_type
, "123")), 2);
55 test(S(MAKE_CSTRING(typename
S::value_type
, "123")), 3);
60 TEST_CONSTEXPR_CXX20
void operator()() {
61 test_string
<std::basic_string
<T
> >();
62 #if TEST_STD_VER >= 11
63 test_string
<std::basic_string
<T
, std::char_traits
<T
>, min_allocator
<T
> > >();
68 TEST_CONSTEXPR_CXX20
bool test() {
69 types::for_each(types::character_types(), TestCaller());
74 int main(int, char**) {
77 static_assert(test());