sharkdp / dbg-macro

A dbg(…) macro for C++

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for enums?

sharkdp opened this issue · comments

Enums are currently not supported (unless the user has defined an operator<< overload for ostream).

We could potentially implement support for enums if we:

  • use std::is_enum<E> to add a specialization for enums (similar to containers)
  • cast the value to std::underlying_type<E>::type and print that.

If we decide to do this, we should probably only use the overload if no custom operator<< is defined for that type.

Ok, but that would require modifications in the user code, right?

I don't think we could use WISE_ENUM_ADAPT to generate the necessary code, for a user enum type CustomEnum, given just an invocation of dbg(CustomEnum::VALUE1).

https://github.com/Neargye/magic_enum

Thank you for the reference. Unfortunately, it does require C++17 and we are targeting C++11. We could, of course, use something like this for C++17 and fall back to what I suggested in the first comment for older versions.