| 232 | }; |
| 233 | |
| 234 | bool SC::SmallVectorTest::smallVectorSnippet() |
| 235 | { |
| 236 | //! [SmallVectorSnippet] |
| 237 | auto pushThreeIntegers = [](Vector<int>& myVector) -> bool |
| 238 | { |
| 239 | SC_TRY(myVector.push_back(1)); |
| 240 | SC_TRY(myVector.push_back(2)); |
| 241 | SC_TRY(myVector.push_back(3)); |
| 242 | return true; |
| 243 | }; |
| 244 | //... |
| 245 | |
| 246 | SmallVector<int, 3> mySmallVector; |
| 247 | SC_TRY(pushThreeIntegers(mySmallVector)); // <-- No heap allocation will happen |
| 248 | |
| 249 | // ... later on |
| 250 | |
| 251 | SC_TRY(mySmallVector.push_back(4)); // <-- Vector is now moved to heap |
| 252 | |
| 253 | // ... later on |
| 254 | |
| 255 | SC_TRY(mySmallVector.pop_back()); // <-- Vector is moved back to SmallVector inline storage |
| 256 | //! [SmallVectorSnippet] |
| 257 | return true; |
| 258 | } |
| 259 | |
| 260 | namespace SC |
| 261 | { |