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 explicit
13// basic_format_parse_context(basic_string_view<charT> fmt,
14// size_t num_args = 0) noexcept
15
16#include <format>
17
18#include <cassert>
19#include <string_view>
20#include <type_traits>
21
22#include "test_macros.h"
23
24template <class CharT>
25constexpr void test(const CharT* fmt) {
26 // Validate the constructor is explicit.
27 static_assert(
28 !std::is_convertible_v<std::basic_string_view<CharT>,
29 std::basic_format_parse_context<CharT> >);
30 static_assert(
31 !std::is_copy_constructible_v<std::basic_format_parse_context<CharT> >);
32 static_assert(
33 !std::is_copy_assignable_v<std::basic_format_parse_context<CharT> >);
34 // The move operations are implicitly deleted due to the
35 // deleted copy operations.
36 static_assert(
37 !std::is_move_constructible_v<std::basic_format_parse_context<CharT> >);
38 static_assert(
39 !std::is_move_assignable_v<std::basic_format_parse_context<CharT> >);
40
41 ASSERT_NOEXCEPT(std::basic_format_parse_context{std::basic_string_view<CharT>{}});
42 ASSERT_NOEXCEPT(std::basic_format_parse_context{std::basic_string_view<CharT>{}, 42});
43
44 {
45 std::basic_format_parse_context<CharT> context(fmt);
46 assert(std::to_address(context.begin()) == &fmt[0]);
47 assert(std::to_address(context.end()) == &fmt[3]);
48 }
49 {
50 std::basic_string_view view{fmt};
51 std::basic_format_parse_context context(view);
52 assert(context.begin() == view.begin());
53 assert(context.end() == view.end());
54 }
55}
56
57constexpr bool test() {
58 test(fmt: "abc");
59#ifndef TEST_HAS_NO_WIDE_CHARACTERS
60 test(fmt: L"abc");
61#endif
62#ifndef TEST_HAS_NO_CHAR8_T
63 test(fmt: u8"abc");
64#endif
65 test(fmt: u"abc");
66 test(fmt: U"abc");
67
68 return true;
69}
70
71int main(int, char**) {
72 test();
73 static_assert(test());
74
75 return 0;
76}
77

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