| 635 | //---------------------------------------------------------- |
| 636 | |
| 637 | void |
| 638 | usingArrays() |
| 639 | { |
| 640 | { |
| 641 | // tag::snippet_arrays_1[] |
| 642 | |
| 643 | array arr1; // empty array, uses the default memory resource |
| 644 | |
| 645 | array arr2( make_shared_resource<monotonic_resource>() ); // empty array, uses a counted monotonic resource |
| 646 | |
| 647 | // end::snippet_arrays_1[] |
| 648 | } |
| 649 | { |
| 650 | // tag::snippet_arrays_2[] |
| 651 | |
| 652 | array arr( { "Hello", 42, true } ); |
| 653 | |
| 654 | // end::snippet_arrays_2[] |
| 655 | } |
| 656 | try |
| 657 | { |
| 658 | // tag::snippet_arrays_3[] |
| 659 | |
| 660 | array arr; |
| 661 | |
| 662 | arr.emplace_back( "Hello" ); |
| 663 | arr.emplace_back( 42 ); |
| 664 | arr.emplace_back( true ); |
| 665 | |
| 666 | // end::snippet_arrays_3[] |
| 667 | |
| 668 | // tag::snippet_arrays_4[] |
| 669 | |
| 670 | assert( arr[0].as_string() == "Hello" ); |
| 671 | |
| 672 | // The following line throws system_error, since the index is out of range |
| 673 | arr.at( 3 ) = nullptr; |
| 674 | |
| 675 | // end::snippet_arrays_4[] |
| 676 | } |
| 677 | catch (...) |
| 678 | { |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | //---------------------------------------------------------- |
| 683 | |