martinmoene / expected-dark

Expected objects for C++11 and later (and later perhaps C++98 )
MIT License
52 stars 4 forks source link

operator== Missing for void specialization #29

Open shua27 opened 6 years ago

shua27 commented 6 years ago

When attempting to compare expected objects specialized with a void value type, I get the following error during compilation:

error: no match for ‘operator*’ (operand type is ‘const nonstd::expected<void, CUSTOM_ERROR_CODE>’) 
        return bool(x) != bool(y) ? false : bool(x) == false ? true : *x == *y;

Obviously this wouldn't compile as you can't compare as the void specialization of expected doesn't (can't) have an implementation of operator*.

Currently, the behavior of the operator== when T is not void is such that the values are compared if a value exists, else just the truthiness is compared, which makes sense. Reference.

Extending this logic to the void specialization would just require comparing the truthiness of the object, as all void expected objects should be equal:

template <typename E>
constexpr bool operator==( expected<void,E> const & x, expected<void,E> const & y )
{
    return bool(x) == bool(y);
}

Is there a reason why the equality operator hasn't been implemented for the void specialization?

martinmoene commented 6 years ago

Thanks @shua27,

I'm in the process of updating expected lite to the latest proposal, p0323R6, see issue #20 (*)

IIUC, p0323R6's section Expected Equality operators [expected.equality_op] describes the behavior you propose.

(*) Be it sidetracked a bit to gsl-lite, span-lite and status_value.