little-bear-labs / ipfs-chromium

19 stars 1 forks source link

Optional options #100

Closed John-LittleBearLabs closed 5 months ago

John-LittleBearLabs commented 6 months ago

So here's the thing:

In old versions of Chromium there were interfaces with pure virtual functions that take an absl::optional as an argument.

In the latest dev version, those arguments are now std::optional.

I want to be able to support both simultaneously with the same concrete class.

I tried implementing both, allowing at build time one of them to override or not as need be. However, there's a static analysis check that says functions that are overriding base class MUST be marked as override, which I normally approve of, BTW.

So instead I tried to use build-time flags to determine which template should be used. And I didn't want to just call it optional because even in older versions std::optional was already in-use just not in virtual methods.

So here I introduce ipfs::VirtualOptional , which is an alias template for either std::optional or absl::optional as need be.

It's in component/ and not library/ because this is really, truly, a Chromium-specific issue. And I had to fall back on Chromium source major version (obviously not available outside Chromium) to detect which it should be since both headers are available both pre- and post-change and I see no other precompiler flag that would give away which it needs to be.