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

Method vectorMapSnippet

Tests/Libraries/Containers/VectorMapTest.cpp:72–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70};
71
72bool SC::VectorMapTest::vectorMapSnippet()
73{
74 //! [VectorMapSnippet]
75 VectorMap<String, int> map;
76 SC_TRY(map.insertIfNotExists({"A", 2})); // Allocates a String
77 SC_TRY(map.insertIfNotExists({"B", 3})); // Allocates a String
78 const int* value;
79 SC_TRY(map.contains("A", value) && *value == 2); // <-- "A" is a StringView, avoiding allocation
80 SC_TRY(map.contains("B", value) && *value == 3); // <-- "B" is a StringView, avoiding allocation
81 SC_TRY(not map.contains("C")); // <-- "C" is a StringView, avoiding allocation
82 //! [VectorMapSnippet]
83 return true;
84}
85
86namespace SC
87{

Callers

nothing calls this directly

Calls 2

insertIfNotExistsMethod · 0.80
containsMethod · 0.45

Tested by

no test coverage detected