I have few classes that look like this:
struct neg_inf {
constexpr double operator()() { return -std::numeric_limits<double>::infinity(); }
};
struct pos_inf {
constexpr double operator()() { return std::numeric_limits<double>::infinity(); }
};
template<typename dX, class LowerBound, class UpperBound>
class limit {
dX dx;
UpperBound upperBound;
LowerBound lowerBound;
double step_size;
limit( dX x, LowerBound lower, UpperBound upper, double step = 1 ) :
dx{ x }, lowerBound{ lower }, upperBound{ upper }, step_size{ step }
{}
dX value() const { return dx; }
LowerBound lower() const { return lowerBound; }
UpperBound upper() const { return upperBound; }
double step() const { return step_size; }
};
These classes so far work as intended. Now I want to modify the template arguments using conditionals such as std::enable_if_t, std::is_arithemtic std::is_same.
These are the conditions that need to be met to instantiate a limit object.
dXmust be at leastarithmeticandnumericalLower&Upperboundmust be eithernumerical,arithmeticorneg_inforpos_inf.
For example these are valid instantiations:
dX = 1st and can be any: int, long, float, double, /*complex*/, etc.
limit< 1st, 1st, 1st > // default template
limit< 1st, 1st, pos_inf > // these will be specializations
limit< 1st, 1st, neg_inf >
limit< 1st, pos_inf, 1st >
limit< 1st, neg_inf, 1st >
limit< 1st, pos_inf, pos_inf >
limit< 1st, neg_inf, neg_inf >
limit< 1st, neg_inf, pos_inf >
limit< 1st, pos_inf, neg_inf >
These are the valid conditions for instantiating my template. I am planning on partially specializing this class when either or both UpperBound and or LowerBound are an infinity type. When the upper and lower bounds are numerical - arithmetic types, the general or default template will handle them.
My question is what would the template declaration to my class look like with the type_traits library?