Commit d45c47b
Ryan Haining
Updates FnPartials to move stored_arg when rvalue
Overloads `operator|` for rvalue and lvalue `Pipeable`s and downcasts
accordingly.
Adds rvalue-reference qualified overloads to FnPartial `operator|`
that calls `std::move(stored_arg)` when creating the actual iterable
object.
This allows a move-only callable to get passed by value, but only moves,
all the way into the itertool.
```
// both should work
iter::some_itertool(sequence, MoveOnlyCallable{});
sequence | iter::some_itertool(MoveOnlyCallable{});
```
I did attempt passing a `std::reference_wrapper` from the `FnPartial`
but the iteration happens after the `FnPartial` is destroyed, So the
following is unsafe:
```
// unsafe, wrong
template <typename Container>
auto operator()(Container&& container) const {
if constexpr (std::is_copy_constructible_v<T>) {
return F{}(stored_arg, std::forward<Container>(container));
} else {
return F{}(std::ref(stored_arg), std::forward<Container>(container));
}
}
```
Setting the stage to fix #891 parent 1c828d0 commit d45c47b
1 file changed
+30
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
353 | 353 | | |
354 | 354 | | |
355 | 355 | | |
356 | | - | |
357 | | - | |
| 356 | + | |
| 357 | + | |
358 | 358 | | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
359 | 364 | | |
360 | 365 | | |
361 | 366 | | |
| |||
378 | 383 | | |
379 | 384 | | |
380 | 385 | | |
| 386 | + | |
381 | 387 | | |
382 | | - | |
| 388 | + | |
383 | 389 | | |
384 | 390 | | |
385 | | - | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
386 | 397 | | |
387 | 398 | | |
388 | 399 | | |
| |||
403 | 414 | | |
404 | 415 | | |
405 | 416 | | |
406 | | - | |
| 417 | + | |
407 | 418 | | |
408 | 419 | | |
409 | | - | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
410 | 426 | | |
411 | 427 | | |
412 | 428 | | |
| |||
469 | 485 | | |
470 | 486 | | |
471 | 487 | | |
472 | | - | |
| 488 | + | |
473 | 489 | | |
474 | 490 | | |
475 | | - | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
476 | 498 | | |
477 | 499 | | |
478 | 500 | | |
| |||
0 commit comments