core/types.h: T* check(T *v)
This commit is contained in:
parent
533c96e17d
commit
17faa14416
@ -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
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user