Files
cavity_LIBS/compat/qt5_msvc_compat.h
2026-11-06 14:45:09 +08:00

45 lines
1.5 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// ===========================================================================
// Qt 5.15.2 + 新版 MSVC(VS2022 17.10 之后 / VS2026)兼容层
//
// 背景:Qt 5.15 的 qlist.h / qvector.h / qvarlengtharray.h 里用
// QT_MAKE_CHECKED_ARRAY_ITERATOR 扩展成 stdext::make_checked_array_iterator
// (MSVC 的“受检数组迭代器”)。新版 MSVC 的 <iterator> 已经把这个辅助函数
// 删掉了,于是 Qt 头文件在实例化 QVector<T>::operator== 时报:
// error C2653: "stdext": 不是类或命名空间名称
// error C3861: "make_checked_array_iterator": 找不到标识符
//
// 做法:在包含任何 Qt 头文件之前,把这两个辅助函数补回到 stdext 命名空间。
// 这里返回裸指针,语义与“不做检查的迭代器”一致——Qt 只是把它当普通迭代器用。
//
// 用法:只对 MSVC 生效,用 /FI(强制包含)注入,不改动 Qt 安装目录:
// cl /FI"D:\...\compat\qt5_msvc_compat.h" ...
// CMake 里由 target_compile_options(... /FI<本文件>) 自动加入。
// ===========================================================================
#ifndef CAVITY_QT5_MSVC_COMPAT_H
#define CAVITY_QT5_MSVC_COMPAT_H
#include <cstddef>
#if defined(_MSC_VER) && !defined(__clang__)
namespace stdext {
template <typename T>
inline T *make_checked_array_iterator(T *p, std::size_t /*size*/)
{
return p;
}
template <typename T>
inline T *make_unchecked_array_iterator(T *p)
{
return p;
}
} // namespace stdext
#endif // _MSC_VER
#endif // CAVITY_QT5_MSVC_COMPAT_H