I am trying to create template class for arbitrary precision unsigned integer type. In order to do this properly I need to have multiple versions of this template class with different constraints. Here is my version:
template<uint32_t N,bool Destroy=true,bool Const=false>
requires(N >= 16 and __globals::is_power_2(N) and Destroy and not Const)
class _uint;
template<uint32_t N,bool Destroy,bool Const>
requires(N >= 16 and __globals::is_power_2(N) and not Destroy and Const)
class _uint;
/* Some necessary declarations */
template <uint32_t N, bool Destroy, bool Const>
requires (N >= 16 && __globals::is_power_2(N) && Destroy && not Const)
class _uint
{
// ... Class definition ...
};
template <uint32_t N, bool Destroy, bool Const>
requires (N >= 16 && __globals::is_power_2(N) && not Destroy && Const)
class _uint
{
// ... Class definition ...
};
Unfortunately, compiler tells me the following:
error: redeclaration of ‘template<unsigned int N, bool Destroy, bool Const> requires N >= 16 && is_power_2(std::size_t)(N) && Destroy && !Const class _uint’ with different constraints
I don't understand why I can't do this. My vision was that 'requires' statement is like a strict hint for a compiler that dictates which version of the class it should compile. So it shouldn't be bothered about how many declarations of the same class I have until it actually find a conflict, for example when two constraints satisfy one set of template arguments. Can someone explain me this, please?
I want not only to find out a work around but also why I need to do this. In referenced duplicate person doesn't explain why I need to use partial specialization in order to fix this. For me it still remains bizarre..