g13gui/g13d/find_or_throw.h
June Tate-Gans 1918d6875c g13d: Reformat all the files to Google style
This is closer to what I'm looking for, and gives us a style guide to boot.
2021-04-25 20:30:56 -05:00

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