Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions stl/inc/random
Original file line number Diff line number Diff line change
Expand Up @@ -1824,12 +1824,12 @@ private:
result_type _Eval(_Engine& _Eng, _Ty _Min, _Ty _Max) const { // compute next value in range [_Min, _Max]
_Rng_from_urng<_Uty, _Engine> _Generator(_Eng);

const _Uty _Umin = _Adjust(_Uty(_Min));
const _Uty _Umax = _Adjust(_Uty(_Max));
const _Uty _Umin = _Adjust(static_cast<_Uty>(_Min));
const _Uty _Umax = _Adjust(static_cast<_Uty>(_Max));

_Uty _Uret;

if (_Umax - _Umin == _Uty(-1)) {
if (_Umax - _Umin == static_cast<_Uty>(-1)) {
_Uret = static_cast<_Uty>(_Generator._Get_all_bits());
} else {
_Uret = static_cast<_Uty>(_Generator(static_cast<_Uty>(_Umax - _Umin + 1)));
Expand All @@ -1839,23 +1839,19 @@ private:
}

static _Uty _Adjust(_Uty _Uval) { // convert signed ranges to unsigned ranges and vice versa
return _Adjust(_Uval, is_signed<_Ty>{});
}

static _Uty _Adjust(_Uty _Uval, true_type) { // convert signed ranges to unsigned ranges and vice versa
const _Uty _Adjuster = (_Uty(-1) >> 1) + 1; // 2^(N-1)
if _CONSTEXPR_IF (is_signed_v<_Ty>) {
const _Uty _Adjuster = (static_cast<_Uty>(-1) >> 1) + 1; // 2^(N-1)

if (_Uval < _Adjuster) {
return static_cast<_Uty>(_Uval + _Adjuster);
} else {
return static_cast<_Uty>(_Uval - _Adjuster);
if (_Uval < _Adjuster) {
return static_cast<_Uty>(_Uval + _Adjuster);
} else {
return static_cast<_Uty>(_Uval - _Adjuster);
}
} else { // _Ty is already unsigned, do nothing
return _Uval;
}
}

static _Uty _Adjust(_Uty _Uval, false_type) { // _Ty is already unsigned, do nothing
return _Uval;
}

param_type _Par;
};

Expand Down
2 changes: 1 addition & 1 deletion stl/inc/xmemory
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ struct _Get_propagate_on_container_swap<_Ty, void_t<typename _Ty::propagate_on_c
// STRUCT TEMPLATE _Get_is_always_equal
template <class _Ty, class = void>
struct _Get_is_always_equal {
using type = typename is_empty<_Ty>::type;
using type = bool_constant<is_empty_v<_Ty>>;
};

template <class _Ty>
Expand Down
2 changes: 1 addition & 1 deletion stl/inc/xtree
Original file line number Diff line number Diff line change
Expand Up @@ -1759,7 +1759,7 @@ protected:
_Nodeptr _Newroot = _Scary->_Myhead; // point at nil node

if (!_Rootnode->_Isnil) { // copy or move a node, then any subtrees
typename is_same<key_type, value_type>::type _Is_set;
bool_constant<is_same_v<key_type, value_type>> _Is_set;
_Nodeptr _Pnode = _Copy_or_move(_Rootnode->_Myval, _Movefl, _Is_set);
_Pnode->_Parent = _Wherenode;
_Pnode->_Color = _Rootnode->_Color;
Expand Down
3 changes: 2 additions & 1 deletion stl/inc/xutility
Original file line number Diff line number Diff line change
Expand Up @@ -5466,7 +5466,8 @@ _NODISCARD constexpr bool _Within_limits(const _Ty& _Val, false_type, false_type
template <class _InIt, class _Ty>
_NODISCARD constexpr bool _Within_limits(_InIt, const _Ty& _Val) { // check whether _Val is within the limits of _Elem
using _Elem = remove_pointer_t<_InIt>;
return _Within_limits(_Val, is_signed<_Elem>{}, is_signed<_Ty>{}, bool_constant<-1 == static_cast<_Ty>(-1)>{});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this change as much as the others, I think it impacts clarity more. I'm OK with it if the throughput improvement is actually decent though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was enough to show up on @xiangfan-ms's radar. Clarity will be dramatically improved when we can if constexprize this, hopefully soon.

return _Within_limits(_Val, bool_constant<is_signed_v<_Elem>>{}, bool_constant<is_signed_v<_Ty>>{},
bool_constant<-1 == static_cast<_Ty>(-1)>{});
}

template <class _InIt>
Expand Down