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

Enhance alias to work with elements of a sequence? #20612

Open
TurkeyMan opened this issue Dec 28, 2024 · 6 comments
Open

Enhance alias to work with elements of a sequence? #20612

TurkeyMan opened this issue Dec 28, 2024 · 6 comments
Labels
Feature:alias alias and alias this

Comments

@TurkeyMan
Copy link
Contributor

Something like this doesn't work; I think it's because the alias is trying to alias an [] operator expression?

alias seq = AliasSeq!(x, y, z);
alias x = seq[0];

I constantly want to do things like: alias firstParam = Parameters!myFunction[0] when implementing some shim's or function call wrappers.

@WalterBright
Copy link
Member

You'll need to be more specific, as:

template AliasSeq(TList...)
{
    alias AliasSeq = TList;
}

alias seq = AliasSeq!(int, uint, long);
alias x = seq[0];

x j = 3;

static assert(is (typeof(j) == int));

compiles without error.

@TurkeyMan
Copy link
Contributor Author

I'll try and find the problem situations... I always seem to find it when using Parameters!func, or similar functions analysis traits.

@dkorpel
Copy link
Contributor

dkorpel commented Jan 9, 2025

@TurkeyMan Did you find any?

@TurkeyMan
Copy link
Contributor Author

I haven't had time at a computer, I'm traveling at the moment.
But most of the situations I encounter problems were when working with Parameters!(), manipulating function args in call shims and stuff.
Also I think when some T... template args have non-type parameters, I think I've seen weird non-uniform failures when trying to alias certain members to simplify introspection logic.

@TurkeyMan
Copy link
Contributor Author

You'll need to be more specific, as:

template AliasSeq(TList...)
{
    alias AliasSeq = TList;
}

alias seq = AliasSeq!(int, uint, long);
alias x = seq[0];

x j = 3;

static assert(is (typeof(j) == int));

compiles without error.

What about

alias seq = AliasSeq!(1, 2, 3);
alias x = seq[0];

int j = x;

??
I didn't test, I'm just guessing the kind of problem... I need to dig into one of my function adapters.

@ntrel
Copy link
Contributor

ntrel commented Jan 13, 2025

alias seq = AliasSeq!(1, 2, 3);
alias x = seq[0];

seqelem.d(3): Error: alias seqelem.x cannot alias an expression 1

alias x = 1; also doesn't work. That's an issue with alias rather than sequences (https://dlang.org/library/std/meta/alias.html).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:alias alias and alias this
Projects
None yet
Development

No branches or pull requests

5 participants