Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TRIVIAL] Simpler CommonType #8288

Merged
merged 1 commit into from
Oct 18, 2021
Merged

Conversation

andralex
Copy link
Member

this is it

@dlang-bot dlang-bot added the Review:Trivial typos, formatting, comments label Oct 16, 2021
@dlang-bot
Copy link
Contributor

Thanks for your pull request, @andralex!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + phobos#8288"

@RazvanN7 RazvanN7 merged commit 9252a88 into dlang:master Oct 18, 2021
@nordlow
Copy link
Contributor

nordlow commented Oct 18, 2021

What about making the implementation iterative using static foreach and alias assignment? I tried as

    template CommonType(T...)
    {
        static if (T.length == 0)
            alias CommonType = void;
        else
        {
            alias CommonType = T[0];
            static foreach (i; 1 .. T.length)
                static if (is(typeof(true ? CommonType.init : T[i].init) U))
                    CommonType = U;
                else
                    CommonType = void;
        }
    }

but it errors at the line

CommonType = U;

because CommonType is read in the line above. In this case I believe this restriction should be relaxed in the compiler because CommonType is not aliased in the static if expression.

Coulld such an aliasing checking enable more uses cases for alias assignment, @andralex @WalterBright?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Review:Trivial typos, formatting, comments
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants