1//===----------------------------------------------------------------------===//
2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3// See https://llvm.org/LICENSE.txt for license information.
4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5//
6//===----------------------------------------------------------------------===//
7
8// UNSUPPORTED: c++03, c++11, c++14, c++17
9
10// <format>
11
12// constexpr void advance_to(const_iterator it);
13
14#include <format>
15
16#include <cassert>
17#include <string_view>
18
19#include "test_macros.h"
20
21template <class CharT>
22constexpr void test(const CharT* fmt) {
23 {
24 std::basic_format_parse_context<CharT> context(fmt);
25
26 context.advance_to(context.begin() + 1);
27 assert(std::to_address(context.begin()) == fmt + 1);
28
29 context.advance_to(context.begin() + 1);
30 assert(std::to_address(context.begin()) == fmt + 2);
31
32 context.advance_to(context.begin() + 1);
33 assert(context.begin() == context.end());
34 }
35 {
36 std::basic_string_view view{fmt};
37 std::basic_format_parse_context context(view);
38
39 context.advance_to(context.begin() + 1);
40 assert(std::to_address(context.begin()) == fmt + 1);
41
42 context.advance_to(context.begin() + 1);
43 assert(std::to_address(context.begin()) == fmt + 2);
44
45 context.advance_to(context.begin() + 1);
46 assert(context.begin() == context.end());
47 }
48}
49
50constexpr bool test() {
51 test(fmt: "abc");
52#ifndef TEST_HAS_NO_WIDE_CHARACTERS
53 test(fmt: L"abc");
54#endif
55#ifndef TEST_HAS_NO_CHAR8_T
56 test(fmt: u8"abc");
57#endif
58 test(fmt: u"abc");
59 test(fmt: U"abc");
60
61 return true;
62}
63
64int main(int, char**) {
65 test();
66 static_assert(test());
67
68 return 0;
69}
70

source code of libcxx/test/std/utilities/format/format.formatter/format.parse.ctx/advance_to.pass.cpp