QT C 使用功能模板中的约束

Qt C++ using constraints in function templates

本文关键字:约束 功能 QT      更新时间:2023-10-16

使用QT我尝试声明功能模板以计算quint8quint16quint32的某些值。我写道:

template<typename T>
concept CrcCompatible = typeid(T) == typeid(quint8) || typeid(T) == typeid(quint16) || typeid(T) == typeid(quint32);
template<typename T> requires CrcCompatible<T>
T crc(T initial, T polynomial, T *pcBlock, T len, bool isFinalXor);

但是conceptrequires关键字并未作为语法的一部分突出显示。当我尝试编译此代码时发生错误时:

concept does not name a type
...
requires does not name a type

我尝试第一次使用QT中的模板。我不明白如何解决此错误,以及为什么编译器无法理解关键字。

在项目文件中我添加QMAKE_CXXFLAGS += -std=c++11CONFIG += c++11但是什么都没有改变。

我不明白我在Google中问什么,所以找不到答案...

我想问题是C 11中不支持概念。从我在文档中看到的内容,这些概念仅在C 20中可用。无论如何,如果现在由某些组合商支持,则应通过除--std=c++11以外的其他标志启用此支持。