53 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++1710 11// libc++ supports basic_format_string in C++20 as an extension12// UNSUPPORTED: !stdlib=libc++ && c++2013 14// <format>15 16// template<class charT, class... Args>17// class basic_format_string<charT, type_identity_t<Args>...>18//19// constexpr basic_string_view<charT> get() const noexcept { return str; }20 21#include <format>22 23#include <cassert>24#include <concepts>25#include <string_view>26 27#include "test_macros.h"28#include "make_string.h"29 30#define CSTR(S) MAKE_CSTRING(CharT, S)31#define SV(S) MAKE_STRING_VIEW(CharT, S)32 33template <class CharT>34constexpr bool test() {35 assert((std::basic_format_string<CharT>{CSTR("foo")}.get() == SV("foo")));36 assert((std::basic_format_string<CharT, int>{CSTR("{}")}.get() == SV("{}")));37 assert((std::basic_format_string<CharT, int, char>{CSTR("{} {:*>6}")}.get() == SV("{} {:*>6}")));38 39 // Embedded NUL character40 assert((std::basic_format_string<CharT, void*, bool>{SV("{}\0{}")}.get() == SV("{}\0{}")));41 return true;42}43 44int main(int, char**) {45 test<char>();46 static_assert(test<char>());47#ifndef TEST_HAS_NO_WIDE_CHARACTERS48 test<wchar_t>();49 static_assert(test<wchar_t>());50#endif51 return 0;52}53