project-imprimis / libprimis

Libprimis: Imprimis' 3D destroyable world engine
https://project-imprimis.github.io/libprimis/index.html
Other
29 stars 8 forks source link

std::map and std::unordered_map STL #257 #258

Closed Duskhorn closed 1 year ago

Duskhorn commented 2 years ago

I'll add this just to keep track for now, rn I have some painful template errors and I don't understand what it wants from me

Duskhorn commented 2 years ago

I require help in this template error landscape

In file included from /usr/include/c++/10.2/string:48,
                 from /home/dusk/projects/libprimis/src/engine/../libprimis-headers/cube.h:27,
                 from /home/dusk/projects/libprimis/src/engine/model/animmodel.cpp:10:
/usr/include/c++/10.2/bits/stl_function.h: In instantiation of 'constexpr bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = animmodel::shaderparams]':
/usr/include/c++/10.2/bits/stl_map.h:499:32:   required from 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = animmodel::shaderparams; _Tp = animmodel::ShaderParamsKey; _Compare = std::less<animmodel::shaderparams>; _Alloc = std::allocator<std::pair<const animmodel::shaderparams, animmodel::ShaderParamsKey> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = animmodel::ShaderParamsKey; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = animmodel::shaderparams]'
/home/dusk/projects/libprimis/src/engine/model/animmodel.cpp:204:39:   required from here
/usr/include/c++/10.2/bits/stl_function.h:386:20: error: no match for 'operator<' (operand types are 'const animmodel::shaderparams' and 'const animmodel::shaderparams')
  386 |       { return __x < __y; }
      |                ~~~~^~~~~
no-lex commented 2 years ago

You need a comparison operator because map is a binary search tree. Since there is no particularly good logical fit for operator< with shaderparams you probably want to use an unordered_map.

Duskhorn commented 1 year ago

Given the fact that a lot has happened since I last worked on this and I can't keep track of the stuff to fix I'm gonna close this PR in favor of a newer one