简体   繁体   English

在std :: map中添加std :: tuple可以在Macos上运行,而不是在Linux上运行

[英]Adding std::tuple to std::map compiles and works on Macos, not on Linux

Here is the following code (assuming id and speed are already initialised, and includes are correct): 这是以下代码(假设idspeed已经初始化,并且包含正确的代码):

std::map<int, std::tuple<double, double>> mymap;

mymap.insert(std::pair<int, std::tuple<double, double>>(id, speed));

This code compiles and works under Macos (Xcode using clang-800.0.42.1) and Linux (Ubuntu 16.04, gcc 5.4.0). 此代码可在Macos(使用clang-800.0.42.1的Xcode) Linux(Ubuntu 16.04,gcc 5.4.0)下编译和运行。

mymap.insert(std::tie(id, speed));

This code compiles and works under Macos (Xcode using clang-800.0.42.1), but not under Linux (Ubuntu 16.04, gcc 5.4.0). 此代码可在Macos(使用clang-800.0.42.1的Xcode)下编译并工作,但在Linux(Ubuntu 16.04,gcc 5.4.0)下则不能编译。 For the latter, the error raised is: 对于后者,引发的错误是:

error: no matching function for call to 'std::map<int, std::tuple<double, double> >::insert(std::tuple<int&, std::tuple<double, double>&>)

Note that the problem is similar when trying to insert an std::tuple to an std::map (bypassed by using std::pair instead of std::tuple). 请注意,尝试将std :: tuple插入std :: map时,问题类似(通过使用std :: pair而不是std :: tuple绕过)。

Can anyone explain? 谁能解释? Thanks! 谢谢!

Tuples are added to C++ form C++11. 元组以C ++ 11形式添加到C ++。

std::tuple std :: tuple

For use of C++11 features you need to add -std=c++11 flag to your gcc compiler by default it is not activated yet. 要使用C ++ 11功能,您需要在默认情况下将-std = c ++ 11标志添加到gcc编译器。

I think mac compiles because you are using Xcode and maybe the -std=c++11 flag is already set from IDA. 我认为mac可以编译是因为您正在使用Xcode,也许-std = c ++ 11标志已从IDA设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM