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

Use iterator concept in vector's range constructor #1794

Merged
merged 14 commits into from
Jun 12, 2022
Merged
Changes from 5 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
43 changes: 39 additions & 4 deletions stl/inc/vector
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,16 @@ private:

template <class _Iter>
_CONSTEXPR20_CONTAINER void _Range_construct_or_tidy(_Iter _First, _Iter _Last, forward_iterator_tag) {
#ifdef __cpp_lib_concepts
size_type _Count;
if constexpr (forward_iterator<_Iter>) {
AdamBucior marked this conversation as resolved.
Show resolved Hide resolved
_Count = _Convert_size<size_type>(static_cast<size_t>(_RANGES distance(_First, _Last)));
} else {
_Count = _Convert_size<size_type>(static_cast<size_t>(_STD distance(_First, _Last)));
}
#else // ^^^ __cpp_lib_concepts ^^^ / vvv !__cpp_lib_concepts vvv
const auto _Count = _Convert_size<size_type>(static_cast<size_t>(_STD distance(_First, _Last)));
#endif // ^^^ !__cpp_lib_concepts ^^^
if (_Count != 0) {
_Buy_nonzero(_Count);
_Tidy_guard<vector> _Guard{this};
Expand All @@ -539,7 +548,15 @@ public:
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alty, _Getal());
_Container_proxy_ptr<_Alty> _Proxy(_Alproxy, _Mypair._Myval2);
_Adl_verify_range(_First, _Last);
#ifdef __cpp_lib_concepts
if constexpr (derived_from<_Iter_concept<_Iter>, _Iter_cat_t<_Iter>>) {
_Range_construct_or_tidy(_Get_unwrapped(_First), _Get_unwrapped(_Last), _Iter_concept<_Iter>{});
} else {
_Range_construct_or_tidy(_Get_unwrapped(_First), _Get_unwrapped(_Last), _Iter_cat_t<_Iter>{});
}
#else // ^^^ __cpp_lib_concepts ^^^ / vvv !__cpp_lib_concepts vvv
_Range_construct_or_tidy(_Get_unwrapped(_First), _Get_unwrapped(_Last), _Iter_cat_t<_Iter>{});
#endif // ^^^ !__cpp_lib_concepts ^^^
_Proxy._Release();
}

Expand Down Expand Up @@ -1137,11 +1154,20 @@ private:
template <class _Iter>
_CONSTEXPR20_CONTAINER void _Assign_range(_Iter _First, _Iter _Last, forward_iterator_tag) {
// assign forward range [_First, _Last)
#ifdef __cpp_lib_concepts
size_type _Newsize;
if constexpr (forward_iterator<_Iter>) {
AdamBucior marked this conversation as resolved.
Show resolved Hide resolved
_Newsize = _Convert_size<size_type>(static_cast<size_t>(_RANGES distance(_First, _Last)));
} else {
_Newsize = _Convert_size<size_type>(static_cast<size_t>(_STD distance(_First, _Last)));
}
#else // ^^^ __cpp_lib_concepts ^^^ / vvv !__cpp_lib_concepts vvv
const auto _Newsize = _Convert_size<size_type>(static_cast<size_t>(_STD distance(_First, _Last)));
auto& _My_data = _Mypair._Myval2;
pointer& _Myfirst = _My_data._Myfirst;
pointer& _Mylast = _My_data._Mylast;
pointer& _Myend = _My_data._Myend;
#endif // ^^^ !__cpp_lib_concepts ^^^
auto& _My_data = _Mypair._Myval2;
pointer& _Myfirst = _My_data._Myfirst;
pointer& _Mylast = _My_data._Mylast;
pointer& _Myend = _My_data._Myend;

_My_data._Orphan_all();

Expand Down Expand Up @@ -1187,6 +1213,15 @@ public:
_CONSTEXPR20_CONTAINER void assign(_Iter _First, _Iter _Last) {
_Adl_verify_range(_First, _Last);
_Assign_range(_Get_unwrapped(_First), _Get_unwrapped(_Last), _Iter_cat_t<_Iter>{});
#ifdef __cpp_lib_concepts
if constexpr (derived_from<_Iter_concept<_Iter>, _Iter_cat_t<_Iter>>) {
_Assign_range(_Get_unwrapped(_First), _Get_unwrapped(_Last), _Iter_concept<_Iter>{});
} else {
_Assign_range(_Get_unwrapped(_First), _Get_unwrapped(_Last), _Iter_cat_t<_Iter>{});
}
#else // ^^^ __cpp_lib_concepts ^^^ / vvv !__cpp_lib_concepts vvv
_Assign_range(_Get_unwrapped(_First), _Get_unwrapped(_Last), _Iter_cat_t<_Iter>{});
#endif // ^^^ !__cpp_lib_concepts ^^^
}

_CONSTEXPR20_CONTAINER void assign(initializer_list<_Ty> _Ilist) {
Expand Down