Debian Codegraph @

libcxx/test/std/utilities/format/format.arguments/format.args/ctor.pass.cpp

raw
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 // template<class... Args>
13 // basic_format_args(const format-arg-store<Context, Args...>& store) noexcept;
14
15 #include <format>
16 #include <cassert>
17 #include <type_traits>
18
19 #include "test_macros.h"
20
21 template <class CharT>
22 void test() {
23 int i = 1;
24 char c = 'c';
25 nullptr_t p = nullptr;
26 using Context = std::basic_format_context<CharT*, CharT>;
27 static_assert(!std::is_default_constructible_v<std::basic_format_args<Context>>);
28 {
29 auto store = std::make_format_args<Context>(i);
30 ASSERT_NOEXCEPT(std::basic_format_args<Context>{store});
31 std::basic_format_args<Context> format_args{store};
32 assert(format_args.get(0));
33 assert(!format_args.get(1));
34 }
35 {
36 auto store = std::make_format_args<Context>(i, c);
37 ASSERT_NOEXCEPT(std::basic_format_args<Context>{store});
38 std::basic_format_args<Context> format_args{store};
39 assert(format_args.get(0));
40 assert(format_args.get(1));
41 assert(!format_args.get(2));
42 }
43 {
44 auto store = std::make_format_args<Context>(i, c, p);
45 ASSERT_NOEXCEPT(std::basic_format_args<Context>{store});
46 std::basic_format_args<Context> format_args{store};
47 assert(format_args.get(0));
48 assert(format_args.get(1));
49 assert(format_args.get(2));
50 assert(!format_args.get(3));
51 }
52 }
53
54 void test() {
55 test<char>();
56 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
57 test<wchar_t>();
58 #endif
59 }
60
61 int main(int, char**) {
62 test();
63
64 return 0;
65 }