On Mar 11, 10:15 pm, David Johansen <davejohan...@gmail.com> wrote:
On Mar 11, 12:22 pm, SG <s.gesem...@gmail.com> wrote:
On 11 Mrz., 19:46, Dave Johansen <davejohan...@gmail.com> wrote:
Is it possible to specialized numeric_limits with a templated type?
Sure.
template<unsigned int DIGITS>
class BigInt;
template<unsigned int DIGITS>
class std::numeric_limits<BigInt<DIGITS> >
{
// ...
};
Thanks for the tip because it worked, but I guess I'm missing
something and I don't get how/why this works. Is the syntax
for a explicit specialization of a class when using a
templated typed different? Or is something else going on that
I'm not realizing?
Because if I do something like this:
class test
{
};
class std::numeric_limits<test>
{
};
Then it doesn't compile without the "template<>", so what am I
not getting?
In order to explicitly specialize a template with a single type
parameter (like std::numeric_limits), you need a type. A class
is a type; a class template is *not*. What SG provided is not
an explicit specialization, but a partial specialization,
something different, which obeys different rules. You could
also use an explicit specialization (using template<>), but only
for a specific type, e.g.:
template<>
class std::numeric_limits< BigInt< 200 > >
{
// ...
} ;
SG's suggestion, using partial specialization, is probably what
you want, however.
UB. Is that not the case and specialising is permitted or is this an