Description
According to the standard(ref ), char_traits::eq/lt/to_char_type/to_int_type/eq_int_type/not_eof should take values instead of references as parameters.
(
Also in
https://github.com/microsoft/STL/blob/a62109595b6d89e08172fdf4beb75a2670fe0cc9/stl/inc/xstring#L305-L327?plain=1
https://github.com/microsoft/STL/blob/a62109595b6d89e08172fdf4beb75a2670fe0cc9/stl/inc/xstring#L449-L471?plain=1
)
_NODISCARD static constexpr bool eq(const _Elem& _Left, const _Elem& _Right) noexcept {
return _Left == _Right;
}
_NODISCARD static constexpr bool lt(const _Elem& _Left, const _Elem& _Right) noexcept {
return _Left < _Right;
}
_NODISCARD static constexpr _Elem to_char_type(const int_type& _Meta) noexcept {
return static_cast<_Elem>(_Meta);
}
_NODISCARD static constexpr int_type to_int_type(const _Elem& _Ch) noexcept {
return static_cast<int_type>(_Ch);
}
_NODISCARD static constexpr bool eq_int_type(const int_type& _Left, const int_type& _Right) noexcept {
return _Left == _Right;
}
_NODISCARD static constexpr int_type not_eof(const int_type& _Meta) noexcept {
return _Meta != eof() ? _Meta : !eof();
}
Also, int_types for char_traits<char16_t>, <char32_t> and <wchar_t> should be uint_least16_t, uint_least32_t and wint_t respectively. Currently they are defined as unsigned short, unsigned int and unsigned short. --They just works now. However, I think it will be better to use aliases directly, or at least add some static_asserts(e.g. static_assert(std::is_same_v<wint_t,unsigned short>).
template <>
struct char_traits<char16_t> : _WChar_traits<char16_t> {};
template <>
struct char_traits<char32_t> : _Char_traits<char32_t, unsigned int> {};
template <>
struct char_traits<wchar_t> : _WChar_traits<wchar_t> {};
(char_traits<char>,<char8_t> has no such issue)
(off topic) We can safely add noexcept /*strengthened*/ for this function:
_NODISCARD constexpr int compare(_In_z_ const _Elem* const _Ptr) const { // compare [0, _Mysize) with [_Ptr, <null>)
return compare(basic_string_view(_Ptr));
}
(off topic; question) What does the template(line2547~2549) do here? _Alloc2 is not used in the body, and _Alloc is directly used as allocator in other member functions.
(
Also here; the only another use of this pattern
https://github.com/microsoft/STL/blob/a62109595b6d89e08172fdf4beb75a2670fe0cc9/stl/inc/xstring#L2560-L2566?plain=1
)
#if _HAS_CXX17
template <class _Alloc2 = _Alloc, enable_if_t<_Is_allocator<_Alloc2>::value, int> = 0>
#endif // _HAS_CXX17
_CONSTEXPR20 basic_string(_In_z_ const _Elem* const _Ptr, const _Alloc& _Al)
: _Mypair(_One_then_variadic_args_t{}, _Al) {
_Construct<_Construct_strategy::_From_ptr>(_Ptr, _Convert_size<size_type>(_Traits::length(_Ptr)));
}
Reactions are currently unavailable
You can’t perform that action at this time.
According to the standard(ref),
char_traits::eq/lt/to_char_type/to_int_type/eq_int_type/not_eofshould take values instead of references as parameters.(
Also in
https://github.com/microsoft/STL/blob/a62109595b6d89e08172fdf4beb75a2670fe0cc9/stl/inc/xstring#L305-L327?plain=1
https://github.com/microsoft/STL/blob/a62109595b6d89e08172fdf4beb75a2670fe0cc9/stl/inc/xstring#L449-L471?plain=1
)
STL/stl/inc/xstring
Lines 193 to 215 in a621095
Also,
int_types forchar_traits<char16_t>,<char32_t>and<wchar_t>should beuint_least16_t,uint_least32_tandwint_trespectively. Currently they are defined asunsigned short,unsigned intandunsigned short. --They just works now. However, I think it will be better to use aliases directly, or at least add some static_asserts(e.g.static_assert(std::is_same_v<wint_t,unsigned short>).STL/stl/inc/xstring
Lines 337 to 344 in a621095
(
char_traits<char>,<char8_t>has no such issue)(off topic) We can safely add
noexcept /*strengthened*/for this function:STL/stl/inc/xstring
Lines 1402 to 1404 in a621095
(off topic; question) What does the template(line2547~2549) do here?
_Alloc2is not used in the body, and_Allocis directly used as allocator in other member functions.(
Also here; the only another use of this pattern
https://github.com/microsoft/STL/blob/a62109595b6d89e08172fdf4beb75a2670fe0cc9/stl/inc/xstring#L2560-L2566?plain=1
)
STL/stl/inc/xstring
Lines 2547 to 2553 in a621095