mirror of
https://github.com/jtgans/g13gui.git
synced 2025-06-20 08:23:50 -04:00
39 lines
691 B
C++
39 lines
691 B
C++
#ifndef FIND_OR_THROW_H
|
|
#define FIND_OR_THROW_H
|
|
|
|
#include <map>
|
|
|
|
namespace G13 {
|
|
|
|
class NotFoundException : public std::exception {
|
|
public:
|
|
const char *what() throw();
|
|
};
|
|
|
|
template <class K_T, class V_T>
|
|
inline const V_T &find_or_throw(const std::map<K_T, V_T> &m,
|
|
const K_T &target) {
|
|
auto i = m.find(target);
|
|
|
|
if (i == m.end()) {
|
|
throw NotFoundException();
|
|
}
|
|
|
|
return i->second;
|
|
};
|
|
|
|
template <class K_T, class V_T>
|
|
inline V_T &find_or_throw(std::map<K_T, V_T> &m, const K_T &target) {
|
|
auto i = m.find(target);
|
|
|
|
if (i == m.end()) {
|
|
throw NotFoundException();
|
|
}
|
|
|
|
return i->second;
|
|
};
|
|
|
|
} // namespace G13
|
|
|
|
#endif // FIND_OR_THROW_H
|