In some C++ code, I use integers to store lots of changing data. To analyze my program, I want to log certain changes to some of the variables, such as how often a certain value is assigned to, and how often that assignment is redundant (the new value is the same as the old value.)
If the type were a class Foo, I'd just derive a new LoggingFoo and add my logging data to the member function(s) I was interested in, and then call the parent member function. I'd have to update my code to use the new type, but as long as I was originally consistent with typedefs, that's a one-line change.
My problem is that the variable I want to add logging to is an int. You can't derive from built in types in C++ (can you?)
My question is whether there's a clever way to derive from the basic types (int, float, double, etc).
The solution may be to define a new class that effectively is an int.. it defines every operation an int can do and just applies that operation to a private int data member. This strategy will work, but perhaps others have already made such a class and I can just use a "fakeint.h" header file definition. Is there such a "proxy native class wrapper" type definitions already available somewhere before I implement them myself?
I do realize of course my proxy int can't be used interchangably with an int especially since existing function definitions all expect an int.. but for my app, this is all in an inner loop which is doing lots of simple native +-*^= operations, not used as function arguments or anything.