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

Casey's miscellaneous changes, definitive edition #5014

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 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
14 changes: 5 additions & 9 deletions stl/inc/__msvc_ranges_to.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1180,18 +1180,14 @@ namespace ranges {

template <input_range _Rng>
struct _Phony_input_iterator {
using iterator_category = input_iterator_tag;
using value_type = range_value_t<_Rng>;
using difference_type = ptrdiff_t;
using pointer = add_pointer_t<range_reference_t<_Rng>>;
using reference = range_reference_t<_Rng>;

reference operator*() const;
pointer operator->() const;
using value_type = range_value_t<_Rng>;
using difference_type = ptrdiff_t;

// These member functions are never defined:
range_reference_t<_Rng> operator*() const;
add_pointer_t<range_reference_t<_Rng>> operator->() const;
_Phony_input_iterator& operator++();
_Phony_input_iterator operator++(int);

bool operator==(const _Phony_input_iterator&) const;
};

Expand Down
2 changes: 1 addition & 1 deletion stl/inc/__msvc_ranges_tuple_formatter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -880,8 +880,8 @@ template <class _CharT>
struct _Phony_fmt_iter_for {
using difference_type = ptrdiff_t;

// These member functions are never defined:
_CharT& operator*() const;

_Phony_fmt_iter_for& operator++();
_Phony_fmt_iter_for operator++(int);
};
Expand Down
4 changes: 2 additions & 2 deletions stl/inc/algorithm
Original file line number Diff line number Diff line change
Expand Up @@ -8487,7 +8487,7 @@ _Ty* _Uninitialized_merge_move(_FwdIt _First, const _FwdIt _Mid, const _FwdIt _L
}

template <class _InIt, class _OutIt, class _Pr>
_OutIt _Merge_move(_InIt _First, const _InIt _Mid, const _InIt _Last, _OutIt _Dest, _Pr _Pred) {
_OutIt _Merge_move_unchecked(_InIt _First, const _InIt _Mid, const _InIt _Last, _OutIt _Dest, _Pr _Pred) {
// move merging adjacent ranges [_First, _Mid) and [_Mid, _Last) to _Dest
// pre: _First != _Mid && _Mid != _Last
_InIt _Next = _Mid;
Expand Down Expand Up @@ -8545,7 +8545,7 @@ void _Chunked_merge_unchecked(_BidIt _First, const _BidIt _Last, _OutIt _Dest, c
const auto _Chunk2 = (_STD min)(_Chunk, _Count);
_Count -= _Chunk2;
const _BidIt _Mid2 = _STD next(_Mid1, _Chunk2);
_Dest = _STD _Merge_move(_First, _Mid1, _Mid2, _Dest, _Pred);
_Dest = _STD _Merge_move_unchecked(_First, _Mid1, _Mid2, _Dest, _Pred);
_First = _Mid2;
}

Expand Down
17 changes: 13 additions & 4 deletions stl/inc/array
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ public:
using reverse_iterator = _STD reverse_iterator<iterator>;
using const_reverse_iterator = _STD reverse_iterator<const_iterator>;

using _Library_defined = array;

#if _HAS_TR1_NAMESPACE
_DEPRECATE_TR1_NAMESPACE void assign(const _Ty& _Value) {
_STD fill_n(_Elems, _Size, _Value);
Expand Down Expand Up @@ -610,6 +612,8 @@ public:
using reverse_iterator = _STD reverse_iterator<iterator>;
using const_reverse_iterator = _STD reverse_iterator<const_iterator>;

using _Library_defined = array;

#if _HAS_TR1_NAMESPACE
_DEPRECATE_TR1_NAMESPACE void assign(const _Ty&) {}
#endif // _HAS_TR1_NAMESPACE
Expand Down Expand Up @@ -844,10 +848,15 @@ _NODISCARD constexpr array<remove_cv_t<_Ty>, _Size> to_array(_Ty (&&_Array)[_Siz
}
#endif // _HAS_CXX20

template <class _Ty, class _Enable = void>
constexpr bool _Is_library_defined = false;
template <class _Ty>
constexpr bool _Is_library_defined<_Ty, enable_if_t<is_same_v<typename _Ty::_Library_defined, _Ty>>> = true;

_EXPORT_STD template <size_t _Idx, class _Ty, size_t _Size>
_NODISCARD constexpr _Ty& get(array<_Ty, _Size>& _Arr) noexcept {
static_assert(_Idx < _Size, "array index out of bounds");
if constexpr (_Has_unchecked_begin_end<array<_Ty, _Size>>) {
if constexpr (_Is_library_defined<array<_Ty, _Size>>) {
return _Arr._Elems[_Idx];
} else {
#if _HAS_CXX17
Expand All @@ -861,7 +870,7 @@ _NODISCARD constexpr _Ty& get(array<_Ty, _Size>& _Arr) noexcept {
_EXPORT_STD template <size_t _Idx, class _Ty, size_t _Size>
_NODISCARD constexpr const _Ty& get(const array<_Ty, _Size>& _Arr) noexcept {
static_assert(_Idx < _Size, "array index out of bounds");
if constexpr (_Has_unchecked_begin_end<array<_Ty, _Size>>) {
if constexpr (_Is_library_defined<array<_Ty, _Size>>) {
return _Arr._Elems[_Idx];
} else {
return _Arr[_Idx];
Expand All @@ -871,7 +880,7 @@ _NODISCARD constexpr const _Ty& get(const array<_Ty, _Size>& _Arr) noexcept {
_EXPORT_STD template <size_t _Idx, class _Ty, size_t _Size>
_NODISCARD constexpr _Ty&& get(array<_Ty, _Size>&& _Arr) noexcept {
static_assert(_Idx < _Size, "array index out of bounds");
if constexpr (_Has_unchecked_begin_end<array<_Ty, _Size>>) {
if constexpr (_Is_library_defined<array<_Ty, _Size>>) {
return _STD move(_Arr._Elems[_Idx]);
} else {
#if _HAS_CXX17
Expand All @@ -885,7 +894,7 @@ _NODISCARD constexpr _Ty&& get(array<_Ty, _Size>&& _Arr) noexcept {
_EXPORT_STD template <size_t _Idx, class _Ty, size_t _Size>
_NODISCARD constexpr const _Ty&& get(const array<_Ty, _Size>&& _Arr) noexcept {
static_assert(_Idx < _Size, "array index out of bounds");
if constexpr (_Has_unchecked_begin_end<array<_Ty, _Size>>) {
if constexpr (_Is_library_defined<array<_Ty, _Size>>) {
return _STD move(_Arr._Elems[_Idx]);
} else {
return _STD move(_Arr[_Idx]);
Expand Down
4 changes: 2 additions & 2 deletions stl/inc/execution
Original file line number Diff line number Diff line change
Expand Up @@ -2945,7 +2945,7 @@ struct _Static_partitioned_stable_sort3 {
const size_t _Base = _Visitor._Base;
const size_t _Mid = _Base + _Visitor._Shift;
const size_t _End = _Mid + _Visitor._Shift;
_STD _Merge_move(_Temp_buf._Get_first(_Base), _Temp_buf._Get_first(_Mid),
_STD _Merge_move_unchecked(_Temp_buf._Get_first(_Base), _Temp_buf._Get_first(_Mid),
_Temp_buf._Get_first(_End), _Basis._Get_first(_Base, _Team._Get_chunk_offset(_Base)), _Pred);
}

Expand All @@ -2963,7 +2963,7 @@ struct _Static_partitioned_stable_sort3 {
const size_t _Base = _Visitor._Base;
const size_t _Mid = _Base + _Visitor._Shift;
const size_t _End = _Mid + _Visitor._Shift;
_STD _Merge_move(_Basis._Get_first(_Base, _Team._Get_chunk_offset(_Base)),
_STD _Merge_move_unchecked(_Basis._Get_first(_Base, _Team._Get_chunk_offset(_Base)),
_Basis._Get_first(_Mid, _Team._Get_chunk_offset(_Mid)),
_Basis._Get_first(_End, _Team._Get_chunk_offset(_End)), _Temp_buf._Get_first(_Base), _Pred);
}
Expand Down
18 changes: 9 additions & 9 deletions stl/inc/format
Original file line number Diff line number Diff line change
Expand Up @@ -398,15 +398,15 @@ private:
_GB11_LeftHand_regex _GB11_rx;

public:
using value_type = iter_value_t<_Wrapped_iter_type>;
using difference_type = ptrdiff_t;

_NODISCARD constexpr bool operator==(default_sentinel_t) const noexcept {
return _WrappedIter == default_sentinel;
}

_NODISCARD constexpr bool operator==(const _Grapheme_break_property_iterator&) const noexcept = default;

using difference_type = ptrdiff_t;
using value_type = iter_value_t<_Wrapped_iter_type>;

constexpr _Grapheme_break_property_iterator(const _CharT* _First, const _CharT* _Last)
: _WrappedIter(_First, _Last) {}

Expand Down Expand Up @@ -2388,15 +2388,15 @@ private:
_Grapheme_break_property_iterator<_CharT> _WrappedIter;

public:
using value_type = int;
using difference_type = ptrdiff_t;

_NODISCARD constexpr bool operator==(const _Measure_string_prefix_iterator_utf&) const noexcept = default;

_NODISCARD constexpr bool operator==(default_sentinel_t) const noexcept {
return _WrappedIter == default_sentinel;
}

using difference_type = ptrdiff_t;
using value_type = int;

constexpr _Measure_string_prefix_iterator_utf(const _CharT* _First, const _CharT* _Last)
: _WrappedIter(_First, _Last) {}

Expand Down Expand Up @@ -2438,16 +2438,16 @@ private:
}

public:
using value_type = int;
using difference_type = ptrdiff_t;

_NODISCARD bool operator==(default_sentinel_t) const noexcept {
return _First == _Last;
}
_NODISCARD bool operator==(const _Measure_string_prefix_iterator_legacy& _Rhs) const noexcept {
return _First == _Rhs._First && _Last == _Rhs._Last;
}

using difference_type = ptrdiff_t;
using value_type = int;

_Measure_string_prefix_iterator_legacy(const char* _First_val, const char* _Last_val)
: _First(_First_val), _Last(_Last_val) {
_Update_units();
Expand Down
18 changes: 6 additions & 12 deletions stl/inc/print
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,12 @@ struct _NODISCARD _Stream_lock_guard {

class _Print_to_stream_it {
public:
using iterator_category = output_iterator_tag;
using value_type = void;
using difference_type = ptrdiff_t;
using pointer = void;
using reference = void;
using difference_type = ptrdiff_t;

explicit _Print_to_stream_it(FILE* const _Stream_) noexcept : _Stream(_Stream_) {}

_Print_to_stream_it& operator=(char); // These members are intentionally not defined
// These member functions are never defined:
_Print_to_stream_it& operator=(char);
_Print_to_stream_it& operator*();
_Print_to_stream_it& operator++();
_Print_to_stream_it operator++(int);
Expand Down Expand Up @@ -79,16 +76,13 @@ struct _Fmt_iterator_flush<_Print_to_stream_it> {

class _Print_to_unicode_console_it {
public:
using iterator_category = output_iterator_tag;
using value_type = void;
using difference_type = ptrdiff_t;
using pointer = void;
using reference = void;
using difference_type = ptrdiff_t;

explicit _Print_to_unicode_console_it(const __std_unicode_console_handle _Console_handle_) noexcept
: _Console_handle(_Console_handle_) {}

_Print_to_unicode_console_it& operator=(char); // These members are intentionally not defined
// These member functions are never defined:
_Print_to_unicode_console_it& operator=(char);
_Print_to_unicode_console_it& operator*();
_Print_to_unicode_console_it& operator++();
_Print_to_unicode_console_it operator++(int);
Expand Down
4 changes: 2 additions & 2 deletions stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -7158,7 +7158,7 @@ namespace ranges {
private:
friend zip_view;

#ifdef __clang__ // TRANSITION, need to reduce and report (was thought to be LLVM-61763)
#if defined(__clang__) && __clang_major__ <= 18 // TRANSITION, Clang 19 (was thought to be LLVM-61763)
public:
#else // ^^^ workaround / no workaround vvv
template <class _Func, class... _OtherViews>
Expand Down Expand Up @@ -7983,7 +7983,7 @@ namespace ranges {
private:
friend adjacent_view;

#ifdef __clang__ // TRANSITION, need to reduce and report (was thought to be LLVM-61763)
#if defined(__clang__) && __clang_major__ <= 18 // TRANSITION, Clang 19 (was thought to be LLVM-61763)
public:
#else // ^^^ workaround / no workaround vvv
template <class _Vw2, class _Fn, size_t _Nx2>
Expand Down
35 changes: 19 additions & 16 deletions stl/inc/xmemory
Original file line number Diff line number Diff line change
Expand Up @@ -92,37 +92,33 @@ _NODISCARD constexpr size_t _Get_size_of_n(const size_t _Count) {
template <class _Ty>
constexpr size_t _New_alignof = (_STD max)(alignof(_Ty), __STDCPP_DEFAULT_NEW_ALIGNMENT__);

struct _Default_allocate_traits {
__declspec(allocator) static
#ifdef __clang__ // Clang and MSVC implement P0784R7 differently; see GH-1532
_CONSTEXPR20
#endif // defined(__clang__)
void*
_Allocate(const size_t _Bytes) {
#define _CLANG_CONSTEXPR20 _CONSTEXPR20
#else // ^^^ Clang / Other vvv
#define _CLANG_CONSTEXPR20
#endif // ^^^ Other ^^^

struct _Default_allocate_traits {
__declspec(allocator) static _CLANG_CONSTEXPR20 void* _Allocate(const size_t _Bytes) {
return ::operator new(_Bytes);
}

#ifdef __cpp_aligned_new
__declspec(allocator) static
#ifdef __clang__ // Clang and MSVC implement P0784R7 differently; see GH-1532
_CONSTEXPR20
#endif // defined(__clang__)
void*
_Allocate_aligned(const size_t _Bytes, const size_t _Align) {
#ifdef __clang__ // Clang and MSVC implement P0784R7 differently; see GH-1532
#if _HAS_CXX20
__declspec(allocator) static _CLANG_CONSTEXPR20 void* _Allocate_aligned(const size_t _Bytes, const size_t _Align) {
#if defined(__clang__) && _HAS_CXX20 // Ditto, "Clang and MSVC implement P0784R7 differently"
if (_STD is_constant_evaluated()) {
return ::operator new(_Bytes);
} else
#endif // _HAS_CXX20
#endif // defined(__clang__)
#endif // ^^^ defined(__clang__) && _HAS_CXX20 ^^^
{
return ::operator new(_Bytes, align_val_t{_Align});
}
}
#endif // defined(__cpp_aligned_new)
};

#undef _CLANG_CONSTEXPR20

constexpr bool _Is_pow_2(const size_t _Value) noexcept {
return _Value != 0 && (_Value & (_Value - 1)) == 0;
}
Expand Down Expand Up @@ -1797,6 +1793,8 @@ _CONSTEXPR20 _Alloc_ptr_t<_Alloc> _Uninitialized_copy(
// note: only called internally from elsewhere in the STL
using _Ptrval = typename _Alloc::value_type*;

_STL_INTERNAL_CHECK((_STD _Adl_verify_range(_First, _Last), true));
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved

#if _HAS_CXX20
auto _UFirst = _RANGES _Unwrap_iter<_Se>(_STD move(_First));
auto _ULast = _RANGES _Unwrap_sent<_InIt>(_STD move(_Last));
Expand Down Expand Up @@ -1842,7 +1840,11 @@ _CONSTEXPR20 _Alloc_ptr_t<_Alloc> _Uninitialized_copy_n(
// note: only called internally from elsewhere in the STL
using _Ptrval = typename _Alloc::value_type*;

#ifdef _ENABLE_STL_INTERNAL_CHECK
auto _UFirst = _STD _Get_unwrapped_n(_STD move(_First), _Count);
#else // ^^^ Checking / No checking ^^^
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
auto _UFirst = _STD _Get_unwrapped(_STD move(_First));
#endif // ^^^ No checking ^^^

constexpr bool _Can_memmove =
conjunction_v<bool_constant<_Iter_copy_cat<decltype(_UFirst), _Ptrval>::_Bitcopy_constructible>,
Expand Down Expand Up @@ -1903,6 +1905,7 @@ _CONSTEXPR20 _Alloc_ptr_t<_Alloc> _Uninitialized_move(
const _InIt _First, const _InIt _Last, _Alloc_ptr_t<_Alloc> _Dest, _Alloc& _Al) {
// move [_First, _Last) to raw _Dest, using _Al
// note: only called internally from elsewhere in the STL
_STL_INTERNAL_CHECK((_STD _Adl_verify_range(_First, _Last), true));
using _Ptrval = typename _Alloc::value_type*;
auto _UFirst = _STD _Get_unwrapped(_First);
const auto _ULast = _STD _Get_unwrapped(_Last);
Expand Down
27 changes: 9 additions & 18 deletions stl/inc/xutility
Original file line number Diff line number Diff line change
Expand Up @@ -777,13 +777,6 @@ struct _Unused_parameter { // generic unused parameter struct
constexpr _Unused_parameter(_Ty&&) noexcept {}
};

template <class _Ty, class = void> // checks whether a container/view is a non-customized specialization
constexpr bool _Has_unchecked_begin_end = false;

template <class _Ty>
constexpr bool _Has_unchecked_begin_end<_Ty,
void_t<decltype(_STD declval<_Ty&>()._Unchecked_begin()), decltype(_STD declval<_Ty&>()._Unchecked_end())>> = true;

template <class _Ty>
using _Algorithm_int_t = conditional_t<is_integral_v<_Ty>, _Ty, ptrdiff_t>;

Expand Down Expand Up @@ -3966,12 +3959,15 @@ namespace ranges {
template <_Convertible_to_non_slicing<_It> _It2>
constexpr subrange(_It2 _First_, _Se _Last_)
requires (!_Store_size<_It, _Se, _Ki>)
: _First(_STD move(_First_)), _Last(_STD move(_Last_)) {}
: _First(_STD move(_First_)), _Last(_STD move(_Last_)) {
_STD _Adl_verify_range(_First, _Last);
}

template <_Convertible_to_non_slicing<_It> _It2>
constexpr subrange(_It2 _First_, _Se _Last_, const _Size_type _Size_)
requires (_Ki == subrange_kind::sized)
: _Subrange_base<_It, _Se, _Ki>(_Size_), _First(_STD move(_First_)), _Last(_STD move(_Last_)) {
_STD _Adl_verify_range(_First, _Last);
if constexpr (sized_sentinel_for<_Se, _It>) {
_STL_ASSERT(_Size_ == static_cast<_Size_type>(_Last - _First),
"This constructor's third argument should be equal to the distance "
Expand Down Expand Up @@ -4523,16 +4519,11 @@ template <class _Iter1, class _Iter2>
requires (!sized_sentinel_for<_Iter1, _Iter2>)
constexpr bool disable_sized_sentinel_for<move_iterator<_Iter1>, move_iterator<_Iter2>> = true;

_EXPORT_STD struct unreachable_sentinel_t;
namespace _Unreachable_sentinel_detail {
struct _Base {
template <weakly_incrementable _Winc>
_NODISCARD friend constexpr bool operator==(const unreachable_sentinel_t&, const _Winc&) noexcept {
return false;
}
};
} // namespace _Unreachable_sentinel_detail
_EXPORT_STD struct unreachable_sentinel_t : _Unreachable_sentinel_detail::_Base {}; // TRANSITION, /permissive-
_EXPORT_STD struct unreachable_sentinel_t {
_NODISCARD constexpr bool operator==(const weakly_incrementable auto&) const noexcept {
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
return false;
}
};

_EXPORT_STD inline constexpr unreachable_sentinel_t unreachable_sentinel{};
#endif // _HAS_CXX20
Expand Down
5 changes: 2 additions & 3 deletions tests/std/include/range_algorithm_support.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,8 @@ namespace test {

template <class T>
struct init_list_not_constructible_iterator {
using iterator_category = std::forward_iterator_tag;
using difference_type = int;
using value_type = T;
using value_type = T;
using difference_type = int;

init_list_not_constructible_iterator() = default;
init_list_not_constructible_iterator(T*) {}
Expand Down
Loading