Exemplo n.º 1
0
bool ParseNumberT(const char* str, T* value, char** endptr, int base)
{
    TOFT_STATIC_ASSERT(std::is_signed<T>::value ==
                       std::is_signed<IntermediaType>::value);
    TOFT_STATIC_ASSERT(sizeof(T) <= sizeof(IntermediaType));

    char* tmp_endptr;
    if (endptr == NULL) // Allow NULL endptr
        endptr = &tmp_endptr;

    int old_errno = errno;
    errno = 0;
    IntermediaType number = StringToNumber<IntermediaType>::Convert(str, endptr, base);
    if (errno != 0)
        return false;

    if (sizeof(T) < sizeof(IntermediaType) &&
        (number > std::numeric_limits<T>::max() || number < std::numeric_limits<T>::min()))
    {
        errno = ERANGE;
        return false;
    }

    if (*endptr == str)
    {
        errno = EINVAL;
        return false;
    }

    errno = old_errno;
    *value = static_cast<T>(number);
    return true;
}
Exemplo n.º 2
0
TEST(StaticAssert, NoCompileTest)
{
#if 0 // uncomment to test
    TOFT_STATIC_ASSERT(false);
    TOFT_STATIC_ASSERT(1 == 2);
    TOFT_STATIC_ASSERT(1 == 2, "1 == 2");
#endif
}
Exemplo n.º 3
0
TEST(StaticAssert, Test)
{
    TOFT_STATIC_ASSERT(1 == 1);
    TOFT_STATIC_ASSERT(1 == 1, "1 should be equal to 1");
}