F
Frederick Gotham
I'm writing a template, and I need to know the maximum value of a given
integer type at compile time. something like:
template<class NumType>
class Arb {
public:
static NumType const max = /* maximum value */;
};
If the template were only to be used with unsigned integer types, then
I'd do the following:
template<class NumType>
class Arb {
public:
static NumType const max = -1;
};
I need a compile-time constant which evaluates to the maximum value of an
integer type.
Any ideas?
If it weren't undefined behaviour to overflow a signed integer, I could
use a metaprogramming technique such as the following:
template<class T, bool overflow = false>
struct MaxIntVal {
private:
static T const internal = 1 + MaxIntVal<T,...
public:
static T const val = SCHAR_MAX + internal;
};
integer type at compile time. something like:
template<class NumType>
class Arb {
public:
static NumType const max = /* maximum value */;
};
If the template were only to be used with unsigned integer types, then
I'd do the following:
template<class NumType>
class Arb {
public:
static NumType const max = -1;
};
I need a compile-time constant which evaluates to the maximum value of an
integer type.
Any ideas?
If it weren't undefined behaviour to overflow a signed integer, I could
use a metaprogramming technique such as the following:
template<class T, bool overflow = false>
struct MaxIntVal {
private:
static T const internal = 1 + MaxIntVal<T,...
public:
static T const val = SCHAR_MAX + internal;
};