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
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.
Comments