You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
445 B
C++
21 lines
445 B
C++
3 years ago
|
#include <cstdlib>
|
||
|
#include <climits>
|
||
|
|
||
|
namespace Util
|
||
|
{
|
||
|
bool strtol(const char* nptr, long& n)
|
||
|
{
|
||
|
if (!nptr || *nptr == '\0')
|
||
|
return false;
|
||
|
char* endptr = nullptr;
|
||
|
long tmp = std::strtol(nptr, &endptr, 10);
|
||
|
if (*endptr != '\0')
|
||
|
return false;
|
||
|
if (tmp == LONG_MAX || tmp == LONG_MIN)
|
||
|
return false;
|
||
|
n = tmp;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
} // namespace Util
|