Skip to content

Commit

Permalink
Merge branch 'work' into tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oktonion committed Mar 13, 2024
2 parents 6c55811 + 222d083 commit 7289c6a
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 44 deletions.
13 changes: 6 additions & 7 deletions stdex/include/cstdint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,13 @@ namespace stdex
{ };

template<class _Tp>
struct _is_integral_constant:
_is_integral_constant_impl<_Tp,
_is_integral_constant_std_impl<unsigned short>::value == bool(true)
&& _is_integral_constant_std_impl<long>::value == bool(true)
&& _is_integral_constant_std_impl<signed char>::value == bool(true)
>
struct _is_integral_constant
{

static const bool flag =
(_is_integral_constant_std_impl<unsigned short>::value == bool(true)
&& _is_integral_constant_std_impl<long>::value == bool(true)
&& _is_integral_constant_std_impl<signed char>::value == bool(true));
static const bool value = _is_integral_constant_impl<_Tp, flag>::value;
};

template<class _Tp>
Expand Down
19 changes: 9 additions & 10 deletions stdex/include/nullptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,10 @@ namespace stdex
static const bool _equal_void_ptr = _is_equal_size_to_void_ptr<_nullptr_t_as_integral>::value;
static const bool _can_be_compared_to_ptr = _nullptr_t_can_be_compared_to_ptr<_nullptr_t_as_integral>::value;
};

typedef _nullptr_choose_as_int<
static const bool _nullptr_choose_as_int_flag =
(nullptr_detail::_NULL_is_convertable_to_int::value == bool(true)) &&
(_as_int::_is_convertable_to_ptr == bool(true) && _as_int::_equal_void_ptr == bool(true) && _as_int::_can_be_compared_to_ptr == bool(true))
>::type type;
(_as_int::_is_convertable_to_ptr == bool(true) && _as_int::_equal_void_ptr == bool(true) && _as_int::_can_be_compared_to_ptr == bool(true));
typedef _nullptr_choose_as_int< _nullptr_choose_as_int_flag >::type type;
};

template<>
Expand All @@ -420,10 +419,10 @@ namespace stdex
static const bool _equal_void_ptr = _is_equal_size_to_void_ptr<_nullptr_t_as_enum>::value;
static const bool _can_be_ct_constant = true;//_nullptr_can_be_ct_constant_impl<_nullptr_t_as_enum>::value;
};
static const bool _nullptr_choose_as_enum_flag =
(_as_enum::_is_convertable_to_ptr == bool(true) && _as_enum::_equal_void_ptr == bool(true) && _as_enum::_can_be_ct_constant == bool(true));

typedef _nullptr_choose_as_enum<
(_as_enum::_is_convertable_to_ptr == bool(true) && _as_enum::_equal_void_ptr == bool(true) && _as_enum::_can_be_ct_constant == bool(true))
>::type type;
typedef _nullptr_choose_as_enum< _nullptr_choose_as_enum_flag >::type type;
};

struct _nullptr_chooser
Expand All @@ -437,10 +436,10 @@ namespace stdex
static const bool _equal_void_ptr = _is_equal_size_to_void_ptr<_nullptr_t_as_class>::value;
static const bool _can_be_ct_constant = _nullptr_can_be_ct_constant_impl<_nullptr_t_as_class>::value;
};
static const bool _nullptr_choose_as_class_flag =
(_as_class::_equal_void_ptr == bool(true) && _as_class::_can_be_ct_constant == bool(true));

typedef _nullptr_choose_as_class<
(_as_class::_equal_void_ptr == bool(true) && _as_class::_can_be_ct_constant == bool(true))
>::type type;
typedef _nullptr_choose_as_class< _nullptr_choose_as_class_flag >::type type;
};
} // namespace detail

Expand Down
61 changes: 38 additions & 23 deletions stdex/include/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@
#include <cstddef> // std::size_t
#include <iomanip> // std::setbase

