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// UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
10
11// XFAIL: availability-fp_to_chars-missing
12
13// <format>
14
15// template<class... Args>
16// size_t formatted_size(format-string<Args...> fmt, const Args&... args);
17// template<class... Args>
18// size_t formatted_size(wformat-string<Args...> fmt, const Args&... args);
19
20#include <format>
21#include <cassert>
22#include <vector>
23
24#include "test_macros.h"
25#include "format_tests.h"
26#include "string_literal.h"
27#include "test_format_string.h"
28
29auto test =
30 []<class CharT, class... Args>(
31 std::basic_string_view<CharT> expected, test_format_string<CharT, Args...> fmt, Args&&... args) constexpr {
32 std::size_t size = std::formatted_size(fmt, std::forward<Args>(args)...);
33 assert(size == expected.size());
34 };
35
36auto test_exception = []<class CharT, class... Args>(std::string_view, std::basic_string_view<CharT>, Args&&...) {
37 // After P2216 most exceptions thrown by std::formatted_siz3 become ill-formed.
38 // Therefore this tests does nothing.
39 // A basic ill-formed test is done in formatted_size.verify.cpp
40 // The exceptions are tested by other functions that don't use the basic-format-string as fmt argument.
41};
42
43int main(int, char**) {
44 format_tests<char, execution_modus::partial>(check: test, check_exception: test_exception);
45
46#ifndef TEST_HAS_NO_WIDE_CHARACTERS
47 format_tests_char_to_wchar_t(check: test);
48 format_tests<wchar_t, execution_modus::partial>(check: test, check_exception: test_exception);
49#endif
50
51 return 0;
52}
53

source code of libcxx/test/std/utilities/format/format.functions/formatted_size.pass.cpp