Is there something like var_dump php in c / c ++?

I'm looking for an API that can be used to remove most data structures, is there any in c / C ++?

+5
source share
2 answers

I'm looking for an API that can be used to remove most data structures, is there any in c / C ++?

Short answer: No, no.

Longer answer: C ++ is not reflected. That is, there is no way to parse unknown data structures at runtime. You will have to write the dump procedures yourself for any data structure that you want to reset based on what is available to its data members.

However, note that C ++ has many tools to make this easier. For example, for a simple simple template dump():

template< typename T >
inline void dump(std::ostream& os, const T& obj) {os << obj;}

:

template< typename OutIt >
void dump(std::ostream& os, OutIt begin, OutIt end)
{
  if(begin != end)
    os << *begin++;
  while(begin != end) {
    os << ", ";
    dump(*begin++);
  }
}
+3

boost , , .

, , . ++ - , GCC-XML , Open++, .

+1

All Articles