MCPcopy Create free account
hub / github.com/Apress/beginning-cpp20 / main

Function main

Exercises/NoModules/Chapter 19/Soln19_05/Soln19_05.cpp:15–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13}
14
15int main()
16{
17 const size_t boxCount {20}; // Number of Box object to be created
18
19 // Create boxCount Box objects
20 Truckload load;
21 for (size_t i {}; i < boxCount; ++i)
22 load.addBox(randomSharedBox());
23
24 DeliveryTruck truck{ load }; // Copy the load, because we still need it below.
25 // Note that all Boxes are shared, so the they themselves are not copied.
26
27 // Register two callback functions:
28 truck.registerOnDelivered(logDelivary);
29
30 unsigned count {};
31 truck.registerOnDelivered([&count](SharedBox) { ++count; });
32
33 // Deliver some boxes:
34 for (size_t i : { 5u, 8u, 11u })
35 truck.deliverBox(load[i]);
36
37 std::cout << count << " boxes were delivered. On time, as always!" << std::endl;
38}

Callers

nothing calls this directly

Calls 4

randomSharedBoxFunction · 0.70
addBoxMethod · 0.45
registerOnDeliveredMethod · 0.45
deliverBoxMethod · 0.45

Tested by

no test coverage detected