'Is deducing template integer parameter from compile-time-known function-parameter possible?

There is a struct and a generator function for it

template<int Size>
struct Foo
{
    int buffer[Size];
};

template<int Size>
Foo<Size> generate(int Size)
{
      return Foo<Size>();
}

and it produces this error:

: error: declaration of 'int Size' shadows template parameter
8 |     Foo<Size> generate(int Size)

clearly, I can't use same name of integer template parameter as the function parameter to force it deduce the Foo template's parameter.

Is there a way to pick the template parameter like this:

auto foo = generate(32);

instead of this:

auto foo = generate<32>();

Here 32 is compile-time known so it could work if there was a way to do it and I don't expect it to work like this:

auto foo = generate(clock()); // not known, so won't work

On the other hand, it could be good if it could auto-generate it for a limited range like this:

auto foo = generate(clock()%10); // compile-time known to be between 0 and 9

because it is not possible to do it like this:

auto foo = generate<clock()%10>();


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source