#ifdef max
#define _STDEX_NUMERIC_LIMITS_MAX(T) (std::numeric_limits<T>::max)()
#else
#define _STDEX_NUMERIC_LIMITS_MAX(T) std::numeric_limits<T>::max()
#endif
#ifdef min
#define _STDEX_NUMERIC_LIMITS_MIN(T) (std::numeric_limits<T>::min)()
#else
#define _STDEX_NUMERIC_LIMITS_MIN(T) std::numeric_limits<T>::min()
#endif

namespace stdex
{
namespace cstddef
Expand Down Expand Up @@ -209,7 +220,7 @@ namespace stdex
unsigned long int uvalue = strtoul(positive_str.c_str(), NULL, base);
unsigned long int _zero = 0;

if(errno == 0 && uvalue > static_cast<unsigned long int>(is_negative ? _zero - (numeric_limits<long int>::min)() : (numeric_limits<long int>::max)() ))
if(errno == 0 && uvalue > static_cast<unsigned long int>(is_negative ? _zero - _STDEX_NUMERIC_LIMITS_MIN(long int) : _STDEX_NUMERIC_LIMITS_MAX(long int) ))
errno = ERANGE;// using errno is bad - m'kay?
}

Expand Down Expand Up @@ -255,7 +266,7 @@ namespace stdex
unsigned long int uvalue = wcstoul(positive_str.c_str(), NULL, base);
unsigned long int _zero = 0;

if(errno == 0 && uvalue > static_cast<unsigned long int>(is_negative ? _zero - (numeric_limits<long int>::min)() : (numeric_limits<long int>::max)() ))
if(errno == 0 && uvalue > static_cast<unsigned long int>(is_negative ? _zero - _STDEX_NUMERIC_LIMITS_MIN(long int) : _STDEX_NUMERIC_LIMITS_MAX(long int) ))
errno = ERANGE;// using errno is bad - m'kay?
}

Expand Down Expand Up @@ -285,7 +296,7 @@ namespace stdex
#ifdef LONG_MIN
return ((_value == -LONG_MIN || _value == LONG_MIN));
#else
return ((_value == (std::numeric_limits<long int>::min)() || _value == (std::numeric_limits<long int>::max)()));
return ((_value == _STDEX_NUMERIC_LIMITS_MIN(long int) || _value == _STDEX_NUMERIC_LIMITS_MAX(long int)));
#endif
#endif
}
Expand Down Expand Up @@ -467,7 +478,7 @@ namespace stdex
#ifdef ULONG_MAX
return ((_value == ULONG_MAX));
#else
return ((_value == (std::numeric_limits<unsigned long int>::max)()));
return ((_value == _STDEX_NUMERIC_LIMITS_MAX(unsigned long int)));
#endif
}
};
Expand Down Expand Up @@ -529,7 +540,7 @@ namespace stdex
template<class _Tp>
struct _infinity_impl<_Tp, false>
{
static _Tp inf() { return (std::numeric_limits<_Tp>::max)(); }
static _Tp inf() { return _STDEX_NUMERIC_LIMITS_MAX(_Tp); }
};

template<class _Tp>
Expand Down Expand Up @@ -950,7 +961,7 @@ namespace stdex
#ifdef LLONG_MIN
return ((_value == -LLONG_MIN || _value == LLONG_MIN));
#else
return ((_value == (std::numeric_limits<string_detail::_long_long_type>::min)() || _value == (std::numeric_limits<string_detail::_long_long_type>::max)()));
return ((_value == _STDEX_NUMERIC_LIMITS_MIN(string_detail::_long_long_type) || _value == _STDEX_NUMERIC_LIMITS_MAX(string_detail::_long_long_type)));
#endif
#endif
}
Expand Down Expand Up @@ -979,7 +990,7 @@ namespace stdex
#ifdef ULLONG_MAX
return ((_value == ULLONG_MAX));
#else
return ((_value == (std::numeric_limits<string_detail::_unsigned_long_long_type>::max)()));
return ((_value == _STDEX_NUMERIC_LIMITS_MAX(string_detail::_unsigned_long_long_type)));
#endif
}
};
Expand Down Expand Up @@ -1023,9 +1034,9 @@ namespace stdex

