Skip to content

Commit

Permalink
Add QT_NO_STD_FORMAT_SUPPORT definition to disable std::format support
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by:  Alexey Edelev <[email protected]>
  • Loading branch information
isolovev committed Sep 10, 2024
1 parent 07749de commit 014007f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmake/QtInternalTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions src/corelib/io/qtformat_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 014007f

Please sign in to comment.