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

Reduce the amount of content included by <array> #482

Merged
merged 6 commits into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
39 changes: 0 additions & 39 deletions stl/inc/algorithm
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ _STL_DISABLE_CLANG_WARNINGS
#pragma push_macro("new")
#undef new

#if (defined(_M_IX86) || defined(_M_X64)) && !defined(_M_CEE_PURE) && !defined(_M_HYBRID)
_EXTERN_C
// See note about "noalias" in <xutility>
__declspec(noalias) void __cdecl __std_swap_ranges_trivially_swappable_noalias(
void* _First1, void* _Last1, void* _First2) noexcept;
_END_EXTERN_C
#endif // (defined(_M_IX86) || defined(_M_X64)) && !defined(_M_CEE_PURE) && !defined(_M_HYBRID)

_STD_BEGIN
// COMMON SORT PARAMETERS
_INLINE_VAR constexpr int _ISORT_MAX = 32; // maximum size for insertion sort
Expand Down Expand Up @@ -1259,38 +1251,7 @@ _NODISCARD _FwdIt1 find_first_of(_ExPo&& _Exec, const _FwdIt1 _First1, const _Fw
}
#endif // _HAS_CXX17


// FUNCTION TEMPLATE swap_ranges
template <class _FwdIt1, class _FwdIt2>
_CONSTEXPR20 _FwdIt2 _Swap_ranges_unchecked(_FwdIt1 _First1, const _FwdIt1 _Last1, _FwdIt2 _First2) {
// swap [_First1, _Last1) with [_First2, ...), no special optimization
for (; _First1 != _Last1; ++_First1, (void) ++_First2) {
_STD iter_swap(_First1, _First2);
}

return _First2;
}

#if (defined(_M_IX86) || defined(_M_X64)) && !defined(_M_CEE_PURE) && !defined(_M_HYBRID)
template <class _Ty, enable_if_t<_Is_trivially_swappable_v<_Ty>, int> = 0>
_CONSTEXPR20 _Ty* _Swap_ranges_unchecked(_Ty* _First1, _Ty* const _Last1, _Ty* _First2) {
// swap [_First1, _Last1) with [_First2, ...), trivially swappable optimization
#ifdef __cpp_lib_is_constant_evaluated
if (!_STD is_constant_evaluated())
#endif // __cpp_lib_is_constant_evaluated
{
__std_swap_ranges_trivially_swappable_noalias(_First1, _Last1, _First2);
return _First2 + (_Last1 - _First1);
}

for (; _First1 != _Last1; ++_First1, (void) ++_First2) {
_STD iter_swap(_First1, _First2);
}

return _First2;
}
#endif // (defined(_M_IX86) || defined(_M_X64)) && !defined(_M_CEE_PURE) && !defined(_M_HYBRID)

