0
votes

I've got a type IVector3 provided by the glm library:

using IVector3 = glm::ivec3;

I've got a hash function for 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;
    }
};

And I'm trying to map IVector3s to floats in an unordered_map:

std::unordered_map<IVector3, float, IVector3Hash> g_score;

However, when I try and emplace a value in this map, I get a warning that I need to see the reference to function template instantiation:

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>        ]

I've looked through the documentation for std::pair and std::unordered_map but I can't see what I'm doing wrong. The code compiles, but I don't want errors to occur if other compilers are used.

Thank you for any help :)

EDIT to include full warning text: https://pastebin.com/G1EdxKKe

1
Please copy-paste full warning text. What you provided is only a part of it.Algirdas Preidžius
when you emplace use 0.0f, not 0; because 0 is an int not a floatRaxvan
Aha let me try that real quickAlistair401
Thank you @Raxvan that solved itAlistair401

1 Answers

1
votes

I was confused by the long-winded error output, but the actual error was because I was trying to emplace(...) using an int rather than a float as the map required.

Changing to:

g_score.emplace(from_node->index, 0.0f);

solved the issue.