core/types.h: T* check(T *v)

master
Perttu Ahola 2014-10-28 14:50:00 +02:00
parent 533c96e17d
commit 17faa14416
2 changed files with 19 additions and 0 deletions

View File

@ -69,6 +69,9 @@ Non-exception throwing and exception-throwing methods
- find_x: Returns nullptr or equivalent if not found
- check_x: Throws exception if not found
To check for nullptr returned by get_x() or find_x(), use the check() function
in core/types.h.
Directory structure
-------------------
├── 3rdparty << Bundled 3rd-party libraries

View File

@ -146,4 +146,20 @@ template<typename T>
static inline cc_* cs(const T &v){
return dump(v).c_str();
}
// check()
template<typename T>
static inline T* check(T *v){
if(v == nullptr)
throw Exception("check(): nullptr");
return v;
}
template<typename T>
static inline const T* check(const T *v){
if(v == nullptr)
throw Exception("check(): nullptr");
return v;
}
// vim: set noet ts=4 sw=4: