Non-type template parameter dependent on a default template type parameter

lightxbulb

Is there a way (in C++17) to achieve something similar to a forward declare, in a template? What I want to achieve is something like this:

template<typename T, SizeType D, typename SizeType = int>

Obviously here D depends on SizeType, so it must come before it. But in that case I cannot set a default parameter unless D also has a default parameter (which I do not want). Basically I want to be able to "declare" SizeType before D, but "define" it after it.

Edit: Here is an example of how I would like to use it:

template<typename T, SizeType D, typename SizeType = int>
class StaticArray{};
//...
StaticArray<float, 5> s; // = StaticArray<float, 5, int>
StaticArray<float, (1<<40), size_t>; // 1<<40 doesn't fit in int
StoryTeller - Unslander Monica

You could do something like this

template<typename T, auto DArg, typename SizeType = int, SizeType D = DArg>

Now the argument for D is provided first, then the type of D, and finally the argument is converted to D of the correct type.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Template function dependent on non-type parameter

Non type template parameter

Partial specialization of single type template parameter class template using non-type template parameter through a dependent type

Specialize template template parameter with a non-type template parameter

template non-type template parameter

Alias Template with non-type template parameter

why __dependent_type from libcxx uses a template non-type parameter bool _Dummy?

'Use of class template requires template arguments' error with default specified non-type template parameter value

Default template parameter based on type of other template parameter

Can a template template parameter default reference other template type parameters?

Function template taking a template non-type template parameter

Using non-type template template parameter in template specialisation

How to provide a default parameter argument when the type of that parameter is a template type?

Template template parameter with mixed type and non-type variadic parameters

Default parameter value in template function, depending on type

static_assert dependent on non-type template parameter (different behavior on gcc and clang)

non type template parameter pack expansion

pointer non-type template parameter

Non-type variadic template parameter

Why is it called "non-type" template parameter?

Template non-type parameter deduction

Template non-type parameter with different types

Integer sequence as a non-type template parameter

template template parameter of unknown type

template type deduction of template parameter

Determine type of template parameter in template

function template parameter deduction of template parameter vs of default template parameter vs of return type

Template parameter as return type

Why is initialization of a constant dependent type in a template parameter list disallowed by the standard?