[Webkit-unassigned] [Bug 176285] WSL should support the bool type

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Sat Sep 2 18:01:25 PDT 2017


https://bugs.webkit.org/show_bug.cgi?id=176285

--- Comment #1 from Filip Pizlo <fpizlo at apple.com> ---
Also, it seems like it would be best to remove the notion that operator! is a customizable operator. Instead, go straight to explicit operator bool.

In this world, operator! is built-in.

operator! and all of the conditional contexts ("if (_)", "while (_)", and "for (;_;)") are parsed so that they first emit a call to "operator bool(T)". Essentially we can turn this:

    !e

into this:

    !(operator bool(e))

Where you can declare an operator bool for whatever types you like.  We could declare a default one that looks like this:

operator bool<T>(T value)
{
    T defaultValue;
    return value != defaultValue;
}

Note that a!=b is parsed as !(a==b).  Currently override resolution is order-based: we parse the signatures in order and we pick the first one that matches.  We could say that the standard library has a suffix portion that is parsed after the program, which contains the following:

operator bool<T>(T value)
{
    T defaultValue;
    return value != defaultValue;
}
native bool operator==<T>(T a, T b); // Does bitwise equality

By making this a suffix, it means that the programmer can always rely on these as defaults but can easily override them for their type.

So, in this world, this totally works.

struct MyPoint { int x; int y; }
void foo()
{
    MyPoint p;
    ...
    if (p)
        do stuff if p is not the origin
}

Does this seem useful, or overkill?  Do you want to try to do this?

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20170903/102a96c9/attachment.html>


More information about the webkit-unassigned mailing list