if (_str_to_integral::check(_value) && errno == ERANGE)
num_s_end = 0;
else if (_value > static_cast<large_value_type>((std::numeric_limits<_Tp>::max)()) || _value < static_cast<large_value_type>((std::numeric_limits<_Tp>::min)()))
else if (_value > static_cast<large_value_type>(_STDEX_NUMERIC_LIMITS_MAX(_Tp)) || _value < static_cast<large_value_type>(_STDEX_NUMERIC_LIMITS_MIN(_Tp)))
{
_value = (std::numeric_limits<_Tp>::max)();
_value = _STDEX_NUMERIC_LIMITS_MAX(_Tp);
num_s_end = 0;
}
else
Expand All @@ -1050,9 +1061,9 @@ namespace stdex

if (_str_to_integral::check(_value) && errno == ERANGE)
num_s_end = 0;
else if (_value > static_cast<large_value_type>((std::numeric_limits<_Tp>::max)()) || _value < static_cast<large_value_type>((std::numeric_limits<_Tp>::min)()))
else if (_value > static_cast<large_value_type>(_STDEX_NUMERIC_LIMITS_MAX(_Tp)) || _value < static_cast<large_value_type>(_STDEX_NUMERIC_LIMITS_MIN(_Tp)))
{
_value = (std::numeric_limits<_Tp>::max)();
_value = _STDEX_NUMERIC_LIMITS_MAX(_Tp);
num_s_end = 0;
}
else
Expand All @@ -1078,9 +1089,9 @@ namespace stdex

if (_str_to_integral::check(_value) && errno == ERANGE)
num_s_end = 0;
else if (_value > static_cast<large_value_type>((std::numeric_limits<_Tp>::max)()) || _value < static_cast<large_value_type>((std::numeric_limits<_Tp>::min)()))
else if (_value > static_cast<large_value_type>(_STDEX_NUMERIC_LIMITS_MAX(_Tp)) || _value < static_cast<large_value_type>(_STDEX_NUMERIC_LIMITS_MIN(_Tp)))
{
_value = (std::numeric_limits<_Tp>::max)();
_value = _STDEX_NUMERIC_LIMITS_MAX(_Tp);
num_s_end = 0;
}
else
Expand All @@ -1105,9 +1116,9 @@ namespace stdex

if (_str_to_integral::check(_value) && errno == ERANGE)
num_s_end = 0;
else if (_value > static_cast<large_value_type>((std::numeric_limits<_Tp>::max)()) || _value < static_cast<large_value_type>((std::numeric_limits<_Tp>::min)()))
else if (_value > static_cast<large_value_type>(_STDEX_NUMERIC_LIMITS_MAX(_Tp)) || _value < static_cast<large_value_type>(_STDEX_NUMERIC_LIMITS_MIN(_Tp)))
{
_value = (std::numeric_limits<_Tp>::max)();
_value = _STDEX_NUMERIC_LIMITS_MAX(_Tp);
num_s_end = 0;
}
else
Expand Down Expand Up @@ -1136,9 +1147,9 @@ namespace stdex
if (errno == ERANGE)
#endif
num_s_end = 0;
else if (_value > static_cast<double>((std::numeric_limits<_Tp>::max)()) || _value < static_cast<double>(-(std::numeric_limits<_Tp>::max)()))
else if (_value > static_cast<double>(_STDEX_NUMERIC_LIMITS_MAX(_Tp)) || _value < static_cast<double>(-_STDEX_NUMERIC_LIMITS_MAX(_Tp)))
{
_value = (std::numeric_limits<_Tp>::max)();
_value = _STDEX_NUMERIC_LIMITS_MAX(_Tp);
num_s_end = 0;
}
else
Expand Down Expand Up @@ -1166,9 +1177,9 @@ namespace stdex
if (errno == ERANGE)
#endif
num_s_end = 0;
else if (_value > static_cast<double>((std::numeric_limits<_Tp>::max)()) || _value < static_cast<double>(-(std::numeric_limits<_Tp>::max)()))
else if (_value > static_cast<double>(_STDEX_NUMERIC_LIMITS_MAX(_Tp)) || _value < static_cast<double>(-_STDEX_NUMERIC_LIMITS_MAX(_Tp)))
{
_value = (std::numeric_limits<_Tp>::max)();
_value = _STDEX_NUMERIC_LIMITS_MAX(_Tp);
num_s_end = 0;
}
else
Expand Down Expand Up @@ -1274,7 +1285,7 @@ namespace stdex
value = fp_integer_part + fp_fractional_part;
}

