I want to create a container for an arbitrary type T. However, I want to add some functionality if T has a member, which is a type of header (which I also define). If T does not have this header element, the added functionality can simply be skipped.
The added functionality may, for example, consist of adding a time stamp based on the operation. Here's the pseudo code for what I want:
struct my_header {
timestamp_t time;
}
template <class T>
class my_container {
public:
void some_operation(T val) {
if T has a member of type my_header {
val.header.time = get_current_time();
}
}
};
Of course, like mine, some_operation should also define the instance name my_header in class T. This requirement could be eliminated by imposing one of the following requirements for additional functions that will be used (in order of least preferred):
my_header T headermy_header - T- T my_header , -.
++ 11 ( ).