|
441 | 441 | shared_ptr<A> sp2 = factory<A>(i, 1.414); // OK
|
442 | 442 | }
|
443 | 443 | \end{codeblock}
|
444 |
| - |
445 |
| -\pnum |
446 | 444 | In the first call to \tcode{factory},
|
447 | 445 | \tcode{A1} is deduced as \tcode{int}, so 2 is forwarded
|
448 | 446 | to \tcode{A}'s constructor as an rvalue.
|
|
451 | 449 | to \tcode{A}'s constructor as an lvalue. In
|
452 | 450 | both cases, \tcode{A2} is deduced as \tcode{double}, so
|
453 | 451 | 1.414 is forwarded to \tcode{A}'s constructor as an rvalue.
|
454 |
| - |
455 | 452 | \end{example}
|
456 | 453 | \end{itemdescr}
|
457 | 454 |
|
|
475 | 472 |
|
476 | 473 | struct A {
|
477 | 474 | A();
|
478 |
| - A(const A&); // copies from lvalues |
479 |
| - A(A&&); // moves from rvalues |
| 475 | + A(const A&); // copies from lvalues |
| 476 | + A(A&&); // moves from rvalues |
480 | 477 | };
|
481 | 478 |
|
482 | 479 | void g() {
|
483 | 480 | A a;
|
484 |
| - shared_ptr<A> sp1 = factory<A>(a); // ``\tcode{a}'' binds to \tcode{A(const A\&)} |
485 |
| - shared_ptr<A> sp1 = factory<A>(std::move(a)); // ``\tcode{a}'' binds to \tcode{A(A\&\&)} |
| 481 | + shared_ptr<A> sp1 = factory<A>(a); // ``\tcode{a}\!'' binds to \tcode{A(const A\&)} |
| 482 | + shared_ptr<A> sp1 = factory<A>(std::move(a)); // ``\tcode{a}\!'' binds to \tcode{A(A\&\&)} |
486 | 483 | }
|
487 | 484 | \end{codeblock}
|
488 |
| - |
489 |
| -\pnum |
490 | 485 | In the first call to \tcode{factory},
|
491 | 486 | \tcode{A1} is deduced as \tcode{A\&}, so \tcode{a} is forwarded
|
492 | 487 | as a non-const lvalue. This binds to the constructor \tcode{A(const A\&)},
|
|
496 | 491 | \tcode{A1} is deduced as \tcode{A}, so \tcode{a} is forwarded
|
497 | 492 | as an rvalue. This binds to the constructor \tcode{A(A\&\&)},
|
498 | 493 | which moves the value from \tcode{a}.
|
499 |
| - |
500 | 494 | \end{example}
|
501 | 495 | \end{itemdescr}
|
502 | 496 |
|
|
0 commit comments