Looking at C++ interface code. I do not have access to the implementation. I made a small example to show the behavior.
struct MessageInfo{
MessageInfo() : length{}, from{}, to{} {}
MessageInfo(int _length, string _from, string _to) : length{_length}, from{_from}, to{_to}
{}
int length;
string from;
string to;
using IsEnumerableTag = void;
template<typename F>
void enumerate(F& fun) {
fun(this->length);
fun(this->from);
fun(this->to);
}
};
Can somebody explain to me what is the usage of enumerate struct function member in this struct definition?
Based on my understanding the enumerate in this struct can take a function type as input parameter (function pointer?)
- Does it mean that whenever we create an object of MessageInfo struct we can call this method like below?
- How can define the function type, In other words what should i use instead of "???" in following code?
- What is the advantage of this model of coding (more specifically about enumerate method)?
MessageInfo messageInfo (1000, "A", "B");
messageInfo.enumerate<???>(printFrom(messageInfo.From);
void printFrom(string f) {
cout<<"the msgInfo is sent from "<< f<<endl;
}