I remembered that C++20 got features to iterate over members in a struct ,I read a blog about it with example codes, but I can't find it anymore.
For example:
struct Foo {
std::string a;
std::string b;
std::string c;
};
struct Bar {
std::string e;
std::string f;
};
template <typename T>
void PrintMember (T& t) {
// what to do to iterate members in C++ 20?
}
The code of the template may not look like that, since C++20 got concepts. Any idea how to write codes to iterate members in Foo
and Bar
?
P.S. I remembered that it use concepts to do the trick, but maybe I'm wrong or the blog is wrong (that's why I can't find it anymore), an answer of "No you can't, even in C++20" is welcomed.
P.P.S. One thing I didn't clarify, I don't need the field name, but I need to iterate for all fields, including inherited fields.