#ifndef _LIBCPP___OSTREAM_PRINT_H
#define _LIBCPP___OSTREAM_PRINT_H
#include <__config>
#if _LIBCPP_HAS_LOCALIZATION
# include <__fwd/ostream.h>
# include <__iterator/ostreambuf_iterator.h>
# include <__ostream/basic_ostream.h>
# include <format>
# include <ios>
# include <print>
# include <streambuf>
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
# endif
_LIBCPP_BEGIN_NAMESPACE_STD
# if _LIBCPP_STD_VER >= 23
template <class = void> _LIBCPP_HIDE_FROM_ABI inline void
__vprint_nonunicode(ostream& __os, string_view __fmt, format_args __args, bool __write_nl) {
ostream::sentry __s(__os);
if (__s) {
string __o = std::vformat(__os.getloc(), __fmt, __args);
if (__write_nl)
__o += '\n';
# if _LIBCPP_HAS_EXCEPTIONS
try {
# endif if (auto __rdbuf = __os.rdbuf();
!__rdbuf || __rdbuf->sputn(__o.data(), __o.size()) != static_cast<streamsize>(__o.size()))
__os.setstate(ios_base::badbit | ios_base::failbit);
# if _LIBCPP_HAS_EXCEPTIONS
} catch (...) {
__os.__set_badbit_and_consider_rethrow();
}
# endif }
}
template <class = void> _LIBCPP_HIDE_FROM_ABI inline void vprint_nonunicode(ostream& __os, string_view __fmt, format_args __args) {
std::__vprint_nonunicode(__os, __fmt, __args, false);
}
_LIBCPP_EXPORTED_FROM_ABI FILE* __get_ostream_file(ostream& __os);
# if _LIBCPP_HAS_UNICODE
template <class = void> _LIBCPP_HIDE_FROM_ABI void __vprint_unicode(ostream& __os, string_view __fmt, format_args __args, bool __write_nl) {
# if _LIBCPP_AVAILABILITY_HAS_PRINT == 0
return std::__vprint_nonunicode(__os, __fmt, __args, __write_nl);
# else
FILE* __file = std::__get_ostream_file(__os);
if (!__file || !__print::__is_terminal(__file))
return std::__vprint_nonunicode(__os, __fmt, __args, __write_nl);
__os.flush();
# if _LIBCPP_HAS_EXCEPTIONS
try {
# endif ostream::sentry __s(__os);
if (__s) {
# ifndef _LIBCPP_WIN32API
__print::__vprint_unicode_posix(__file, __fmt, __args, __write_nl, true);
# elif _LIBCPP_HAS_WIDE_CHARACTERS
__print::__vprint_unicode_windows(__file, __fmt, __args, __write_nl, true);
# else
# error "Windows builds with wchar_t disabled are not supported."
# endif
}
# if _LIBCPP_HAS_EXCEPTIONS
} catch (...) {
__os.__set_badbit_and_consider_rethrow();
}
# endif # endif }
template <class = void> _LIBCPP_HIDE_FROM_ABI inline void vprint_unicode(ostream& __os, string_view __fmt, format_args __args) {
std::__vprint_unicode(__os, __fmt, __args, false);
}
# endif
template <class... _Args>
_LIBCPP_HIDE_FROM_ABI void print(ostream& __os, format_string<_Args...> __fmt, _Args&&... __args) {
# if _LIBCPP_HAS_UNICODE
if constexpr (__print::__use_unicode_execution_charset)
std::__vprint_unicode(__os, __fmt.get(), std::make_format_args(__args...), false);
else
std::__vprint_nonunicode(__os, __fmt.get(), std::make_format_args(__args...), false);
# else
std::__vprint_nonunicode(__os, __fmt.get(), std::make_format_args(__args...), false);
# endif }
template <class... _Args>
_LIBCPP_HIDE_FROM_ABI void println(ostream& __os, format_string<_Args...> __fmt, _Args&&... __args) {
# if _LIBCPP_HAS_UNICODE
if constexpr (__print::__use_unicode_execution_charset)
std::__vprint_unicode(__os, __fmt.get(), std::make_format_args(__args...), true);
else
std::__vprint_nonunicode(__os, __fmt.get(), std::make_format_args(__args...), true);
# else
std::__vprint_nonunicode(__os, __fmt.get(), std::make_format_args(__args...), true);
# endif }
template <class = void> _LIBCPP_HIDE_FROM_ABI inline void println(ostream& __os) {
std::print(__os, "\n");
}
# endif
_LIBCPP_END_NAMESPACE_STD
#endif
#endif