Skip to content

Commit 760df88

Browse files
Add a convenience function to aid in casting from a possibly null
reference to a reference that is known not to be null.
1 parent d8ddcaf commit 760df88

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

dynd/include/utility_functions.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,17 @@ inline py_ref_tmpl<owns_ref, true> nullcheck(py_ref_tmpl<owns_ref, not_null> &&o
401401
return out;
402402
}
403403

404+
/* Convert to a non-null reference.
405+
* No nullcheck is used, except for an assertion in debug builds.
406+
* This should be used when the pointer is already known to not be null.
407+
*/
408+
template <bool owns_ref, bool not_null>
409+
inline py_ref_tmpl<owns_ref, true> nullcheck(py_ref_tmpl<owns_ref, not_null> &&obj) noexcept
410+
{
411+
assert(obj.get() != nullptr);
412+
return py_ref_tmpl<owns_ref, true>(obj.release(), owns_ref);
413+
}
414+
404415
// RAII class to acquire GIL.
405416
class with_gil {
406417
PyGILState_STATE m_gstate;

0 commit comments

Comments
 (0)