Add QT_NO_STD_FORMAT_SUPPORT definition to disable std::format support

The outcome from the QtCS discussion [0] was that we want to add
std::format support directly into the Qt class' header, so that the
users do not need to include anything extra to be able to use it.

This, however, means that many of Qt headers would include <format>,
which itself is quite heavy. As a result, we decided to add a define
that allows to disable std::format support, if the users do not need
it.

This patch introduces QT_NO_STD_FORMAT_SUPPORT as such definition.
Users can define it in their projects. It is also defined for Qt
for now, because we cannot use std::format inside Qt anyway.

Note that we cannot use compile-time QT_FEATURE for that, because
Qt itself can be configured with different parameters than the user
project.

This patch does not add any public documentation for the definition,
because it's not yet clear where to provide these docs. However, it
adds some comments that would hopefully clarify the situation with
the macros.

[0]: https://wiki.qt.io/QtCS2024_std::format

Fixes: QTBUG-128779
Change-Id: Ie3041966c3a2131e3b47750fbe6831e11b4b74cc
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by:  Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
Ivan Solovev 2024-09-09 17:19:51 +02:00
parent 07749de7ef
commit 014007faf5
2 changed files with 12 additions and 0 deletions

View File

@ -156,6 +156,7 @@ qt_internal_add_global_definition(QT_NO_NARROWING_CONVERSIONS_IN_CONNECT)
qt_internal_add_global_definition(QT_EXPLICIT_QFILE_CONSTRUCTION_FROM_PATH)
qt_internal_add_global_definition(QT_USE_QSTRINGBUILDER SCOPE PLUGIN TOOL MODULE)
qt_internal_add_global_definition(QT_NO_FOREACH)
qt_internal_add_global_definition(QT_NO_STD_FORMAT_SUPPORT SCOPE PLUGIN TOOL MODULE)
if(WARNINGS_ARE_ERRORS)
qt_internal_set_warnings_are_errors_flags(PlatformModuleInternal INTERFACE)

View File

@ -12,11 +12,22 @@
#include <QtCore/qsystemdetection.h>
#include <QtCore/qtconfigmacros.h>
// Users can disable std::format support in their
// projects by using this definition.
#ifndef QT_NO_STD_FORMAT_SUPPORT
#if (defined(__cpp_lib_format) && (__cpp_lib_format >= 202106L))
#include <format>
// If this macro is defined, std::format support is actually available.
// Use it to provide the implementation!
// Note that any out-of-line helper function should not depend on this
// definition, as it should be unconditionally available even in C++17 builds
// to keep BC.
#define QT_SUPPORTS_STD_FORMAT 1
#endif // __cpp_lib_format
#endif // QT_NO_STD_FORMAT_SUPPORT
#endif // QTFORMAT_IMPL_H