Skip to main content
added 1 character in body
Source Link
n00b101
  • 163
  • 4
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
    }
});
}
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
    }
});
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
    });
}
added 27 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Note: This idea was inspired by a different Maybe type implementation described in https://github.com/simonask/simonask.github.com/blob/master/maybe.markdown (full source: https://github.com/simonask/reflect/blob/master/base/maybe.hpp)Note: This idea was inspired by a different Maybe type implementation described here (full source)

Note: This idea was inspired by a different Maybe type implementation described in https://github.com/simonask/simonask.github.com/blob/master/maybe.markdown (full source: https://github.com/simonask/reflect/blob/master/base/maybe.hpp)

Note: This idea was inspired by a different Maybe type implementation described here (full source)

edited tags
Link
n00b101
  • 163
  • 4
Source Link
n00b101
  • 163
  • 4
Loading