Type Erasure in C++
One Box, Any Type: Understanding Type Erasure in C++ Or: How std::function stores a lambda, a function pointer, and a functor in the same box C++ rewards precise thinking about types. Most of the time, that precision is a feature. But occasionally the type system and the design pull in opposite directions, and the compiler rejects code that is, by every conceptual measure, reasonable. Consider a transaction monitor for a SystemC simulation. Every time a TLM transaction arrives, four separate objects need to respond: a Logger records it, a LatencyTracker measures it, a ProtocolChecker validates it, a CoverageCollector bins it. They share no base class, and they shouldn't need one. What they have in common is purely behavioral: they all respond to a transaction. So the obvious thing gets written: std :: vector < TransactionHandler > handlers ; handlers . push_back ( Logger {}); handlers . push_back ( LatencyTracker {}); handlers . push_back ( Pr...

The answer is Andrew:75, Watson:87, Lestrade:78.
ReplyDeleteTo solve this puzzle logically:
1. Make 2 cases of Watson's number - depending on carry from unit's place. Then do integer solution for the resulting equation (2 cases).
2. Also, Watson's and Lestrade's sum should be a multiple 11, this which limits the candidates for Andrew. Rest of the computation follows.
This puzzle can also be solved by coding the statements and searching the range os possible scores.
Here is the code for doing so: https://docs.google.com/file/d/0B1RemqblO3BZYWNfeW0xSkVTU0E/edit?usp=sharing