wgois / OIS

Official OIS repository. Object oriented Input System
https://wgois.github.io/OIS/
zlib License
254 stars 86 forks source link

CI build fails on Linux/Clang because of std::hash<OIS::KeyCode> #55

Closed Ybalrid closed 4 years ago

Ybalrid commented 4 years ago

See this : https://travis-ci.org/wgois/OIS/jobs/587741226#L826

dagophil commented 4 years ago

This may be a defect in clang or its standard library.

One solution would be to specialize std::hash for KeyCode. Adding this to the bottom of OISKeyboard.h works:

namespace std {
  template <> struct hash<OIS::KeyCode> {
    size_t operator() (OIS::KeyCode code) const {
      return static_cast<size_t>(code);
    }
  };
}

Note that specializing std::hash is explicitly allowed by the standard.

Another way would be to change the line

typedef std::unordered_map<KeyCode, KeySym> OIStoX_KeyMap;

in LinuxKeyboard.h to

typedef std::unordered_map<KeyCode, KeySym, std::hash<int>> OIStoX_KeyMap;

Both solutions fix the Travis build and also work on AppVeyor. Do you want me to create a pull request for one of them?