铛6不支持unordered_map ::合并? [英] clang 6 not supporting unordered_map::merge?

查看:61
本文介绍了铛6不支持unordered_map ::合并?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这个简单的示例中,出现编译错误:

With this trivial example, I get a compilation error:

#include <unordered_map>

int main() {
    std::unordered_map<int, int> a, b;
    a.merge(b);
}

错误:

$ clang++ -std=c++17 merge.cpp
merge.cpp:5:4: error: no member named 'merge' in 'std::__1::unordered_map<int, int, std::__1::hash<int>, std::__1::equal_to<int>, std::__1::allocator<std::__1::pair<const int, int> > >'
        a.merge(b);
        ~ ^
1 error generated.

版本:

$ clang++ --version
clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-apple-darwin17.5.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin

根据cppreference ,由于C ++,这应该是合法的17.GCC 7很高兴对其进行编译.

According to cppreference, this should be legal since C++17. GCC 7 is happy to compile it.

推荐答案

我遇到了同样的问题.我很生气,为什么我不能编译使用 unordered_map :: merge()使用macOS 10.14.6

I had same issue. I was outraged, why I can't compile application which use unordered_map::merge() using macOS 10.14.6

unordered_map :: merge()在c ++ 17中添加了提案 P0083R3拼接图和集合(修订5)",请参见

unordered_map::merge() was added in c++17 with proposal P0083R3 "Splicing Maps and Sets (Revision 5)", see github blame.

文档介绍了常见的编译器对C ++新功能的支持.找到拼接图和集"行,然后检查编译器版本.

Documentation presents common compilers' support for new C++ features. Find row "Splicing Maps and Sets" and check you compiler version.

拼接图和集合"编译器的支持:

"Splicing Maps and Sets" compilers' support:

+-----------------------+---------------------+------+
| Compiler              | Version             | Link |
+-----------------------+---------------------+------+
| GCC libstdc++         |                 7.1 | [1]  |
| Clang libc++          |                 8.0 | [2]  |
| MSVC Standard Library | 19.12 (VS 2017 15.5)| [3]  |
| Apple Clang           |                   - | [4]  |
+-----------------------+---------------------+------+

  1. https://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html
  2. https://libcxx.llvm.org/cxx1z_status.html
  3. https://docs.microsoft.com/cpp/overview/visual-cpp-language-conformance?view = vs-2019
  4. Apple LLVM具有clang编译器的特殊实现,请参见下面的说明

如果您要求使用clang版本,则会得到以下内容:

if you request a clang version, you get something like this:

➜ ~ clang++ --version

Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Apple的clang版本号与官方的版本号无关.一些用户尝试在此处映射苹果和官方的clang版本.我认为,这并不总是可能的.

Apple's clang version number has nothing to with the official's one. Some users try to map apple's and official clang versions here. I think, it's not always possible.

我也找不到其他Apple Clang版本的c ++标准支持状态的详尽表,这与其他编译器不同(如果有的话,请在注释中共享).我们只有官方的 xcode发行说明.

Also I couldn't find exhaustive table of c++ standard support status for different Apple Clang versions, unlike another compilers (share it in comments if you have). All we have is official xcode release notes.

但是mac OS用户仍然可以利用c ++ 17的所有新功能.您应该只...安装原始llvm.在文章在OSX上安装LLVM/Clang"中阅读的详细指南菲利普·约翰斯顿.

But mac OS users can still take advantage of all the new features of c++17. You should only... install original llvm. Detailed guide read in article "Installing LLVM/Clang on OSX" by Phillip Johnston.

使用brew安装llvm更安全:

Installing llvm using brew is much safer:

llvm仅限于小桶,这意味着它没有符号链接到/usr/local,因为macOS已经提供了此软件并安装了另一个并行版本会引起各种麻烦.

llvm is keg-only, which means it was not symlinked into /usr/local, because macOS already provides this software and installing another version in parallel can cause all kinds of trouble.

安装llvm:

// optional "--with-toolchain" from article is deprecated
brew install llvm

检查llvm的状态

➜ ~ brew info llvm
llvm: stable 8.0.1 (bottled), HEAD [keg-only]
Next-gen compiler infrastructure
https://llvm.org/
/usr/local/Cellar/llvm/8.0.1 (6,807 files, 3.3GB)
  Poured from bottle on 2019-09-14 at 14:19:29
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/llvm.rb
==> Dependencies
Build: cmake ✔
Required: libffi ✔, swig ✔
==> Requirements
Build: xcode ✔
==> Options
--HEAD
    Install HEAD version
==> Caveats
To use the bundled libc++ please add the following LDFLAGS:
  LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"

llvm is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have llvm first in your PATH run:
  echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.zshrc

For compilers to find llvm you may need to set:
  export LDFLAGS="-L/usr/local/opt/llvm/lib"
  export CPPFLAGS="-I/usr/local/opt/llvm/include"

检查clang版本:

➜ ~ /usr/local/Cellar/llvm/8.0.1/bin/clang++ --version
clang version 8.0.1 (tags/RELEASE_801/final)
Target: x86_64-apple-darwin18.7.0
Thread model: posix

配置项目

现在您可以定义编译器了,我使用CMake并在CMakeLists.txt中添加行:

Now you can define compiler, I use CMake and add lines in CMakeLists.txt:

set(CMAKE_C_COMPILER "/usr/local/Cellar/llvm/8.0.1/bin/clang")
set(CMAKE_CXX_COMPILER "/usr/local/Cellar/llvm/8.0.1/bin/clang++")
set(CMAKE_CXX_STANDARD 17)

或传递cmake命令的选项:

or pass cmake command's options:

➜ ~ cmake \
  -D CMAKE_C_COMPILER="/usr/local/Cellar/llvm/8.0.1/bin/clang" \
  -D CMAKE_CXX_COMPILER "/usr/local/Cellar/llvm/8.0.1/bin/clang++" \
  /path/to/CMakeLists.txt

或定义环境变量:

➜ ~ export CC=/usr/local/Cellar/llvm/8.0.1/bin/clang
➜ ~ export CXX=/usr/local/Cellar/llvm/8.0.1/bin/clang++
➜ ~ cmake /path/to/CMakeLists.txt

这篇关于铛6不支持unordered_map ::合并?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