if(value > (numeric_limits<long double>::max)() || value < (numeric_limits<long double>::min)())
if(value > _STDEX_NUMERIC_LIMITS_MAX(long double) || value < _STDEX_NUMERIC_LIMITS_MIN(long double))
{
errno = ERANGE;
value = 0.0;
Expand Down Expand Up @@ -1316,7 +1327,7 @@ namespace stdex
value = fp_integer_part + fp_fractional_part;
}

if (value > (numeric_limits<long double>::max)() || value < (numeric_limits<long double>::min)())
if (value > _STDEX_NUMERIC_LIMITS_MAX(long double) || value < _STDEX_NUMERIC_LIMITS_MIN(long double))
{
errno = ERANGE;
value = 0.0;
Expand Down Expand Up @@ -1411,7 +1422,7 @@ namespace stdex
if (std::numeric_limits<long double>::max_exponent10 < _i)
{
errno = ERANGE;
return (std::numeric_limits<long double>::max)();
return _STDEX_NUMERIC_LIMITS_MAX(long double);
}
return _a_to_floating_point(_str);
}
Expand Down Expand Up @@ -1510,7 +1521,7 @@ namespace stdex
if (std::numeric_limits<long double>::max_exponent10 < _i)
{
errno = ERANGE;
return (std::numeric_limits<long double>::max)();
return _STDEX_NUMERIC_LIMITS_MAX(long double);
}
return _a_to_floating_point(_str);
}
Expand Down Expand Up @@ -2414,4 +2425,8 @@ namespace stdex

}


#undef _STDEX_NUMERIC_LIMITS_MAX
#undef _STDEX_NUMERIC_LIMITS_MIN

#endif // _STDEX_STRING_H
29 changes: 25 additions & 4 deletions stdex/include/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -949,13 +949,34 @@ _STDEX_MSVC_SUPPRESS_WARNING_POP // warning C4180
{ };

template<class _Tp>
struct _arr_is_incomplete_type:
_is_incomplete_type<_Tp[]>
{ };
_Tp* _arr_is_incomplete_type_tester_helper(_Tp(*)[]);

template<class _Tp>
void* _arr_is_incomplete_type_tester_helper(...);

template<class _Tp>
_no_type _arr_is_incomplete_type_tester(_Tp*);

_yes_type _arr_is_incomplete_type_tester(...);

template<class _Tp>
struct _arr_is_incomplete_type
//_is_incomplete_type<_Tp[]>
{

static const bool value =
sizeof( _arr_is_incomplete_type_tester(_arr_is_incomplete_type_tester_helper<_Tp>(0)) )
== sizeof(_yes_type);
};

template<class _Tp>
struct _arr_is_incomplete_type<_Tp&>:
_is_incomplete_type<_Tp[]>
_arr_is_incomplete_type<_Tp>
{ };

template<>
struct _arr_is_incomplete_type<void>:
_is_incomplete_type<void>
{ };

template<>
Expand Down

0 comments on commit 7289c6a

Please sign in to comment.