#if __cplusplus >= 201103L
#include <type_traits>
+#include <ext/numeric_traits.h>
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
namespace __detail
{
+#if __cpp_variable_templates
+ // This accepts 128-bit integers even in strict mode.
+ template<typename _Tp>
+ constexpr bool __integer_to_chars_is_unsigned
+ = ! __gnu_cxx::__int_traits<_Tp>::__is_signed;
+#endif
+
// Generic implementation for arbitrary bases.
template<typename _Tp>
_GLIBCXX14_CONSTEXPR unsigned
__to_chars_len(_Tp __value, int __base = 10) noexcept
{
- static_assert(is_integral<_Tp>::value, "implementation bug");
- static_assert(is_unsigned<_Tp>::value, "implementation bug");
+#if __cpp_variable_templates
+ static_assert(__integer_to_chars_is_unsigned<_Tp>, "implementation bug");
+#endif
unsigned __n = 1;
const unsigned __b2 = __base * __base;
_GLIBCXX23_CONSTEXPR void
__to_chars_10_impl(char* __first, unsigned __len, _Tp __val) noexcept
{
- static_assert(is_integral<_Tp>::value, "implementation bug");
- static_assert(is_unsigned<_Tp>::value, "implementation bug");
+#if __cpp_variable_templates
+ static_assert(__integer_to_chars_is_unsigned<_Tp>, "implementation bug");
+#endif
constexpr char __digits[201] =
"0001020304050607080910111213141516171819"
using __integer_to_chars_result_type
= enable_if_t<__or_<__is_signed_integer<_Tp>,
__is_unsigned_integer<_Tp>,
+#if defined __SIZEOF_INT128__ && defined __STRICT_ANSI__
+ is_same<_Tp, signed __int128>,
+ is_same<_Tp, unsigned __int128>,
+#endif
is_same<char, remove_cv_t<_Tp>>>::value,
to_chars_result>;
constexpr to_chars_result
__to_chars(char* __first, char* __last, _Tp __val, int __base) noexcept
{
- static_assert(is_integral<_Tp>::value, "implementation bug");
- static_assert(is_unsigned<_Tp>::value, "implementation bug");
+ static_assert(__integer_to_chars_is_unsigned<_Tp>, "implementation bug");
to_chars_result __res;
constexpr __integer_to_chars_result_type<_Tp>
__to_chars_16(char* __first, char* __last, _Tp __val) noexcept
{
- static_assert(is_integral<_Tp>::value, "implementation bug");
- static_assert(is_unsigned<_Tp>::value, "implementation bug");
+ static_assert(__integer_to_chars_is_unsigned<_Tp>, "implementation bug");
to_chars_result __res;
constexpr __integer_to_chars_result_type<_Tp>
__to_chars_10(char* __first, char* __last, _Tp __val) noexcept
{
- static_assert(is_integral<_Tp>::value, "implementation bug");
- static_assert(is_unsigned<_Tp>::value, "implementation bug");
+ static_assert(__integer_to_chars_is_unsigned<_Tp>, "implementation bug");
to_chars_result __res;
constexpr __integer_to_chars_result_type<_Tp>
__to_chars_8(char* __first, char* __last, _Tp __val) noexcept
{
- static_assert(is_integral<_Tp>::value, "implementation bug");
- static_assert(is_unsigned<_Tp>::value, "implementation bug");
+ static_assert(__integer_to_chars_is_unsigned<_Tp>, "implementation bug");
to_chars_result __res;
unsigned __len;
constexpr __integer_to_chars_result_type<_Tp>
__to_chars_2(char* __first, char* __last, _Tp __val) noexcept
{
- static_assert(is_integral<_Tp>::value, "implementation bug");
- static_assert(is_unsigned<_Tp>::value, "implementation bug");
+ static_assert(__integer_to_chars_is_unsigned<_Tp>, "implementation bug");
to_chars_result __res;