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