Этот код:
template<class Int_T, long long Min, unsigned long long Max>
class Int_Core
{
static_assert(Check_Range<Minimum>::check(Min,std::numeric_limits<Int_T>::min()),"INCORRECT Min range.");
static_assert(Check_Range<Maximum>::check(Max,std::numeric_limits<Int_T>::max()),"INCORRECT Max range.");
}
Ошибка, которую я получаю, находится на втором static_assert, сообщающем, что использовалось неконстантное выражение. Но Если я изменю 'Макс' на 'Мин' в этом втором утверждении, оно скомпилируется без проблем. Что происходит?
Ошибка:
ошибка: непостоянное условие для статического утверждения
Это вспомогательные классы / fncs:
//this is Int_Core.h file
struct Minimum
{/*eb*/};
struct Maximum
{/*eb*/};
/**Checks if given range is within boundary*/
template<class Range>
struct Check_Range;
template<>
struct Check_Range<Minimum>
{
template<class Value,class Limit>
static constexpr bool check(Value val,Limit limit)
{
return greater_than_or_equal_with(val,limit);
}
};
template<>
struct Check_Range<Maximum>
{
template<class Value,class Limit>
static constexpr bool check(Value val,Limit limit)
{
return greater_than_or_equal_with(val,limit);
}
};
constexpr bool greater_than(long long signed_,unsigned long long unsigned_)
{
// unsigned long long mask = 0x8000000000000000LL;
// bool is_negative = signed_ & mask;
// if (is_negative)
// {
//
// return false;
// }
// else
// {
// return (signed_ > unsigned_);
// }
//
return (signed_ & 0x8000000000000000LL) ? false : (signed_ > unsigned_);
}
constexpr bool equal_with(long long signed_,unsigned long long unsigned_)
{
// unsigned long long mask = 0x8000000000000000LL;
// bool is_negative = signed_ & mask;
// if (is_negative)
// {
//
// return false;
// }
// else
// {
// return (signed_ == unsigned_);
// }
//This line is == to the commented code above (constexpr must have just return statement)
return (signed_ & 0x8000000000000000LL) ? false : (signed_ == unsigned_);
}
constexpr bool greater_than_or_equal_with(long long signed_,unsigned long long unsigned_)
{
return (greater_than(signed_,unsigned_) || equal_with(signed_,unsigned_));
}
Обновление:
#include "Int_Core.h"
int main()
{
Int_Core<unsigned char,1,-50> a;
}