Use of an external variant implementation

Simon Marchi simon.marchi@polymtl.ca
Wed Jun 23 19:10:25 GMT 2021


Hi,

It was suggested a few times that we backport listdcxx's implementation
of std::variant (available in C++ >= 17), so that we can use it in GDB,
a bit like we have done for std::string_view and std::optional.  This
would allow replacing unions with something that can hold non-POD types.

Could we instead use an existing implementation such as this one?

  https://github.com/mapbox/variant

I think it would be wasteful to spend some time writing an
implementation, when there's already one that seems very well tested and
documented.

The only downside I see is that the API doesn't seem to match
std::variant's API exactly.  For example, the standard version uses
std::visit, while that version uses an apply_visitor function.  But I am
pretty sure we would be able to make a little shim so that we are able
to use the standard version when __cplusplus is >= 2017, and that
version otherwise.

The license seems to be BSD, is there a problem with redistributing it
with GDB?

The idea would be to copy just the few relevant headers in our repo,
like we do for readline or other external software.  We could also use
a submodule, I don't really mind.

Simon


More information about the Gdb-patches mailing list