xref: /llvm-project/libcxx/test/std/utilities/format/format.syn/runtime_format_string.pass.cpp (revision 92d9f232dd627eea8bd2c825c539b28374bbfa69)
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, c++20, c++23
10 
11 // <format>
12 
13 // template<class charT> struct runtime-format-string {  // exposition-only
14 // private:
15 //   basic_string_view<charT> str;  // exposition-only
16 //
17 // public:
18 //   runtime-format-string(basic_string_view<charT> s) noexcept : str(s) {}
19 //
20 //   runtime-format-string(const runtime-format-string&) = delete;
21 //   runtime-format-string& operator=(const runtime-format-string&) = delete;
22 // };
23 //
24 // runtime-format-string<char> runtime_format(string_view fmt) noexcept;
25 // runtime-format-string<wchar_t> runtime_format(wstring_view fmt) noexcept;
26 //
27 // Additional testing is done in
28 // - libcxx/test/std/utilities/format/format.functions/format.runtime_format.pass.cpp
29 // - libcxx/test/std/utilities/format/format.functions/format.locale.runtime_format.pass.cpp
30 
31 #include <format>
32 
33 #include <cassert>
34 #include <concepts>
35 #include <string_view>
36 #include <type_traits>
37 
38 #include "test_macros.h"
39 
40 template <class T, class CharT>
test_properties()41 static void test_properties() {
42   static_assert(std::is_nothrow_convertible_v<std::basic_string_view<CharT>, T>);
43   static_assert(std::is_nothrow_constructible_v<T, std::basic_string_view<CharT>>);
44 
45   static_assert(!std::copy_constructible<T>);
46   static_assert(!std::is_copy_assignable_v<T>);
47 
48   static_assert(!std::move_constructible<T>);
49   static_assert(!std::is_move_assignable_v<T>);
50 }
51 
main(int,char **)52 int main(int, char**) {
53   static_assert(noexcept(std::runtime_format(std::string_view{})));
54   auto format_string = std::runtime_format(std::string_view{});
55 
56   using FormatString = decltype(format_string);
57   LIBCPP_ASSERT((std::same_as<FormatString, std::__runtime_format_string<char>>));
58   test_properties<FormatString, char>();
59 
60 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
61   static_assert(noexcept(std::runtime_format(std::wstring_view{})));
62   auto wformat_string = std::runtime_format(std::wstring_view{});
63 
64   using WFormatString = decltype(wformat_string);
65   LIBCPP_ASSERT((std::same_as<WFormatString, std::__runtime_format_string<wchar_t>>));
66   test_properties<WFormatString, wchar_t>();
67 #endif // TEST_HAS_NO_WIDE_CHARACTERS
68 
69   return 0;
70 }
71