|
_STD_BEGIN
|
|
template <class _Ty, class _TVal>
|
|
__declspec(noalias) size_t __std_count_trivial(_Ty* _First, _Ty* _Last, const _TVal _Val) noexcept {
|
|
if constexpr (_STD is_pointer_v<_TVal> || _STD is_null_pointer_v<_TVal>) {
|
|
return _STD __std_count_trivial(_First, _Last, reinterpret_cast<uintptr_t>(_Val));
|
|
} else if constexpr (sizeof(_Ty) == 1) {
|
|
return ::__std_count_trivial_1(_First, _Last, static_cast<uint8_t>(_Val));
|
|
} else if constexpr (sizeof(_Ty) == 2) {
|
|
return ::__std_count_trivial_2(_First, _Last, static_cast<uint16_t>(_Val));
|
|
} else if constexpr (sizeof(_Ty) == 4) {
|
|
return ::__std_count_trivial_4(_First, _Last, static_cast<uint32_t>(_Val));
|
|
} else if constexpr (sizeof(_Ty) == 8) {
|
|
return ::__std_count_trivial_8(_First, _Last, static_cast<uint64_t>(_Val));
|
|
} else {
|
|
static_assert(_STD _Always_false<_Ty>, "Unexpected size");
|
|
}
|
|
}
|
|
|
|
template <class _Ty, class _TVal>
|
|
_Ty* __std_find_trivial(_Ty* _First, _Ty* _Last, const _TVal _Val) noexcept {
|
|
if constexpr (_STD is_pointer_v<_TVal> || _STD is_null_pointer_v<_TVal>) {
|
|
return _STD __std_find_trivial(_First, _Last, reinterpret_cast<uintptr_t>(_Val));
|
|
} else if constexpr (sizeof(_Ty) == 1) {
|
|
return const_cast<_Ty*>(
|
|
static_cast<const _Ty*>(::__std_find_trivial_1(_First, _Last, static_cast<uint8_t>(_Val))));
|
|
} else if constexpr (sizeof(_Ty) == 2) {
|
|
return const_cast<_Ty*>(
|
|
static_cast<const _Ty*>(::__std_find_trivial_2(_First, _Last, static_cast<uint16_t>(_Val))));
|
|
} else if constexpr (sizeof(_Ty) == 4) {
|
|
return const_cast<_Ty*>(
|
|
static_cast<const _Ty*>(::__std_find_trivial_4(_First, _Last, static_cast<uint32_t>(_Val))));
|
|
} else if constexpr (sizeof(_Ty) == 8) {
|
|
return const_cast<_Ty*>(
|
|
static_cast<const _Ty*>(::__std_find_trivial_8(_First, _Last, static_cast<uint64_t>(_Val))));
|
|
} else {
|
|
static_assert(_STD _Always_false<_Ty>, "Unexpected size");
|
|
}
|
|
}
|
|
|
|
template <class _Ty, class _TVal>
|
|
_Ty* __std_find_trivial_unsized(_Ty* _First, const _TVal _Val) noexcept {
|
|
if constexpr (_STD is_pointer_v<_TVal> || _STD is_null_pointer_v<_TVal>) {
|
|
return _STD __std_find_trivial_unsized(_First, reinterpret_cast<uintptr_t>(_Val));
|
|
} else if constexpr (sizeof(_Ty) == 1) {
|
|
return const_cast<_Ty*>(
|
|
static_cast<const _Ty*>(::__std_find_trivial_unsized_1(_First, static_cast<uint8_t>(_Val))));
|
|
} else if constexpr (sizeof(_Ty) == 2) {
|
|
return const_cast<_Ty*>(
|
|
static_cast<const _Ty*>(::__std_find_trivial_unsized_2(_First, static_cast<uint16_t>(_Val))));
|
|
} else if constexpr (sizeof(_Ty) == 4) {
|
|
return const_cast<_Ty*>(
|
|
static_cast<const _Ty*>(::__std_find_trivial_unsized_4(_First, static_cast<uint32_t>(_Val))));
|
|
} else if constexpr (sizeof(_Ty) == 8) {
|
|
return const_cast<_Ty*>(
|
|
static_cast<const _Ty*>(::__std_find_trivial_unsized_8(_First, static_cast<uint64_t>(_Val))));
|
|
} else {
|
|
static_assert(_STD _Always_false<_Ty>, "Unexpected size");
|
|
}
|
|
}
|
|
|
|
template <class _Ty>
|
|
_Ty* __std_min_element(_Ty* _First, _Ty* _Last) noexcept {
|
|
constexpr bool _Signed = _STD is_signed_v<_Ty>;
|
|
|
|
if constexpr (_STD is_same_v<_STD remove_const_t<_Ty>, float>) {
|
|
return const_cast<_Ty*>(static_cast<const _Ty*>(::__std_min_element_f(_First, _Last, false)));
|
|
} else if constexpr (_STD _Is_any_of_v<_STD remove_const_t<_Ty>, double, long double>) {
|
|
return const_cast<_Ty*>(static_cast<const _Ty*>(::__std_min_element_d(_First, _Last, false)));
|
|
} else if constexpr (sizeof(_Ty) == 1) {
|
|
return const_cast<_Ty*>(static_cast<const _Ty*>(::__std_min_element_1(_First, _Last, _Signed)));
|
|
} else if constexpr (sizeof(_Ty) == 2) {
|
|
return const_cast<_Ty*>(static_cast<const _Ty*>(::__std_min_element_2(_First, _Last, _Signed)));
|
|
} else if constexpr (sizeof(_Ty) == 4) {
|
|
return const_cast<_Ty*>(static_cast<const _Ty*>(::__std_min_element_4(_First, _Last, _Signed)));
|
|
} else if constexpr (sizeof(_Ty) == 8) {
|
|
return const_cast<_Ty*>(static_cast<const _Ty*>(::__std_min_element_8(_First, _Last, _Signed)));
|
|
} else {
|
|
static_assert(_STD _Always_false<_Ty>, "Unexpected size");
|
|
}
|
|
}
|
|
|
|
template <class _Ty>
|
|
_Ty* __std_max_element(_Ty* _First, _Ty* _Last) noexcept {
|
|
constexpr bool _Signed = _STD is_signed_v<_Ty>;
|
|
|
|
if constexpr (_STD is_same_v<_STD remove_const_t<_Ty>, float>) {
|
|
return const_cast<_Ty*>(static_cast<const _Ty*>(::__std_max_element_f(_First, _Last, false)));
|
|
} else if constexpr (_STD _Is_any_of_v<_STD remove_const_t<_Ty>, double, long double>) {
|
|
return const_cast<_Ty*>(static_cast<const _Ty*>(::__std_max_element_d(_First, _Last, false)));
|
|
} else if constexpr (sizeof(_Ty) == 1) {
|
|
return const_cast<_Ty*>(static_cast<const _Ty*>(::__std_max_element_1(_First, _Last, _Signed)));
|
|
} else if constexpr (sizeof(_Ty) == 2) {
|
|
return const_cast<_Ty*>(static_cast<const _Ty*>(::__std_max_element_2(_First, _Last, _Signed)));
|
|
} else if constexpr (sizeof(_Ty) == 4) {
|
|
return const_cast<_Ty*>(static_cast<const _Ty*>(::__std_max_element_4(_First, _Last, _Signed)));
|
|
} else if constexpr (sizeof(_Ty) == 8) {
|
|
return const_cast<_Ty*>(static_cast<const _Ty*>(::__std_max_element_8(_First, _Last, _Signed)));
|
|
} else {
|
|
static_assert(_STD _Always_false<_Ty>, "Unexpected size");
|
|
}
|
|
}
|
|
_STD_END
|
The affected code
STL/stl/inc/algorithm
Lines 66 to 112 in bd3d740
STL/stl/inc/xutility
Lines 113 to 214 in bd3d740
The desired change
The functions being defined here are taking
_Ty* _First, _Ty* _Lastparameters, but aren't modifying_Firstand_Lastthemselves. We should apply top-levelconstto these pointers, changing them to_Ty* const _First, _Ty* const _Lastwhich will make our code more consistent and ever-so-slightly more resistant to mistakes.Note that
__std_find_trivial_unsizedtakes only_Ty* _Firstbut should be changed similarly.About this "good first issue"
This issue is intended for a new contributor (especially one new to GitHub) to get started with a simple change.
Please feel free to submit a pull request if there isn't one already linked here - no need to ask for permission! 😸
You can (and should) link your pull request to this issue using GitHub's close/fix/resolve syntax.
(in the PR description not the commit message)