C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Iterating over a parameter pack for...

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Tue, 5 Dec 2023 11:18:51 +0000
On Tue, Dec 5, 2023 at 10:02 AM Marcin Jaczewski wrote:
>
> switch (x)
> {
> template for (constexpr auto a : list)
> {
> // this line is effective copy pasted multiple times
> // with different `a` from each iteration of `template for`
> case a: return foo<a>();
> }
> }


What are you trying to do there in that code? Is 'x' a compile-time
constant integer? Is 'list' a pack of types, or a pack of variables?
Could you please write a full template function?

Anyway it would be interesting to have 'switch typename', which we
could combine with a "for typename..." as follows:

    template<typename... Ts>
    consteval bool AtLeastOneTypeIsSignedShortOrSignedInt(void) noexcept
    {
        for typename... ( T : Ts )
        {
            switch typename ( T )
            {
            case typename int :
            case typename short : return true;
            }
        }

        return false;
    }

Received on 2023-12-05 11:19:04