| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 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 |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17 |
| 10 | |
| 11 | // <format> |
| 12 | |
| 13 | // constexpr void advance_to(const_iterator it); |
| 14 | |
| 15 | #include <format> |
| 16 | |
| 17 | #include <cassert> |
| 18 | #include <string_view> |
| 19 | |
| 20 | #include "test_macros.h" |
| 21 | |
| 22 | template <class CharT> |
| 23 | constexpr void test(const CharT* fmt) { |
| 24 | { |
| 25 | std::basic_format_parse_context<CharT> context(fmt); |
| 26 | |
| 27 | context.advance_to(context.begin() + 1); |
| 28 | assert(std::to_address(context.begin()) == fmt + 1); |
| 29 | |
| 30 | context.advance_to(context.begin() + 1); |
| 31 | assert(std::to_address(context.begin()) == fmt + 2); |
| 32 | |
| 33 | context.advance_to(context.begin() + 1); |
| 34 | assert(context.begin() == context.end()); |
| 35 | } |
| 36 | { |
| 37 | std::basic_string_view view{fmt}; |
| 38 | std::basic_format_parse_context context(view); |
| 39 | |
| 40 | context.advance_to(context.begin() + 1); |
| 41 | assert(std::to_address(context.begin()) == fmt + 1); |
| 42 | |
| 43 | context.advance_to(context.begin() + 1); |
| 44 | assert(std::to_address(context.begin()) == fmt + 2); |
| 45 | |
| 46 | context.advance_to(context.begin() + 1); |
| 47 | assert(context.begin() == context.end()); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | constexpr bool test() { |
| 52 | test(fmt: "abc" ); |
| 53 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 54 | test(fmt: L"abc" ); |
| 55 | #endif |
| 56 | #ifndef TEST_HAS_NO_CHAR8_T |
| 57 | test(fmt: u8"abc" ); |
| 58 | #endif |
| 59 | test(fmt: u"abc" ); |
| 60 | test(fmt: U"abc" ); |
| 61 | |
| 62 | return true; |
| 63 | } |
| 64 | |
| 65 | int main(int, char**) { |
| 66 | test(); |
| 67 | static_assert(test()); |
| 68 | |
| 69 | return 0; |
| 70 | } |
| 71 | |