apply constexpr if

This commit is contained in:
Jinhao
2017-12-18 22:13:03 +08:00
parent 1e551f4e55
commit 486e75f3ae
3 changed files with 106 additions and 5 deletions

View File

@@ -82,10 +82,39 @@ namespace nana
bool check_value(const std::string& str) const override
{
#ifdef _nana_cxx_constexpr_if
auto i = str.c_str();
if ('+' == *i || '-' == *i)
++i;
if constexpr(std::is_same<T, int>::value)
{
for (; 0 != *i; ++i)
{
if (*i < '0' || '9' < *i)
return false;
}
}
else
{
bool dot = false;
for (; 0 != *i; ++i)
{
if (('.' == *i) && (!dot))
{
dot = true;
continue;
}
if (*i < '0' || '9' < *i)
return false;
}
}
#else
if (str.empty())
return true;
auto size = str.size();
auto const size = str.size();
std::size_t pos = 0;
if (str[0] == '+' || str[0] == '-')
pos = 1;
@@ -115,6 +144,7 @@ namespace nana
return false;
}
}
#endif
return true;
}