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

Function main

Exercises/Modules/Chapter 19/Soln19_05/Soln19_05.cpp:16–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 4

randomSharedBoxFunction · 0.50
addBoxMethod · 0.45
registerOnDeliveredMethod · 0.45
deliverBoxMethod · 0.45

Tested by

no test coverage detected