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

<valarray>: Make valarray ADL-proof as required #5157

Merged
merged 2 commits into from
Dec 5, 2024
Merged
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
12 changes: 6 additions & 6 deletions stl/inc/valarray
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public:
}

valarray(const _Ty& _Val, size_t _Count) { // construct with _Count * _Val
_Grow(_Count, &_Val);
_Grow(_Count, _STD addressof(_Val));
}

valarray(const _Ty* _Ptr, size_t _Count) { // construct with [_Ptr, _Ptr + _Count)
Expand Down Expand Up @@ -162,7 +162,7 @@ public:

void resize(size_t _Newsize, _Ty _Val) { // determine new length, filling with _Val elements
_Tidy_deallocate();
_Grow(_Newsize, &_Val, 0);
_Grow(_Newsize, _STD addressof(_Val), 0);
}

valarray& operator=(const slice_array<_Ty>& _Slicearr); // defined below
Expand Down Expand Up @@ -538,7 +538,7 @@ private:
_Myptr = _Allocate_for_op_delete<_Ty>(_Newsize);
_Tidy_deallocate_guard<valarray> _Guard{this};
for (size_t _Idx = 0; _Idx < _Newsize; ++_Idx) {
_Construct_in_place(_Myptr[_Idx]);
_STD _Construct_in_place(_Myptr[_Idx]);
}

_Guard._Target = nullptr;
Expand All @@ -552,7 +552,7 @@ private:
_Myptr = _Allocate_for_op_delete<_Ty>(_Newsize);
_Tidy_deallocate_guard<valarray> _Guard{this};
for (size_t _Idx = 0; _Idx < _Newsize; ++_Idx, _Ptr += _Inc) {
_Construct_in_place(_Myptr[_Idx], *_Ptr);
_STD _Construct_in_place(_Myptr[_Idx], *_Ptr);
}

_Guard._Target = nullptr;
Expand All @@ -562,7 +562,7 @@ private:

void _Tidy_deallocate() noexcept {
if (_Myptr) { // destroy elements
_Destroy_range(_Myptr, _Myptr + _Mysize);
_STD _Destroy_range(_Myptr, _Myptr + _Mysize);
#ifdef __cpp_aligned_new
constexpr bool _Extended_alignment = alignof(_Ty) > __STDCPP_DEFAULT_NEW_ALIGNMENT__;
if constexpr (_Extended_alignment) {
Expand Down Expand Up @@ -2028,7 +2028,7 @@ private:
template <class _Ty>
valarray<_Ty>& valarray<_Ty>::operator=(const slice_array<_Ty>& _Slicearr) {
_Tidy_deallocate();
_Grow(_Slicearr.size(), &_Slicearr._Data(_Slicearr.start()), _Slicearr.stride());
_Grow(_Slicearr.size(), _STD addressof(_Slicearr._Data(_Slicearr.start())), _Slicearr.stride());
return *this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <future>
#include <memory>
#include <type_traits>
#include <utility>
#include <valarray>
#if _HAS_CXX17
#include <optional>
#endif // _HAS_CXX17
Expand Down Expand Up @@ -79,15 +81,15 @@ template <class Tag>
struct tagged_identity {
template <class U>
constexpr U&& operator()(U&& u) const noexcept {
return static_cast<U&&>(u);
return std::forward<U>(u);
}
};

template <class Tag>
struct tagged_large_identity {
template <class U>
constexpr U&& operator()(U&& u) const noexcept {
return static_cast<U&&>(u);
return std::forward<U>(u);
}

alignas(64) unsigned char unused[64]{};
Expand Down Expand Up @@ -145,6 +147,25 @@ void test_promise() {
promise<validator&>{allocator_arg, adl_proof_allocator<unsigned char>{}};
}

void test_valarray() {
using validator_class = holder<validator>;

valarray<validator_class> valarr1(42);

validator_class a[1]{};
valarray<validator_class> valarr2(a, 1);
valarr2.resize(172, a[0]);

valarray<validator_class> valarr3(a[0], 1);
valarr3 = valarr2[slice{0, 1, 1}];

auto valarr4 = valarr1;
valarr4 = valarr1;

auto valarr5 = std::move(valarr2);
valarr5 = std::move(valarr3);
}

#if _HAS_CXX17
void test_optional() {
optional<validator> o{};
Expand Down