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

Deduced values in function contraints are not available inside the function? #20849

Open
TurkeyMan opened this issue Feb 11, 2025 · 2 comments
Open

Comments

@TurkeyMan
Copy link
Contributor

I find I have to do this sort of thing fairly often:

T endianToNative(T, bool little)(ref const ubyte[T.sizeof] bytes)
    if (is(T == U[N], U, size_t N))
{
    // repeat function constraint inside static if to capture U and N
    static if (is(T == U[N], U, size_t N))
    {
        // use `U`, `N`...
    }
}

You can see here I write a static-if repeating the function constraint so I can refer to U and N inside the function.
Is there a reason why deduced material from function constraints are not made available to the function?

@Herringway
Copy link
Contributor

Something like this?

T endianToNative(T : U[N], bool little, U, size_t N)(ref const ubyte[T.sizeof] bytes)
{
	// use `U`, `N`...
}

@TurkeyMan
Copy link
Contributor Author

TurkeyMan commented Feb 11, 2025

Doesn't that mean T can implicitly convert to a U[N], or does colon mean == in this case?
But even so, it sucks that U and N are now mangled into the function as additional template args; that's not a good thing.
I stand by my OP...

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

No branches or pull requests

2 participants