On Tuesday, 10 July 2018 at 13:28:42 UTC, Yuxuan Shui wrote:
On Tuesday, 10 July 2018 at 11:37:25 UTC, ag0aep6g wrote:
On 07/10/2018 11:56 AM, Yuxuan Shui wrote:
Possible alternatives:

* struct Void {}. Takes 1 byte, not as ideal
* alias Void = AliasSeq!(). Doesn't work as template argument. i.e.
       SomeTemplate!Void; // actually become SomeTemplate!()

What about `void[0]`? It's a proper type. You can declare a field with it. Size is 0.

Nice!

How does that solve your original problem?


    struct Result(T, E) {
        bool is_err;
        union {
            T result;
            static if (!is(E == void))
                E error;
        }
    }

I thought you didn't want to have to specialize(meaning the static if)?

Doesn't seem like passing void[0] really solves that problem since you still might pass void.

I think the real solution is simply to never pass void! Then the static if is not needed



    struct Result(T = void[0], E = void[0]) {
        bool is_err;
        union {
            T result;
            E error;
        }
    }






Reply via email to