Skip to content
Open
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
358 changes: 218 additions & 140 deletions stl/inc/memory

Large diffs are not rendered by default.

87 changes: 53 additions & 34 deletions stl/inc/xmemory
Original file line number Diff line number Diff line change
Expand Up @@ -1601,33 +1601,38 @@ namespace ranges {
template <input_iterator _It, sentinel_for<_It> _Se, _No_throw_forward_iterator _Out,
_No_throw_sentinel_for<_Out> _OSe>
requires (constructible_from<iter_value_t<_Out>, iter_rvalue_reference_t<_It>>)
uninitialized_move_result<_It, _Out> _Uninitialized_move_unchecked(
_CONSTEXPR23 uninitialized_move_result<_It, _Out> _Uninitialized_move_unchecked(
_It _IFirst, _Se _ILast, _Out _OFirst, _OSe _OLast) {
// clang-format on
constexpr bool _Is_sized1 = sized_sentinel_for<_Se, _It>;
constexpr bool _Is_sized2 = sized_sentinel_for<_OSe, _Out>;
if constexpr (_Iter_move_cat<_It, _Out>::_Bitcopy_constructible
&& _Sized_or_unreachable_sentinel_for<_Se, _It> //
&& _Sized_or_unreachable_sentinel_for<_OSe, _Out>) {
if constexpr (_Is_sized1 && _Is_sized2) {
return _Copy_memcpy_common(_IFirst, _RANGES next(_IFirst, _STD move(_ILast)), _OFirst,
_RANGES next(_OFirst, _STD move(_OLast)));
} else if constexpr (_Is_sized1) {
return _Copy_memcpy_distance(_IFirst, _OFirst, _IFirst, _RANGES next(_IFirst, _STD move(_ILast)));
} else if constexpr (_Is_sized2) {
return _Copy_memcpy_distance(_IFirst, _OFirst, _OFirst, _RANGES next(_OFirst, _STD move(_OLast)));
} else {
_STL_ASSERT(false, "Tried to uninitialized_move two ranges with unreachable sentinels");
#if _HAS_CXX23
if (!_STD is_constant_evaluated())
#endif // _HAS_CXX23
{
if constexpr (_Is_sized1 && _Is_sized2) {
return _Copy_memcpy_common(_IFirst, _RANGES next(_IFirst, _STD move(_ILast)), _OFirst,
_RANGES next(_OFirst, _STD move(_OLast)));
} else if constexpr (_Is_sized1) {
return _Copy_memcpy_distance(_IFirst, _OFirst, _IFirst, _RANGES next(_IFirst, _STD move(_ILast)));
} else if constexpr (_Is_sized2) {
return _Copy_memcpy_distance(_IFirst, _OFirst, _OFirst, _RANGES next(_OFirst, _STD move(_OLast)));
} else {
_STL_ASSERT(false, "Tried to uninitialized_move two ranges with unreachable sentinels");
}
}
} else {
_Uninitialized_backout _Backout{_STD move(_OFirst)};
}

for (; _IFirst != _ILast && _Backout._Last != _OLast; ++_IFirst) {
_Backout._Emplace_back(_RANGES iter_move(_IFirst));
}
_Uninitialized_backout _Backout{_STD move(_OFirst)};

return {_STD move(_IFirst), _Backout._Release()};
for (; _IFirst != _ILast && _Backout._Last != _OLast; ++_IFirst) {
_Backout._Emplace_back(_RANGES iter_move(_IFirst));
}

return {_STD move(_IFirst), _Backout._Release()};
}
} // namespace ranges
#endif // __cpp_lib_concepts
Expand Down Expand Up @@ -1715,7 +1720,7 @@ _CONSTEXPR20 _NoThrowFwdIt _Uninitialized_copy_unchecked(_InIt _First, const _In
}

template <class _InIt, class _NoThrowFwdIt>
_NoThrowFwdIt uninitialized_copy(const _InIt _First, const _InIt _Last, _NoThrowFwdIt _Dest) {
_CONSTEXPR23 _NoThrowFwdIt uninitialized_copy(const _InIt _First, const _InIt _Last, _NoThrowFwdIt _Dest) {
// copy [_First, _Last) to raw [_Dest, ...)
_Adl_verify_range(_First, _Last);
auto _UFirst = _Get_unwrapped(_First);
Expand Down Expand Up @@ -1786,28 +1791,37 @@ _CONSTEXPR20 _Alloc_ptr_t<_Alloc> _Uninitialized_fill_n(
}

template <class _NoThrowFwdIt, class _Tval>
void uninitialized_fill(const _NoThrowFwdIt _First, const _NoThrowFwdIt _Last, const _Tval& _Val) {
_CONSTEXPR23 void uninitialized_fill(const _NoThrowFwdIt _First, const _NoThrowFwdIt _Last, const _Tval& _Val) {
// copy _Val throughout raw [_First, _Last)
_Adl_verify_range(_First, _Last);
auto _UFirst = _Get_unwrapped(_First);
const auto _ULast = _Get_unwrapped(_Last);
if constexpr (_Fill_memset_is_safe<_Unwrapped_t<const _NoThrowFwdIt&>, _Tval>) {
_Fill_memset(_UFirst, _Val, static_cast<size_t>(_ULast - _UFirst));
} else {
if constexpr (_Fill_zero_memset_is_safe<_Unwrapped_t<const _NoThrowFwdIt&>, _Tval>) {
#if _HAS_CXX23
if (!_STD is_constant_evaluated())
#endif // _HAS_CXX23
{
_Fill_memset(_UFirst, _Val, static_cast<size_t>(_ULast - _UFirst));
return;
}
} else if constexpr (_Fill_zero_memset_is_safe<_Unwrapped_t<const _NoThrowFwdIt&>, _Tval>) {
#if _HAS_CXX23
if (!_STD is_constant_evaluated())
#endif // _HAS_CXX23
{
if (_Is_all_bits_zero(_Val)) {
_Fill_zero_memset(_UFirst, static_cast<size_t>(_ULast - _UFirst));
return;
}
}
}

_Uninitialized_backout<_Unwrapped_t<const _NoThrowFwdIt&>> _Backout{_UFirst};
while (_Backout._Last != _ULast) {
_Backout._Emplace_back(_Val);
}

_Backout._Release();
_Uninitialized_backout<_Unwrapped_t<const _NoThrowFwdIt&>> _Backout{_UFirst};
while (_Backout._Last != _ULast) {
_Backout._Emplace_back(_Val);
}

_Backout._Release();
}

template <class _NoThrowFwdIt>
Expand Down Expand Up @@ -1849,19 +1863,24 @@ _CONSTEXPR20 _Alloc_ptr_t<_Alloc> _Uninitialized_value_construct_n(
}

template <class _NoThrowFwdIt, class _Diff>
_NoThrowFwdIt _Uninitialized_value_construct_n_unchecked1(_NoThrowFwdIt _UFirst, _Diff _Count) {
_CONSTEXPR23 _NoThrowFwdIt _Uninitialized_value_construct_n_unchecked1(_NoThrowFwdIt _UFirst, _Diff _Count) {
// value-initialize all elements in [_UFirst, _UFirst + _Count_raw)
_STL_INTERNAL_CHECK(_Count >= 0);
if constexpr (_Use_memset_value_construct_v<_NoThrowFwdIt>) {
return _Zero_range(_UFirst, _UFirst + _Count);
} else {
_Uninitialized_backout<_NoThrowFwdIt> _Backout{_UFirst};
for (; 0 < _Count; --_Count) {
_Backout._Emplace_back();
#if _HAS_CXX23
if (!_STD is_constant_evaluated())
#endif // _HAS_CXX23
{
return _Zero_range(_UFirst, _UFirst + _Count);
}
}

return _Backout._Release();
_Uninitialized_backout<_NoThrowFwdIt> _Backout{_UFirst};
for (; 0 < _Count; --_Count) {
_Backout._Emplace_back();
}

return _Backout._Release();
}

#if _HAS_DEPRECATED_TEMPORARY_BUFFER
Expand Down
26 changes: 20 additions & 6 deletions stl/inc/yvals_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@
// P2136R3 invoke_r()
// P2166R1 Prohibiting basic_string And basic_string_view Construction From nullptr
// P2186R2 Removing Garbage Collection Support
// P2283R2 constexpr Specialized Memory Algorithms

// Parallel Algorithms Notes
// C++ allows an implementation to implement parallel algorithms as calls to the serial algorithms.
Expand Down Expand Up @@ -620,6 +621,13 @@
#define _CONSTEXPR20 inline
#endif // ^^^ inline (not constexpr) in C++17 and earlier ^^^

// Functions that became constexpr in C++23
#if _HAS_CXX23
#define _CONSTEXPR23 constexpr
#else // ^^^ constexpr in C++23 and later / inline (not constexpr) in C++20 and earlier vvv
#define _CONSTEXPR23 inline
#endif // ^^^ inline (not constexpr) in C++20 and earlier ^^^

// P0607R0 Inline Variables For The STL
#if _HAS_CXX17
#define _INLINE_VAR inline
Expand Down Expand Up @@ -1219,12 +1227,12 @@
#ifndef _M_CEE
#define __cpp_lib_parallel_algorithm 201603L
#endif // _M_CEE
#define __cpp_lib_raw_memory_algorithms 201606L
#define __cpp_lib_sample 201603L
#define __cpp_lib_scoped_lock 201703L
#define __cpp_lib_shared_ptr_weak_type 201606L
#define __cpp_lib_string_view 201803L
#define __cpp_lib_to_chars 201611L

#define __cpp_lib_sample 201603L
#define __cpp_lib_scoped_lock 201703L
#define __cpp_lib_shared_ptr_weak_type 201606L
#define __cpp_lib_string_view 201803L
#define __cpp_lib_to_chars 201611L
#endif // _HAS_CXX17

// C++20
Expand Down Expand Up @@ -1390,6 +1398,12 @@
#define __cpp_lib_to_underlying 202102L
#endif // _HAS_CXX23

#if _HAS_CXX23
#define __cpp_lib_raw_memory_algorithms 202106L
#elif _HAS_CXX17 // _HAS_CXX17
#define __cpp_lib_raw_memory_algorithms 201606L
#endif // _HAS_CXX17

#define __cpp_lib_experimental_erase_if 201411L
#define __cpp_lib_experimental_filesystem 201406L

Expand Down
8 changes: 8 additions & 0 deletions tests/std/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,14 @@ tests\P1951R1_default_arguments_pair_forward_ctor
tests\P2136R3_invoke_r
tests\P2162R2_std_visit_for_derived_classes_from_variant
tests\P2231R1_complete_constexpr_optional_variant
tests\P2283R2_constexpr_uninitialized_copy
tests\P2283R2_constexpr_uninitialized_copy_n
tests\P2283R2_constexpr_uninitialized_fill
tests\P2283R2_constexpr_uninitialized_fill_n
tests\P2283R2_constexpr_uninitialized_move
tests\P2283R2_constexpr_uninitialized_move_n
tests\P2283R2_constexpr_uninitialized_value_construct
tests\P2283R2_constexpr_uninitialized_value_construct_n
tests\P2401R0_conditional_noexcept_for_exchange
tests\P2415R2_owning_view
tests\VSO_0000000_allocator_propagation
Expand Down
4 changes: 4 additions & 0 deletions tests/std/tests/P2283R2_constexpr_uninitialized_copy/env.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

RUNALL_INCLUDE ..\concepts_latest_matrix.lst
Loading