我不明白为什么我不能unordered_map用一个array<int,3>键作为键类型:
#include <unordered_map>
using namespace std;
int main() {
array<int,3> key = {0,1,2};
unordered_map< array<int,3> , int > test;
test[key] = 2;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我得到一个很长的错误,最相关的部分是
main.cpp:11:9: error: no match for ‘operator[]’ (operand types are std::unordered_map<std::array<int, 3ul>, int>’ and ‘std::array<int, 3ul>’)
test[key] = 2;
^
Run Code Online (Sandbox Code Playgroud)
数组是否因为错过了一些要求而没有资格成为密钥?
我目前正在研究涉及大量数据和复杂算法的科学计算项目,因此我需要进行大量的代码分析.我目前正依赖<ctime>并clock_t计算代码的执行时间.我对这个解决方案非常满意......除了我基本上计时所有内容,因此对于我必须调用的每一行实际代码start_time_function123 = clock(), end_time_function123 = clock()以及cout << "function123 execution time: " << (end_time_function123-start_time_function123) / CLOCKS_PER_SEC << endl.这导致繁重的代码膨胀,并迅速使我的代码不可读.你会怎么处理?
我能想到的唯一解决方案是找到一个IDE,允许我标记部分代码(在不同的位置,甚至在不同的文件中),并用一个按钮切换隐藏/显示所有标记的代码.这将允许我隐藏与大多数时间分析相关的代码部分,并且只在我想要的时候显示它.