MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / smallVectorSnippet

Method smallVectorSnippet

Tests/Libraries/Containers/SmallVectorTest.cpp:234–258  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

232};
233
234bool 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
260namespace SC
261{

Callers

nothing calls this directly

Calls 2

pop_backMethod · 0.80
push_backMethod · 0.45

Tested by

no test coverage detected