On Monday, 11 January 2021 at 05:44:19 UTC, Ola Fosheim Grostad wrote:
On Monday, 11 January 2021 at 01:49:26 UTC, Paul Backus wrote:
Why are these particular implementation details important to you?

It is for object.d.

I want to allow fast runtime indexing if all elements are of the same type.

static if (allSameType) {
    auto opIndex(size_t i) {
        switch (i) {
            static foreach (j; 0 .. Types.length) {
                case j: return this.expand[j];
            }
            default: assert(0); // or throw RangeError
        }
    }
}

Any decent compiler will turn this into `return this.expand[i]`.

If the types are different I want static indexing, so the plan is to resolve failed lookup as __0 etc by modifying the compiler.

You can just fall back to `alias expand this` like Phobos's Tuple does in this case. No compiler modification needed.
  • I want to create my own Tuple... Ola Fosheim Grøstad via Digitalmars-d-learn
    • Re: I want to create my ... Paul Backus via Digitalmars-d-learn
      • Re: I want to create... Ola Fosheim Grostad via Digitalmars-d-learn
        • Re: I want to cr... Paul Backus via Digitalmars-d-learn
          • Re: I want t... Ola Fosheim Grøstad via Digitalmars-d-learn
            • Re: I w... Ola Fosheim Grøstad via Digitalmars-d-learn
            • Re: I w... Paul Backus via Digitalmars-d-learn
              • Re:... Ola Fosheim Grøstad via Digitalmars-d-learn
              • Re:... Ola Fosheim Grøstad via Digitalmars-d-learn
                • ... Ola Fosheim Grøstad via Digitalmars-d-learn
                • ... Ola Fosheim Grøstad via Digitalmars-d-learn
                • ... Paul Backus via Digitalmars-d-learn
                • ... Ola Fosheim Grøstad via Digitalmars-d-learn
                • ... Paul Backus via Digitalmars-d-learn

Reply via email to