| 1691 | } |
| 1692 | |
| 1693 | void |
| 1694 | testStrongGurantee() |
| 1695 | { |
| 1696 | // We used to preemptively reserve storage even if we don't add a new |
| 1697 | // element. That violated strong guarantee requirement. This test |
| 1698 | // checks we don't do that any more. |
| 1699 | |
| 1700 | object o; |
| 1701 | o.reserve(100); |
| 1702 | std::size_t const capacity = o.capacity(); |
| 1703 | for( std::size_t i = 0; i < o.capacity() ; ++i ) |
| 1704 | o.emplace( std::to_string(i), i ); |
| 1705 | BOOST_ASSERT( capacity == o.capacity() ); |
| 1706 | |
| 1707 | BOOST_TEST( !o.emplace("0", 0).second ); |
| 1708 | BOOST_TEST( capacity == o.capacity() ); |
| 1709 | |
| 1710 | BOOST_TEST( !o.insert_or_assign("0", 0).second ); |
| 1711 | BOOST_TEST( capacity == o.capacity() ); |
| 1712 | |
| 1713 | o["0"] = 0; |
| 1714 | BOOST_TEST( capacity == o.capacity() ); |
| 1715 | |
| 1716 | o.insert( key_value_pair("0", nullptr) ); |
| 1717 | BOOST_TEST( capacity == o.capacity() ); |
| 1718 | |
| 1719 | // Check that insertion rolls back reserve when cannot insert all |
| 1720 | // elements. |
| 1721 | std::array<throws_on_convert, 10> input; |
| 1722 | try |
| 1723 | { |
| 1724 | o.insert( input.begin(), input.end() ); |
| 1725 | } |
| 1726 | catch( ... ) |
| 1727 | { |
| 1728 | // ignore |
| 1729 | } |
| 1730 | BOOST_TEST( capacity == o.capacity() ); |
| 1731 | } |
| 1732 | |
| 1733 | void |
| 1734 | run() |