I think the suggestion here is to just limit the functions using the “null” terminology to overloads accepting pointers. So if we currently have
template <class X, class Y> auto cast_or_null(const Y &Val) {
return cast_if_present<X>(Val);
}
template <class X, class Y> auto cast_or_null(Y &Val) {
return cast_if_present<X>(Val);
}
template <class X, class Y> auto cast_or_null(Y *Val) {
return cast_if_present<X>(Val);
}
template <class X, class Y> auto cast_or_null(std::unique_ptr<Y> &&Val) {
return cast_if_present<X>(std::move(Val));
}
then we can reduce this to just
template <class X, class Y> auto cast_or_null(Y *Val) {
return cast_if_present<X>(Val);
}
This limits the use of cast_or_null
(and friends) to just the case where the naming makes sense.
Also worth noting that next to the two functions already discussed we also have isa_and_nonnull
/ isa_and_present
. The former is self-explanatory, while the latter is not.