void foo(const maybe_ptr<int>& ptr)
{
bool ran = maybe_if(ptr, [](int* n)
{
bar(*n); // never reached if n is null
});
// ran is true if ptr did not contain null (i.e. the lambda was run)
});
void foo(const maybe_ptr<int>& ptr1, const maybe_ptr<float>& ptr2)
{
bool ran = maybe_if(ptr1, ptr2, [](int* n, float* x)
{
bar(*n, *x); // never reached if n or x are null
});
// ran is true if ptr1 & ptr2 did not contain null
});
void foo(const maybe_ptr<int>& ptr)
{
// throws exception if ptr contains null
maybe_iff(ptr, [](int* n)
{
bar(*n); // never reached if n is null
}
});
}