Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@frederick-vs-ja
Copy link
Contributor

@frederick-vs-ja frederick-vs-ja commented Feb 22, 2024

Follows up #4260.

Affected algorithms:

  • reduce
  • transform_reduce
  • exclusive_scan
  • inclusive_scan
  • transform_exclusive_scan
  • transform_inclusive_scan

The standard wording only uses "convertible" (from the results of operations to the element type) in the requirements of these algorithms, so direct-initialization can be sometimes wrong.

The construction from _Transform_op(*_First) seems incorrect for meowscan algorithms as the standard doesn't seem to require this. See also #3783. Perhaps we should remove such construction later.

_Implicitly_construct_in_place_meow function templates are added for performing implicit conversion in placements new and avoiding additional move, which may be important for WG21-P2408R5.

@frederick-vs-ja frederick-vs-ja requested a review from a team as a code owner February 22, 2024 23:47
@frederick-vs-ja frederick-vs-ja changed the title <numeric>: Change improper direct-initialization to copy-initialization in C++17 numeric algorithms <execution>, <numeric>: Change improper direct-initialization to copy-initialization in C++17 numeric algorithms Feb 22, 2024
@StephanTLavavej StephanTLavavej added the bug Something isn't working label Feb 23, 2024
- s/_Implicit_construct/_Implicitly_construct
- Restore some default-initialization
@frederick-vs-ja frederick-vs-ja force-pushed the fix-parallel-numeric-conv branch from ec79508 to 3f811a9 Compare February 23, 2024 02:35
@frederick-vs-ja

This comment was marked as resolved.

@StephanTLavavej StephanTLavavej self-assigned this Feb 23, 2024

template <class _Ty, class _BinaryOp, class _ArgTy>
void _Implicitly_construct_in_place_by_binary_op(_Ty& _Val, _BinaryOp& _Reduce_op, _ArgTy& _Left, _ArgTy& _Right) {
::new (static_cast<void*>(_STD addressof(_Val))) _Ty([&]() -> _Ty { return _Reduce_op(_Left, _Right); }());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And capturing it by reference too. Ditto below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point is performing implicit conversion in placement new with workaround for imperfectness of forwarding. So I guess copying should be avoided.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with capturing by reference since it doesn't affect the function signature, even though it should be a reference to a _Pass_fn.


template <class _Ty, class _BinaryOp, class _ArgTy>
void _Implicitly_construct_in_place_by_binary_op(_Ty& _Val, _BinaryOp& _Reduce_op, _ArgTy& _Left, _ArgTy& _Right) {
::new (static_cast<void*>(_STD addressof(_Val))) _Ty([&]() -> _Ty { return _Reduce_op(_Left, _Right); }());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with capturing by reference since it doesn't affect the function signature, even though it should be a reference to a _Pass_fn.

@StephanTLavavej
Copy link
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej StephanTLavavej merged commit 76599ca into microsoft:main Feb 29, 2024
@StephanTLavavej
Copy link
Member

Thanks for fixing these algorithms! 🛠️ 🧮 🪄

@frederick-vs-ja frederick-vs-ja deleted the fix-parallel-numeric-conv branch February 29, 2024 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants