g13gui/g13d/find_or_throw.h
June Tate-Gans ae6cf5084a g13d: Rework and cleanup namespaces and files
This is the first half of some major rework of the g13d codebase to make things
a bit more manageable. This splits out a great deal of stuff from helper.h into
separate translation units, and also breaks out a great deal of the g13.h header
into separate translation units as well.

Doing this saves in compilation time as we make changes to the system, and also
helps to clean up a whole bunch of leaking symbols.
2021-04-25 16:35:44 -05:00

39 lines
688 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