use*_*291 7 c++ qt qmake clang c++11
我正在 macOS 10.13.6 上使用 Qt 5.11.3 进行编译。Qt使用的clang版本是:
$ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -v
Apple LLVM version 9.1.0 (clang-902.0.39.2)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Run Code Online (Sandbox Code Playgroud)
但我收到此错误:
error: no template named 'enable_if_t' in namespace 'std'; did you mean 'enable_if'?
using FloatingOnly = std::enable_if_t<std::is_floating_point<T>::value, O>;
~~~~~^~~~~~~~~~~
enable_if
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/type_traits:423:63: note: 'enable_if' declared here
template <bool, class _Tp = void> struct _LIBCPP_TEMPLATE_VIS enable_if {};
^
Run Code Online (Sandbox Code Playgroud)
到目前为止,我已经做了这些,但没有效果:
// On source *.cpp file
#include <type_traits>
Run Code Online (Sandbox Code Playgroud)
# On project *.pro file
CONFIG += c++17
QMAKE_CXXFLAGS += -std=c++17 # for Clang
QMAKE_CXXFLAGS += -stdlib=libc++ # xcode_settings
QMAKE_CXXFLAGS += -std=c++11
Run Code Online (Sandbox Code Playgroud)
我刚刚使用了这些,错误得到了解决:
CONFIG += c++14
CONFIG += c++17
Run Code Online (Sandbox Code Playgroud)
模板别名enable_if_t在 C++11 中不可用;它是在 C++14 中添加的,就像大多数其他类型特征*_t版本一样(C++17 添加了*_v布尔特征作为inline constexpr变量的版本)。