#pragma once
#ifndef _STRING_
#define _STRING_
#ifndef RC_INVOKED
#include <istream>
#include <xstring_insert.h>
#if _HAS_CXX17
#include <xpolymorphic_allocator.h>
#endif /* _HAS_CXX17 */
#pragma pack(push,_CRT_PACKING)
#pragma warning(push,_STL_WARNING_LEVEL)
#pragma warning(disable: _STL_DISABLED_WARNINGS)
#pragma warning(disable:
4455
4494
4619
4643
4702
4984
4988
)
_STL_DISABLE_CLANG_WARNINGS
#pragma push_macro("new")
#undef new
template
<
class
,
class
,
class
>
inline
<
,
>&
(
<
,
>&&
,
<
,
,
>&
)
{
typedef
<
>
;
typedef
<
,
>
;
typedef
<
,
,
>
;
typedef
typename
::
;
::
=
::
;
bool
=
false
;
const
typename
::
(
);
if
(
_Ok
)
{
const _Ctype& _Ctype_fac = _STD use_facet<_Ctype>(_Istr.getloc());
const
&
= ::
std
::
<
>(
.
());
.
();
=
0
<
.
()
&& (
)
.
() <
.
()
? (
)
.
() :
.
();
typename
::int_type
=
.
()->sgetc();
for
(;
0
_Size
; --
_Size
,
_Meta
=
.
()->snextc())
if
(
::eq_int_type(
::eof(),
_Meta
))
{
_State
|=
::
;
break
;
}
else
if
(
_Ctype_fac
.
(
::
,
::to_char_type(
_Meta
)))
break
;
else
{
.
(
::to_char_type(
_Meta
));
_Changed
=
true
;
}
_CATCH_IO_(_Istr)
}
catch
(...) { (
).
(
::
,
true
); }
}
.
(
0
);
if
(!
_Changed
)
_State
|=
::
;
.
(
_State
);
return
(
);
}
template
<
class
,
class
,
class
>
inline
<
,
>&
(
<
,
>&&
,
<
,
,
>&
,
const
)
{
typedef
<
,
>
;
::
=
::
;
bool
=
false
;
const
typename
::
(
,
true
);
if
(
_Ok
)
{
.
();
const
typename
::int_type
=
::to_int_type(
);
typename
::int_type
=
.
()->sgetc();
for
(; ;
_Meta
=
.
()->snextc())
if
(
::eq_int_type(
::eof(),
_Meta
))
{
_State
|=
::
;
break
;
}
else
if
(
::eq_int_type(
_Meta
,
_Metadelim
))
{
_Changed
=
true
;
.
()->sbumpc();
break
;
}
else
if
(
.
() <=
.
())
{
_State
|=
::
;
break
;
}
else
{
+=
::to_char_type(
_Meta
);
_Changed
=
true
;
}
_CATCH_IO_(_Istr)
}
catch
(...) { (
).
(
::
,
true
); }
}
if
(!
_Changed
)
_State
|=
::
;
.
(
_State
);
return
(
);
}
template
<
class
,
class
,
class
>
inline
<
,
>&
(
<
,
>&&
,
<
,
,
>&
)
{
return
(
(
,
,
.
(
'\n'
)));
}
template
<
class
,
class
,
class
>
inline
<
,
>&
(
<
,
>&
,
<
,
,
>&
)
{
return (_STD move(_Istr) >> _Str);
}
template
<
class
,
class
,
class
>
inline
<
,
>&
(
<
,
>&
,
<
,
,
>&
,
const
)
{
return (getline(_STD move(_Istr), _Str, _Delim));
return
(
(::
std
::
(
),
,
));
}
template
<
class
,
class
,
class
>
inline
<
,
>&
(
<
,
>&
,
<
,
,
>&
)
{
return (getline(_STD move(_Istr), _Str, _Istr.widen('\n')));
return
(
(::
std
::
(
),
,
.
(
'\n'
)));
}
template
<
class
,
class
,
class
>
inline
<
,
>&
(
<
,
>&
,
const
<
,
,
>&
)
{
return
(
(
,
.
(),
.
()));
}
inline
int
(
const
&
,
*
=
nullptr
,
int
=
10
)
{
int& _Errno_ref = errno; // Nonzero cost, pay it once
const
char
*
=
.
();
char
*
;
_Errno_ref
=
0
;
const long _Ans = _CSTD strtol(_Ptr, &_Eptr, _Base);
const
long
= ::
(
_Ptr
, &
_Eptr
,
);
if
(
_Ptr
_Eptr
)
(
"invalid stoi argument"
);
if (_Errno_ref == ERANGE || _Ans < INT_MIN || INT_MAX < _Ans)
if
(
_Errno_ref
34
||
_Ans
(-
2147483647
-
1
) ||
2147483647
_Ans
)
(
"stoi argument out of range"
);
if
(
!=
nullptr
)
*
= (
)(
_Eptr
-
_Ptr
);
return
((
int
)
_Ans
);
}
inline
long
(
const
&
,
*
=
nullptr
,
int
=
10
)
{
int& _Errno_ref = errno; // Nonzero cost, pay it once
const
char
*
=
.
();
char
*
;
_Errno_ref
=
0
;
const long _Ans = _CSTD strtol(_Ptr, &_Eptr, _Base);
const
long
= ::
(
_Ptr
, &
_Eptr
,
);
if
(
_Ptr
_Eptr
)
(
"invalid stol argument"
);
if (_Errno_ref == ERANGE)
(
"stol argument out of range"
);
if
(
!=
nullptr
)
*
= (
)(
_Eptr
-
_Ptr
);
return
(
_Ans
);
}
inline
unsigned
long
(
const
&
,
*
=
nullptr
,
int
=
10
)
{
int& _Errno_ref = errno; // Nonzero cost, pay it once
const
char
*
=
.
();
char
*
;
_Errno_ref
=
0
;
const unsigned long _Ans = _CSTD strtoul(_Ptr, &_Eptr, _Base);
const
unsigned
long
= ::
(
_Ptr
, &
_Eptr
,
);
if
(
_Ptr
_Eptr
)
(
"invalid stoul argument"
);
if (_Errno_ref == ERANGE)
(
"stoul argument out of range"
);
if
(
!=
nullptr
)
*
= (
)(
_Eptr
-
_Ptr
);
return
(
_Ans
);
}
inline
long
long
(
const
&
,
*
=
nullptr
,
int
=
10
)
{
int& _Errno_ref = errno; // Nonzero cost, pay it once
const
char
*
=
.
();
char
*
;
_Errno_ref
=
0
;
const long long _Ans = _CSTD strtoll(_Ptr, &_Eptr, _Base);
const
long
long
= ::
(
_Ptr
, &
_Eptr
,
);
if
(
_Ptr
_Eptr
)
(
"invalid stoll argument"
);
if (_Errno_ref == ERANGE)
(
"stoll argument out of range"
);
if
(
!=
nullptr
)
*
= (
)(
_Eptr
-
_Ptr
);
return
(
_Ans
);
}
inline
unsigned
long
long
(
const
&
,
*
=
nullptr
,
int
=
10
)
{
int& _Errno_ref = errno; // Nonzero cost, pay it once
const
char
*
=
.
();
char
*
;
_Errno_ref
=
0
;
const unsigned long long _Ans = _CSTD strtoull(_Ptr, &_Eptr, _Base);
const
unsigned
long
long
= ::
(
_Ptr
, &
_Eptr
,
);
if
(
_Ptr
_Eptr
)
(
"invalid stoull argument"
);
if (_Errno_ref == ERANGE)
(
"stoull argument out of range"
);
if
(
!=
nullptr
)
*
= (
)(
_Eptr
-
_Ptr
);
return
(
_Ans
);
}
inline
float
(
const
&
,
*
=
nullptr
)
{
int& _Errno_ref = errno; // Nonzero cost, pay it once
const
char
*
=
.
();
char
*
;
_Errno_ref
=
0
;
const float _Ans = _CSTD strtof(_Ptr, &_Eptr);
const
float
= ::
(
_Ptr
, &
_Eptr
);
if
(
_Ptr
_Eptr
)
(
"invalid stof argument"
);
if (_Errno_ref == ERANGE)
(
"stof argument out of range"
);
if
(
!=
nullptr
)
*
= (
)(
_Eptr
-
_Ptr
);
return
(
_Ans
);
}
inline
double
(
const
&
,
*
=
nullptr
)
{
int& _Errno_ref = errno; // Nonzero cost, pay it once
const
char
*
=
.
();
char
*
;
_Errno_ref
=
0
;
const double _Ans = _CSTD strtod(_Ptr, &_Eptr);
const
double
= ::
(
_Ptr
, &
_Eptr
);
if
(
_Ptr
_Eptr
)
(
"invalid stod argument"
);
if (_Errno_ref == ERANGE)
(
"stod argument out of range"
);
if
(
!=
nullptr
)
*
= (
)(
_Eptr
-
_Ptr
);
return
(
_Ans
);
}
inline
long
double
(
const
&
,
*
=
nullptr
)
{
int& _Errno_ref = errno; // Nonzero cost, pay it once
const
char
*
=
.
();
char
*
;
_Errno_ref
=
0
;
const long double _Ans = _CSTD strtold(_Ptr, &_Eptr);
const
long
double
= ::
(
_Ptr
, &
_Eptr
);
if
(
_Ptr
_Eptr
)
(
"invalid stold argument"
);
if (_Errno_ref == ERANGE)
(
"stold argument out of range"
);
if
(
!=
nullptr
)
*
= (
)(
_Eptr
-
_Ptr
);
return
(
_Ans
);
}
inline
int
(
const
&
,
*
=
nullptr
,
int
=
10
)
{
int& _Errno_ref = errno; // Nonzero cost, pay it once
const
wchar_t
*
=
.
();
wchar_t
*
;
_Errno_ref
=
0
;
const long _Ans = _CSTD wcstol(_Ptr, &_Eptr, _Base);
const
long
= ::
(
_Ptr
, &
_Eptr
,
);
if
(
_Ptr
_Eptr
)
(
"invalid stoi argument"
);
if (_Errno_ref == ERANGE || _Ans < INT_MIN || INT_MAX < _Ans)
if
(
_Errno_ref
34
||
_Ans
(-
2147483647
-
1
) ||
2147483647
_Ans
)
(
"stoi argument out of range"
);
if
(
!=
nullptr
)
*
= (
)(
_Eptr
-
_Ptr
);
return
((
int
)
_Ans
);
}
inline
long
(
const
&
,
*
=
nullptr
,
int
=
10
)
{
int& _Errno_ref = errno; // Nonzero cost, pay it once
const
wchar_t
*
=
.
();
wchar_t
*
;
_Errno_ref
=
0
;
const long _Ans = _CSTD wcstol(_Ptr, &_Eptr, _Base);
const
long
= ::
(
_Ptr
, &
_Eptr
,
);
if
(
_Ptr
_Eptr
)
(
"invalid stol argument"
);
if (_Errno_ref == ERANGE)
(
"stol argument out of range"
);
if
(
!=
nullptr
)
*
= (
)(
_Eptr
-
_Ptr
);
return
(
_Ans
);
}
inline
unsigned
long
(
const
&
,
*
=
nullptr
,
int
=
10
)
{
int& _Errno_ref = errno; // Nonzero cost, pay it once
const
wchar_t
*
=
.
();
wchar_t
*
;
_Errno_ref
=
0
;
const unsigned long _Ans = _CSTD wcstoul(_Ptr, &_Eptr, _Base);
const
unsigned
long
= ::
(
_Ptr
, &
_Eptr
,
);
if
(
_Ptr
_Eptr
)
(
"invalid stoul argument"
);
if (_Errno_ref == ERANGE)
(
"stoul argument out of range"
);
if
(
!=
nullptr
)
*
= (
)(
_Eptr
-
_Ptr
);
return
(
_Ans
);
}
inline
long
long
(
const
&
,
*
=
nullptr
,
int
=
10
)
{
int& _Errno_ref = errno; // Nonzero cost, pay it once
const
wchar_t
*
=
.
();
wchar_t
*
;
_Errno_ref
=
0
;
const long long _Ans = _CSTD wcstoll(_Ptr, &_Eptr, _Base);
const
long
long
= ::
(
_Ptr
, &
_Eptr
,
);
if
(
_Ptr
_Eptr
)
(
"invalid stoll argument"
);
if (_Errno_ref == ERANGE)
(
"stoll argument out of range"
);
if
(
!=
nullptr
)
*
= (
)(
_Eptr
-
_Ptr
);
return
(
_Ans
);
}
inline
unsigned
long
long
(
const
&
,
*
=
nullptr
,
int
=
10
)
{
int& _Errno_ref = errno; // Nonzero cost, pay it once
const
wchar_t
*
=
.
();
wchar_t
*
;
_Errno_ref
=
0
;
const unsigned long long _Ans = _CSTD wcstoull(_Ptr, &_Eptr, _Base);
const
unsigned
long
long
= ::
(
_Ptr
, &
_Eptr
,
);
if
(
_Ptr
_Eptr
)
(
"invalid stoull argument"
);
if (_Errno_ref == ERANGE)
(
"stoull argument out of range"
);
if
(
!=
nullptr
)
*
= (
)(
_Eptr
-
_Ptr
);
return
(
_Ans
);
}
inline
float
(
const
&
,
*
=
nullptr
)
{
int& _Errno_ref = errno; // Nonzero cost, pay it once
const
wchar_t
*
=
.
();
wchar_t
*
;
_Errno_ref
=
0
;
const float _Ans = _CSTD wcstof(_Ptr, &_Eptr);
const
float
= ::
(
_Ptr
, &
_Eptr
);
if
(
_Ptr
_Eptr
)
(
"invalid stof argument"
);
if (_Errno_ref == ERANGE)
(
"stof argument out of range"
);
if
(
!=
nullptr
)
*
= (
)(
_Eptr
-
_Ptr
);
return
(
_Ans
);
}
inline
double
(
const
&
,
*
=
nullptr
)
{
int& _Errno_ref = errno; // Nonzero cost, pay it once
const
wchar_t
*
=
.
();
wchar_t
*
;
_Errno_ref
=
0
;
const double _Ans = _CSTD wcstod(_Ptr, &_Eptr);
const
double
= ::
(
_Ptr
, &
_Eptr
);
if
(
_Ptr
_Eptr
)
(
"invalid stod argument"
);
if (_Errno_ref == ERANGE)
(
"stod argument out of range"
);
if
(
!=
nullptr
)
*
= (
)(
_Eptr
-
_Ptr
);
return
(
_Ans
);
}
inline
long
double
(
const
&
,
*
=
nullptr
)
{
int& _Errno_ref = errno; // Nonzero cost, pay it once
const
wchar_t
*
=
.
();
wchar_t
*
;
_Errno_ref
=
0
;
const long double _Ans = _CSTD wcstold(_Ptr, &_Eptr);
const
long
double
= ::
(
_Ptr
, &
_Eptr
);
if
(
_Ptr
_Eptr
)
(
"invalid stold argument"
);
if (_Errno_ref == ERANGE)
(
"stold argument out of range"
);
if
(
!=
nullptr
)
*
= (
)(
_Eptr
-
_Ptr
);
return
(
_Ans
);
}
template
<
class
,
class
>
inline
*
(
*
,
)
{
static_assert
(
<
>,
"_UTy must be unsigned"
);
#ifdef _WIN64
auto _UVal_trunc = _UVal;
#else /* ^^^ _WIN64 ^^^ // vvv !_WIN64 vvv */
#pragma warning(push)
#pragma warning(disable: 4127) // conditional expression is constant
#pragma warning(disable:
4127
)
if
(
sizeof
(
) >
4
)
{
while
(
>
0xFFFFFFFFU
)
{
auto
=
static_cast
<
unsigned
long
>(
%
1000000000
);
/=
1000000000
;
for
(
int
=
0
;
_Idx
9
; ++
_Idx
)
{
*--
=
static_cast
<
>(
'0'
+
_UVal_chunk
%
10
);
_UVal_chunk
/=
10
;
}
}
}
#pragma warning(pop)
auto
=
static_cast
<
unsigned
long
>(
);
#endif /* _WIN64 */
do
{
*--
=
static_cast
<
>(
'0'
+
_UVal_trunc
%
10
);
_UVal_trunc
/=
10
;
}
while
(
_UVal_trunc
0
);
return
(
);
}
template
<
class
,
class
>
inline
<
>
(
const
)
{
static_assert
(
<
>,
"_Ty must be integral"
);
using
=
<
>;
[
21
];
_Elem* const _Buff_end = _STD end(_Buff);
*
const
= ::
std
::
(
_Buff
);
*
=
_Buff_end
;
const
auto
=
static_cast
<
>(
);
if
(
<
0
)
{
_RNext
=
(
_RNext
,
0
-
_UVal
);
*--
_RNext
=
'-'
;
}
else
_RNext
=
(
_RNext
,
_UVal
);
return
(
<
>(
_RNext
,
_Buff_end
));
}
template
<
class
>
inline
(
const
char
*
,
)
{
static_assert
(
<
>,
"_Ty must be floating point"
);
const auto _Len = static_cast<size_t>(_CSTD _scprintf(_Fmt, _Val));
const
auto
=
static_cast
<
>(::
(
,
));
(
_Len
,
'\0'
);
_CSTD sprintf_s(&_Str[0], _Len + 1, _Fmt, _Val);
::
(&
_Str
0
],
_Len
+
1
,
,
);
return
(
_Str
);
}
template
<
class
>
inline
(
const
wchar_t
*
,
)
{
static_assert
(
<
>,
"_Ty must be floating point"
);
const auto _Len = static_cast<size_t>(_CSTD _scwprintf(_Fmt, _Val));
const
auto
=
static_cast
<
>(::
(
,
));
(
_Len
,
L'\0'
);
_CSTD swprintf_s(&_Str[0], _Len + 1, _Fmt, _Val);
::
(&
_Str
0
],
_Len
+
1
,
,
);
return
(
_Str
);
}
#undef _TO_STRING_BUF_SIZE
_NODISCARD inline string to_string(int _Val)
{
return
(
<
char
>(
));
}
_NODISCARD inline string to_string(unsigned int _Val)
{
return
(
<
char
>(
));
}
_NODISCARD inline string to_string(long _Val)
{
return
(
<
char
>(
));
}
_NODISCARD inline string to_string(unsigned long _Val)
{
return
(
<
char
>(
));
}
_NODISCARD inline string to_string(long long _Val)
{
return
(
<
char
>(
));
}
_NODISCARD inline string to_string(unsigned long long _Val)
inline
(
unsigned
long
long
)
{
return
(
<
char
>(
));
}
_NODISCARD inline string to_string(float _Val)
{
return
(
(
"%f"
,
));
}
_NODISCARD inline string to_string(double _Val)
{
return
(
(
"%f"
,
));
}
_NODISCARD inline string to_string(long double _Val)
{
return
(
(
"%Lf"
,
));
}
_NODISCARD inline wstring to_wstring(int _Val)
{
return
(
<
wchar_t
>(
));
}
_NODISCARD inline wstring to_wstring(unsigned int _Val)
{
return
(
<
wchar_t
>(
));
}
_NODISCARD inline wstring to_wstring(long _Val)
{
return
(
<
wchar_t
>(
));
}
_NODISCARD inline wstring to_wstring(unsigned long _Val)
{
return
(
<
wchar_t
>(
));
}
_NODISCARD inline wstring to_wstring(long long _Val)
{
return
(
<
wchar_t
>(
));
}
_NODISCARD inline wstring to_wstring(unsigned long long _Val)
inline
(
unsigned
long
long
)
{
return
(
<
wchar_t
>(
));
}
_NODISCARD inline wstring to_wstring(float _Val)
{
return
(
(
L"%f"
,
));
}
_NODISCARD inline wstring to_wstring(double _Val)
{
return
(
(
L"%f"
,
));
}
_NODISCARD inline wstring to_wstring(long double _Val)
{
return
(
(
L"%Lf"
,
));
}
inline
namespace
{
inline
namespace
{
_NODISCARD inline string operator "" s(const char *_Str, size_t _Len)
{
return
(
(
,
));
}
_NODISCARD inline wstring operator "" s(const wchar_t *_Str, size_t _Len)
inline
(
const
wchar_t
*
,
)
{
return
(
(
,
));
}
_NODISCARD inline u16string operator "" s(const char16_t *_Str, size_t _Len)
inline
(
const
char16_t
*
,
)
{
return
(
(
,
));
}
_NODISCARD inline u32string operator "" s(const char32_t *_Str, size_t _Len)
inline
(
const
char32_t
*
,
)
{
return
(
(
,
));
}
}
}
#if _HAS_CXX17
namespace pmr {
template<class _Elem,
class _Traits = char_traits<_Elem>>
using basic_string = _STD basic_string<_Elem, _Traits, polymorphic_allocator<_Elem>>;
using string = basic_string<char>;
using u16string = basic_string<char16_t>;
using u32string = basic_string<char32_t>;
using wstring = basic_string<wchar_t>;
} // namespace pmr
#endif /* _HAS_CXX17 */
#pragma pop_macro("new")
_STL_RESTORE_CLANG_WARNINGS
#pragma warning(pop)
#pragma warning(pop)
#pragma pack(pop)
#endif /* RC_INVOKED */
#endif /* _STRING_ */
#pragma pack(pop)