Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove macros and a compiler workaround #1307

Merged
merged 19 commits into from
Oct 3, 2020
Merged
Show file tree
Hide file tree
Changes from 15 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
10 changes: 4 additions & 6 deletions stl/inc/chrono
Original file line number Diff line number Diff line change
Expand Up @@ -575,10 +575,8 @@ namespace chrono {

// CLOCKS
struct system_clock { // wraps GetSystemTimePreciseAsFileTime/GetSystemTimeAsFileTime
using rep = long long;

using period = ratio_multiply<ratio<_XTIME_NSECS_PER_TICK, 1>, nano>;

using rep = long long;
using period = ratio<1, 10'000'000>; // 100 nanoseconds
using duration = chrono::duration<rep, period>;
using time_point = chrono::time_point<system_clock>;
static constexpr bool is_steady = false;
Expand All @@ -588,11 +586,11 @@ namespace chrono {
}

_NODISCARD static __time64_t to_time_t(const time_point& _Time) noexcept { // convert to __time64_t
return static_cast<__time64_t>(_Time.time_since_epoch().count() / _XTIME_TICKS_PER_TIME_T);
return duration_cast<seconds>(_Time.time_since_epoch()).count();
}

_NODISCARD static time_point from_time_t(__time64_t _Tm) noexcept { // convert from __time64_t
return time_point(duration(_Tm * _XTIME_TICKS_PER_TIME_T));
return time_point{seconds{_Tm}};
}
};

Expand Down
2 changes: 1 addition & 1 deletion stl/inc/complex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ _STL_DISABLE_CLANG_WARNINGS
#undef new

#ifndef _C_COMPLEX_T
#define _C_COMPLEX_T
#define _C_COMPLEX_T // Also defined by UCRT <complex.h>

struct _C_double_complex {
double _Val[2];
Expand Down
143 changes: 68 additions & 75 deletions stl/inc/deque
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,14 @@ _STL_DISABLE_CLANG_WARNINGS
#undef new

_STD_BEGIN
// DEQUE PARAMETERS
#define _DEQUEMAPSIZ 8 // minimum map size, at least 1
#define _DEQUESIZ \
(sizeof(value_type) <= 1 \
? 16 \
: sizeof(value_type) <= 2 \
? 8 \
: sizeof(value_type) <= 4 ? 4 \
: sizeof(value_type) <= 8 ? 2 : 1) // elements per block (a power of 2)

// CLASS TEMPLATE _Deque_unchecked_const_iterator
template <class _Mydeque>
class _Deque_unchecked_const_iterator {
private:
using _Size_type = typename _Mydeque::size_type;

static constexpr int _Block_size = _Mydeque::_Block_size;

public:
using iterator_category = random_access_iterator_tag;

Expand All @@ -53,7 +45,7 @@ public:

_NODISCARD reference operator*() const noexcept {
_Size_type _Block = _Mycont->_Getblock(_Myoff);
_Size_type _Off = _Myoff % _DEQUESIZ;
_Size_type _Off = _Myoff % _Block_size;
return _Mycont->_Map[_Block][_Off];
}

Expand Down Expand Up @@ -239,6 +231,8 @@ class _Deque_const_iterator : public _Iterator_base12 {
private:
using _Size_type = typename _Mydeque::size_type;

static constexpr int _Block_size = _Mydeque::_Block_size;

public:
using iterator_category = random_access_iterator_tag;

Expand All @@ -248,7 +242,7 @@ public:
using reference = const value_type&;

using _Mydeque_t = _Mydeque; // helper for expression evaluator
enum { _EEN_DS = _DEQUESIZ }; // helper for expression evaluator
enum { _EEN_DS = _Block_size }; // helper for expression evaluator
_Deque_const_iterator() noexcept : _Myoff(0) {
_Setcont(nullptr);
}
Expand All @@ -266,7 +260,7 @@ public:
#endif // _ITERATOR_DEBUG_LEVEL != 0

_Size_type _Block = _Mycont->_Getblock(_Myoff);
_Size_type _Off = _Myoff % _DEQUESIZ;
_Size_type _Off = _Myoff % _Block_size;
return _Mycont->_Map[_Block][_Off];
}

Expand Down Expand Up @@ -541,11 +535,18 @@ public:
using const_reference = const value_type&;
using _Mapptr = typename _Val_types::_Mapptr;

private:
static constexpr size_t _Bytes = sizeof(value_type);

public:
static constexpr int _Block_size =
_Bytes <= 1 ? 16 : _Bytes <= 2 ? 8 : _Bytes <= 4 ? 4 : _Bytes <= 8 ? 2 : 1; // elements per block (a power of 2)
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved

_Deque_val() noexcept : _Map(), _Mapsize(0), _Myoff(0), _Mysize(0) {}

size_type _Getblock(size_type _Off) const noexcept {
// NB: _Mapsize and _DEQUESIZ are guaranteed to be powers of 2
return (_Off / _DEQUESIZ) & (_Mapsize - 1);
// NB: _Mapsize and _Block_size are guaranteed to be powers of 2
return (_Off / _Block_size) & (_Mapsize - 1);
}

_Mapptr _Map; // pointer to array of pointers to blocks
Expand Down Expand Up @@ -574,6 +575,9 @@ private:
_Deque_iter_types<_Ty, typename _Alty_traits::size_type, typename _Alty_traits::difference_type,
typename _Alty_traits::pointer, typename _Alty_traits::const_pointer, _Ty&, const _Ty&, _Mapptr>>>;

static constexpr int _Minimum_map_size = 8;
static constexpr int _Block_size = _Scary_val::_Block_size;

public:
using allocator_type = _Alloc;
using value_type = _Ty;
Expand All @@ -591,7 +595,7 @@ public:

using reverse_iterator = _STD reverse_iterator<iterator>;
using const_reverse_iterator = _STD reverse_iterator<const_iterator>;
enum { _EEN_DS = _DEQUESIZ }; // helper for expression evaluator
enum { _EEN_DS = _Block_size }; // helper for expression evaluator

deque() : _Mypair(_Zero_then_variadic_args_t{}) {
_Get_data()._Alloc_proxy(static_cast<_Alproxy_ty>(_Getal()));
Expand Down Expand Up @@ -675,34 +679,6 @@ private:
_Guard._Target = nullptr;
}

#define _PUSH_FRONT_BEGIN \
if (_Myoff() % _DEQUESIZ == 0 && _Mapsize() <= (_Mysize() + _DEQUESIZ) / _DEQUESIZ) { \
_Growmap(1); \
} \
_Myoff() &= _Mapsize() * _DEQUESIZ - 1; \
size_type _Newoff = _Myoff() != 0 ? _Myoff() : _Mapsize() * _DEQUESIZ; \
size_type _Block = _Getblock(--_Newoff); \
if (_Map()[_Block] == nullptr) { \
_Map()[_Block] = _Getal().allocate(_DEQUESIZ); \
}

#define _PUSH_FRONT_END \
_Myoff() = _Newoff; \
++_Mysize()

#define _PUSH_BACK_BEGIN \
if ((_Myoff() + _Mysize()) % _DEQUESIZ == 0 && _Mapsize() <= (_Mysize() + _DEQUESIZ) / _DEQUESIZ) { \
_Growmap(1); \
} \
_Myoff() &= _Mapsize() * _DEQUESIZ - 1; \
size_type _Newoff = _Myoff() + _Mysize(); \
size_type _Block = _Getblock(_Newoff); \
if (_Map()[_Block] == nullptr) { \
_Map()[_Block] = _Getal().allocate(_DEQUESIZ); \
}

#define _PUSH_BACK_END ++_Mysize()

public:
deque(deque&& _Right) : _Mypair(_One_then_variadic_args_t{}, _STD move(_Right._Getal())) {
_Get_data()._Alloc_proxy(static_cast<_Alproxy_ty>(_Getal()));
Expand Down Expand Up @@ -786,10 +762,7 @@ private:

public:
void push_front(_Ty&& _Val) {
_Orphan_all();
_PUSH_FRONT_BEGIN;
_Alty_traits::construct(_Getal(), _Unfancy(_Map()[_Block] + _Newoff % _DEQUESIZ), _STD move(_Val));
_PUSH_FRONT_END;
emplace_front(_STD move(_Val));
}

void push_back(_Ty&& _Val) {
Expand All @@ -804,10 +777,22 @@ public:
template <class... _Valty>
decltype(auto) emplace_front(_Valty&&... _Val) {
_Orphan_all();
_PUSH_FRONT_BEGIN;

if (_Myoff() % _Block_size == 0 && _Mapsize() <= (_Mysize() + _Block_size) / _Block_size) {
_Growmap(1);
}
_Myoff() &= _Mapsize() * _Block_size - 1;
size_type _Newoff = _Myoff() != 0 ? _Myoff() : _Mapsize() * _Block_size;
size_type _Block = _Getblock(--_Newoff);
if (_Map()[_Block] == nullptr) {
_Map()[_Block] = _Getal().allocate(_Block_size);
}

_Alty_traits::construct(
_Getal(), _Unfancy(_Map()[_Block] + _Newoff % _DEQUESIZ), _STD forward<_Valty>(_Val)...);
_PUSH_FRONT_END;
_Getal(), _Unfancy(_Map()[_Block] + _Newoff % _Block_size), _STD forward<_Valty>(_Val)...);

_Myoff() = _Newoff;
++_Mysize();

#if _HAS_CXX17
return front();
Expand All @@ -817,10 +802,7 @@ public:
template <class... _Valty>
decltype(auto) emplace_back(_Valty&&... _Val) {
_Orphan_all();
_PUSH_BACK_BEGIN;
_Alty_traits::construct(
_Getal(), _Unfancy(_Map()[_Block] + _Newoff % _DEQUESIZ), _STD forward<_Valty>(_Val)...);
_PUSH_BACK_END;
_Emplace_back_internal(_STD forward<_Valty>(_Val)...);

#if _HAS_CXX17
return back();
Expand Down Expand Up @@ -963,11 +945,12 @@ public:
}

void shrink_to_fit() {
size_type _Oldcapacity = _DEQUESIZ * _Mapsize();
size_type _Oldcapacity = _Block_size * _Mapsize();
size_type _Newcapacity = _Oldcapacity / 2;

if (_Newcapacity < _DEQUESIZ * _DEQUEMAPSIZ)
_Newcapacity = _DEQUESIZ * _DEQUEMAPSIZ;
if (_Newcapacity < _Block_size * _Minimum_map_size) {
_Newcapacity = _Block_size * _Minimum_map_size;
}

if ((empty() && 0 < _Mapsize())
|| (!empty() && size() <= _Newcapacity && _Newcapacity < _Oldcapacity)) { // worth shrinking, do it
Expand Down Expand Up @@ -1015,8 +998,10 @@ public:
}

_NODISCARD const_reference at(size_type _Pos) const {
if (_Mysize() <= _Pos)
if (_Mysize() <= _Pos) {
_Xran();
}

return *(begin() + static_cast<difference_type>(_Pos));
}

Expand Down Expand Up @@ -1077,10 +1062,7 @@ public:
}

void push_front(const _Ty& _Val) {
_Orphan_all();
_PUSH_FRONT_BEGIN;
_Alty_traits::construct(_Getal(), _Unfancy(_Map()[_Block] + _Newoff % _DEQUESIZ), _Val);
_PUSH_FRONT_END;
emplace_front(_Val);
}

void pop_front() noexcept /* strengthened */ {
Expand All @@ -1090,7 +1072,7 @@ public:
} else { // something to erase, do it
_Orphan_off(_Myoff());
size_type _Block = _Getblock(_Myoff());
_Alty_traits::destroy(_Getal(), _Unfancy(_Map()[_Block] + _Myoff() % _DEQUESIZ));
_Alty_traits::destroy(_Getal(), _Unfancy(_Map()[_Block] + _Myoff() % _Block_size));
if (--_Mysize() == 0) {
_Myoff() = 0;
} else {
Expand All @@ -1100,7 +1082,7 @@ public:

#else // _ITERATOR_DEBUG_LEVEL == 2
size_type _Block = _Getblock(_Myoff());
_Alty_traits::destroy(_Getal(), _Unfancy(_Map()[_Block] + _Myoff() % _DEQUESIZ));
_Alty_traits::destroy(_Getal(), _Unfancy(_Map()[_Block] + _Myoff() % _Block_size));
if (--_Mysize() == 0) {
_Myoff() = 0;
} else {
Expand All @@ -1112,9 +1094,20 @@ public:
private:
template <class... _Tys>
void _Emplace_back_internal(_Tys&&... _Vals) {
_PUSH_BACK_BEGIN;
_Alty_traits::construct(_Getal(), _Unfancy(_Map()[_Block] + _Newoff % _DEQUESIZ), _STD forward<_Tys>(_Vals)...);
_PUSH_BACK_END;
if ((_Myoff() + _Mysize()) % _Block_size == 0 && _Mapsize() <= (_Mysize() + _Block_size) / _Block_size) {
_Growmap(1);
}
_Myoff() &= _Mapsize() * _Block_size - 1;
size_type _Newoff = _Myoff() + _Mysize();
size_type _Block = _Getblock(_Newoff);
if (_Map()[_Block] == nullptr) {
_Map()[_Block] = _Getal().allocate(_Block_size);
}

_Alty_traits::construct(
_Getal(), _Unfancy(_Map()[_Block] + _Newoff % _Block_size), _STD forward<_Tys>(_Vals)...);

++_Mysize();
}

public:
Expand All @@ -1131,7 +1124,7 @@ public:
size_type _Newoff = _Myoff() + _Mysize() - 1;
_Orphan_off(_Newoff);
size_type _Block = _Getblock(_Newoff);
_Alty_traits::destroy(_Getal(), _Unfancy(_Map()[_Block] + _Newoff % _DEQUESIZ));
_Alty_traits::destroy(_Getal(), _Unfancy(_Map()[_Block] + _Newoff % _Block_size));
if (--_Mysize() == 0) {
_Myoff() = 0;
}
Expand All @@ -1140,7 +1133,7 @@ public:
#else // _ITERATOR_DEBUG_LEVEL == 2
size_type _Newoff = _Myoff() + _Mysize() - 1;
size_type _Block = _Getblock(_Newoff);
_Alty_traits::destroy(_Getal(), _Unfancy(_Map()[_Block] + _Newoff % _DEQUESIZ));
_Alty_traits::destroy(_Getal(), _Unfancy(_Map()[_Block] + _Newoff % _Block_size));
if (--_Mysize() == 0) {
_Myoff() = 0;
}
Expand Down Expand Up @@ -1428,21 +1421,21 @@ private:
}

void _Growmap(size_type _Count) { // grow map by at least _Count pointers, _Mapsize() a power of 2
static_assert(1 < _DEQUEMAPSIZ, "The _Xlen() test should always be performed.");
static_assert(1 < _Minimum_map_size, "The _Xlen() test should always be performed.");

_Alpty _Almap(_Getal());
size_type _Newsize = 0 < _Mapsize() ? _Mapsize() : 1;
while (_Newsize - _Mapsize() < _Count || _Newsize < _DEQUEMAPSIZ) {
while (_Newsize - _Mapsize() < _Count || _Newsize < _Minimum_map_size) {
// scale _Newsize to 2^N >= _Mapsize() + _Count
if (max_size() / _DEQUESIZ - _Newsize < _Newsize) {
if (max_size() / _Block_size - _Newsize < _Newsize) {
_Xlen(); // result too long
}

_Newsize *= 2;
}
_Count = _Newsize - _Mapsize();

size_type _Myboff = _Myoff() / _DEQUESIZ;
size_type _Myboff = _Myoff() / _Block_size;
_Mapptr _Newmap = _Almap.allocate(_Mapsize() + _Count);
_Mapptr _Myptr = _Newmap + _Myboff;

Expand Down Expand Up @@ -1476,7 +1469,7 @@ private:

for (size_type _Block = _Mapsize(); 0 < _Block;) { // free storage for a block and destroy pointer
if (_Map()[--_Block]) { // free block and destroy its pointer
_Getal().deallocate(_Map()[_Block], _DEQUESIZ);
_Getal().deallocate(_Map()[_Block], _Block_size);
_Destroy_in_place(_Map()[_Block]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion stl/inc/filesystem
Original file line number Diff line number Diff line change
Expand Up @@ -2112,7 +2112,7 @@ namespace filesystem {
// ALIAS file_time_type
struct _File_time_clock { // Implementation of trivial-clock
using rep = long long;
using period = ratio_multiply<ratio<_XTIME_NSECS_PER_TICK, 1>, nano>;
using period = chrono::system_clock::period;
using duration = chrono::duration<rep, period>;
using time_point = chrono::time_point<_File_time_clock>;

Expand Down
19 changes: 0 additions & 19 deletions stl/inc/functional
Original file line number Diff line number Diff line change
Expand Up @@ -1472,24 +1472,6 @@ public:
_Call_binder(_Invoker_ret<_Ret>{}, _Seq{}, _Mypair._Get_first(), _Mypair._Myval2, \
_STD forward_as_tuple(_STD forward<_Unbound>(_Unbargs)...))

#ifdef __EDG__ // TRANSITION, VSO-1132105
template <class... _Unbound>
_CONSTEXPR20 auto operator()(_Unbound&&... _Unbargs) noexcept(noexcept(_Call_binder(_Invoker_ret<_Ret>{}, _Seq{},
_STD declval<_First&>(), _STD declval<_Second&>(), _STD forward_as_tuple(_STD forward<_Unbound>(_Unbargs)...))))
-> decltype(_Call_binder(_Invoker_ret<_Ret>{}, _Seq{}, _STD declval<_First&>(), _STD declval<_Second&>(),
_STD forward_as_tuple(_STD forward<_Unbound>(_Unbargs)...))) {
return _CALL_BINDER;
}

template <class... _Unbound>
_CONSTEXPR20 auto operator()(_Unbound&&... _Unbargs) const
noexcept(noexcept(_Call_binder(_Invoker_ret<_Ret>{}, _Seq{}, _STD declval<const _First&>(),
_STD declval<const _Second&>(), _STD forward_as_tuple(_STD forward<_Unbound>(_Unbargs)...))))
-> decltype(_Call_binder(_Invoker_ret<_Ret>{}, _Seq{}, _STD declval<const _First&>(),
_STD declval<const _Second&>(), _STD forward_as_tuple(_STD forward<_Unbound>(_Unbargs)...))) {
return _CALL_BINDER;
}
#else // ^^^ workaround / no workaround vvv
template <class... _Unbound>
_CONSTEXPR20 auto operator()(_Unbound&&... _Unbargs) noexcept(noexcept(_CALL_BINDER)) -> decltype(_CALL_BINDER) {
return _CALL_BINDER;
Expand All @@ -1500,7 +1482,6 @@ public:
-> decltype(_CALL_BINDER) {
return _CALL_BINDER;
}
#endif // TRANSITION, VSO-1132105

#undef _CALL_BINDER
};
Expand Down
Loading