使用 std::unordered_map 的模板实例化警告
Template instantiation warning using std::unordered_map
我有 glm 库提供的类型 IVector3
:
using IVector3 = glm::ivec3;
我有一个 IVector3s 的哈希函数:
struct IVector3Hash
{
std::size_t operator()(IVector3 const& i) const noexcept
{
std::size_t seed = 0;
boost::hash_combine(seed, i.x);
boost::hash_combine(seed, i.y);
boost::hash_combine(seed, i.z);
return seed;
}
};
我正在尝试将 IVector3s 映射到 unordered_map:
中的浮点数
std::unordered_map<IVector3, float, IVector3Hash> g_score;
但是,当我尝试在此映射中放置一个值时,我收到一条警告,提示我需要查看对函数模板实例化的引用:
g_score.emplace(from_node->index, 0);
1>c:\users\accou\documents\pathfindingexamples\c++ library\pathfindinglib\pathfindinglib\pathfinding.cpp(44): note: see reference to function template instantiation 'std::pair<std::_List_iterator<std::_List_val<std::_List_simple_types<_Ty>>>,boo
l> std::_Hash<std::_Umap_traits<_Kty,float,std::_Uhash_compare<_Kty,_Hasher,_Keyeq>,_Alloc,false>>::emplace<IVector3&,int>(IVector3 &,int &&)' being compiled
1> with
1> [
1> _Ty=std::pair<const IVector3,float>,
1> _Kty=IVector3,
1> _Hasher=IVector3Hash,
1> _Keyeq=std::equal_to<IVector3>,
1> _Alloc=std::allocator<std::pair<const IVector3,float>>
1> ]
我已经查看了 std::pair 和 std::unordered_map 的文档,但我看不出我做错了什么。代码可以编译,但我不希望使用其他编译器时出现错误。
感谢您的帮助:)
编辑以包括完整的警告文本:https://pastebin.com/G1EdxKKe
我对 long-winded 错误输出感到困惑,但实际错误是因为我试图 emplace
(...) 使用 int 而不是 float 作为地图所需。
更改为:
g_score.emplace(from_node->index, 0.0f);
解决了问题。
我有 glm 库提供的类型 IVector3
:
using IVector3 = glm::ivec3;
我有一个 IVector3s 的哈希函数:
struct IVector3Hash
{
std::size_t operator()(IVector3 const& i) const noexcept
{
std::size_t seed = 0;
boost::hash_combine(seed, i.x);
boost::hash_combine(seed, i.y);
boost::hash_combine(seed, i.z);
return seed;
}
};
我正在尝试将 IVector3s 映射到 unordered_map:
中的浮点数std::unordered_map<IVector3, float, IVector3Hash> g_score;
但是,当我尝试在此映射中放置一个值时,我收到一条警告,提示我需要查看对函数模板实例化的引用:
g_score.emplace(from_node->index, 0);
1>c:\users\accou\documents\pathfindingexamples\c++ library\pathfindinglib\pathfindinglib\pathfinding.cpp(44): note: see reference to function template instantiation 'std::pair<std::_List_iterator<std::_List_val<std::_List_simple_types<_Ty>>>,boo
l> std::_Hash<std::_Umap_traits<_Kty,float,std::_Uhash_compare<_Kty,_Hasher,_Keyeq>,_Alloc,false>>::emplace<IVector3&,int>(IVector3 &,int &&)' being compiled
1> with
1> [
1> _Ty=std::pair<const IVector3,float>,
1> _Kty=IVector3,
1> _Hasher=IVector3Hash,
1> _Keyeq=std::equal_to<IVector3>,
1> _Alloc=std::allocator<std::pair<const IVector3,float>>
1> ]
我已经查看了 std::pair 和 std::unordered_map 的文档,但我看不出我做错了什么。代码可以编译,但我不希望使用其他编译器时出现错误。
感谢您的帮助:)
编辑以包括完整的警告文本:https://pastebin.com/G1EdxKKe
我对 long-winded 错误输出感到困惑,但实际错误是因为我试图 emplace
(...) 使用 int 而不是 float 作为地图所需。
更改为:
g_score.emplace(from_node->index, 0.0f);
解决了问题。