Skip to content

[COMMENTS?] enable easy printing (debugging) of some enum classes

Podhorszki, Norbert requested to merge github/fork/germasch/pr/tostring into master

Created by: germasch

I've had this sitting around for a while, and let me start by saying that I don't have strong feelings about it. It adds a somewhat neat feature making it easier to give human-readable output for some enums, but it could also be considered rarely needed bloat.

Essentially, the PR adds adios::tostring and overloads for the ostream operator<< for enum classes. (It only does it for a couple of them right now, I could add the rest if you want this). It allows you to do, e.g.,

std::cout << variable.ShapeID() << std::endl;

and get human readable output. It gets picked up by googletest, so on an (intentionally failing) test, instead of

../testing/adios2/engine/bp/TestBPWriteReadADIOS2.cpp:186: Failure
Expected equality of these values:
  var_i8.ShapeID()
    Which is: 4-byte object <02-00 00-00>
  adios2::ShapeID::LocalArray
    Which is: 4-byte object <05-00 00-00>

you get

../testing/adios2/engine/bp/TestBPWriteReadADIOS2.cpp:186: Failure
Expected equality of these values:
  var_i8.ShapeID()
    Which is: ShapeID::GlobalArray
  adios2::ShapeID::LocalArray
    Which is: ShapeID::LocalArray

In its last commit, it demonstrates that one could also support std::cout << variable to do something akin to Python's __str__ method, which might be useful for debugging, but mostly it's me playing with SFINAE, and I'm less than convinced that this isn't overdoing things.

Merge request reports