template <class _FwdIt1, class _FwdIt2>
_CONSTEXPR20 _FwdIt2 swap_ranges(const _FwdIt1 _First1, const _FwdIt1 _Last1, _FwdIt2 _First2) {
// swap [_First1, _Last1) with [_First2, ...)
Expand Down
4 changes: 1 addition & 3 deletions stl/inc/array
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
#define _ARRAY_
#include <yvals_core.h>
#if _STL_COMPILER_PREPROCESSOR
#include <algorithm>
#include <iterator>
#include <tuple>
#include <xutility>

#pragma pack(push, _CRT_PACKING)
#pragma warning(push, _STL_WARNING_LEVEL)
Expand Down
47 changes: 47 additions & 0 deletions stl/inc/iterator
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,53 @@ _STL_DISABLE_CLANG_WARNINGS
#undef new

_STD_BEGIN
// CLASS TEMPLATE back_insert_iterator
template <class _Container>
class back_insert_iterator { // wrap pushes to back of container as output iterator
public:
using iterator_category = output_iterator_tag;
using value_type = void;
using difference_type = void;
using pointer = void;
using reference = void;

using container_type = _Container;

explicit back_insert_iterator(_Container& _Cont) noexcept /* strengthened */ : container(_STD addressof(_Cont)) {}

back_insert_iterator& operator=(const typename _Container::value_type& _Val) {
container->push_back(_Val);
return *this;
}

back_insert_iterator& operator=(typename _Container::value_type&& _Val) {
container->push_back(_STD move(_Val));
return *this;
}

_NODISCARD back_insert_iterator& operator*() noexcept /* strengthened */ {
return *this;
}

back_insert_iterator& operator++() noexcept /* strengthened */ {
return *this;
}

back_insert_iterator operator++(int) noexcept /* strengthened */ {
return *this;
}

protected:
_Container* container; // pointer to container
};

// FUNCTION TEMPLATE back_inserter
template <class _Container>
_NODISCARD back_insert_iterator<_Container> back_inserter(_Container& _Cont) noexcept /* strengthened */ {
// return a back_insert_iterator
return back_insert_iterator<_Container>(_Cont);
}

// CLASS TEMPLATE front_insert_iterator
template <class _Container>
class front_insert_iterator { // wrap pushes to front of container as output iterator
Expand Down
82 changes: 82 additions & 0 deletions stl/inc/xlocinfo
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,88 @@ private:
void* _Timeptr; // pointer to time information
};

// CLASS TEMPLATE _Yarn
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
template <class _Elem>
class _CRTIMP2_PURE_IMPORT _Yarn { // wrap a NTCTS
public:
__CLR_OR_THIS_CALL _Yarn() noexcept : _Myptr(nullptr), _Nul(0) {}

__CLR_OR_THIS_CALL _Yarn(const _Yarn& _Right) noexcept : _Myptr(nullptr), _Nul(0) {
*this = _Right;
}

__CLR_OR_THIS_CALL _Yarn(const _Elem* _Right) noexcept : _Myptr(nullptr), _Nul(0) {
*this = _Right;
}

_Yarn& __CLR_OR_THIS_CALL operator=(const _Yarn& _Right) noexcept {
return *this = _Right._Myptr;
}

_Yarn& __CLR_OR_THIS_CALL operator=(const _Elem* _Right) noexcept {
if (_Myptr != _Right) { // new value, discard old and copy new
_Tidy();

if (_Right) { // new is not empty, copy it
const _Elem* _Ptr = _Right;
while (*_Ptr != _Elem{}) {
++_Ptr;
}

const auto _Count = (++_Ptr - _Right) * sizeof(_Elem);

#ifdef _DEBUG
_Myptr = static_cast<_Elem*>(_malloc_dbg(_Count, _CRT_BLOCK, __FILE__, __LINE__));
#else // _DEBUG
_Myptr = static_cast<_Elem*>(_CSTD malloc(_Count));
#endif // _DEBUG

if (_Myptr) {
_CSTD memcpy(_Myptr, _Right, _Count);
}
}
}

return *this;
}

__CLR_OR_THIS_CALL ~_Yarn() noexcept {
_Tidy();
}

_NODISCARD bool __CLR_OR_THIS_CALL empty() const noexcept {
return _Myptr == nullptr;
}

_Ret_z_ const _Elem* __CLR_OR_THIS_CALL c_str() const noexcept {
return _Myptr ? _Myptr : &_Nul;
}

_NODISCARD bool __CLR_OR_THIS_CALL _Empty() const noexcept {
return _Myptr == nullptr;
}

_Ret_z_ const _Elem* __CLR_OR_THIS_CALL _C_str() const noexcept {
return _Myptr ? _Myptr : &_Nul;
}

private:
void __CLR_OR_THIS_CALL _Tidy() noexcept {
if (_Myptr) {
#ifdef _DEBUG
_free_dbg(_Myptr, _CRT_BLOCK);
#else // _DEBUG
_CSTD free(_Myptr);
#endif // _DEBUG
}

_Myptr = nullptr;
}

_Elem* _Myptr; // pointer to allocated string
_Elem _Nul; // nul terminator for unallocated string
};

// CLASS _Locinfo
class _CRTIMP2_PURE_IMPORT _Locinfo { // summary of all stuff specific to a locale used by standard facets
public:
Expand Down
27 changes: 27 additions & 0 deletions stl/inc/xmemory
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,33 @@ _STL_DISABLE_CLANG_WARNINGS
#undef new

_STD_BEGIN
// STRUCT TEMPLATE _Tidy_guard
template <class _Ty>
struct _Tidy_guard { // class with destructor that calls _Tidy
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
_Ty* _Target;
~_Tidy_guard() {
if (_Target) {
_Target->_Tidy();
}
}
};

// STRUCT TEMPLATE _Tidy_deallocate_guard
template <class _Ty>
struct _Tidy_deallocate_guard { // class with destructor that calls _Tidy_deallocate
_Ty* _Target;
~_Tidy_deallocate_guard() {
if (_Target) {
_Target->_Tidy_deallocate();
}
}
};

// VARIABLE TEMPLATE _Nothrow_compare
template <class _Keycmp, class _Lhs, class _Rhs>
_INLINE_VAR constexpr bool _Nothrow_compare = noexcept(
static_cast<bool>(_STD declval<const _Keycmp&>()(_STD declval<const _Lhs&>(), _STD declval<const _Rhs&>())));

// FUNCTION TEMPLATE _Get_size_of_n
template <size_t _Ty_size>
_NODISCARD constexpr size_t _Get_size_of_n(const size_t _Count) {
Expand Down
Loading