C++: optional-lite library conflicts with std::optional, breaks Nakama functions with optional parameters

I’ve run into a bit of a snag while trying to integrate Nakama with another SDK I’d like to use. The problem is the other SDK makes use of std::optional.

Nakama uses a third party library called optional-lite. This library requires special consideration. In the github description it says “If available, std::optional is used.

While this might seem to be convenient, this feature of optional-lite breaks Nakama functions with optional parameters in environments where std::optional is present.

For example, an environment that is shared with my other SDK. The result is that authenticateDevice() calls std::optional instead of nonstd::optional to process optional parameters. This leads to problems when trying to assemble those parameters into a POST request to the server. For me it’s manifesting as a “bad allocation” error.

Is it possible to use Nakama in an environment where std::optional is available? How can I over-ride this feature of optional-lite in the context of a Nakama build?

Thanks for any input.

I fixed this by changing line 33 of optional.hpp.

before:

#if !defined( optional_CONFIG_SELECT_OPTIONAL )
# define optional_CONFIG_SELECT_OPTIONAL  ( optional_HAVE_STD_OPTIONAL ? optional_OPTIONAL_STD : optional_OPTIONAL_NONSTD )
#endif

After:

#if !defined( optional_CONFIG_SELECT_OPTIONAL )
# define optional_CONFIG_SELECT_OPTIONAL  optional_OPTIONAL_NONSTD
#endif

This will force the use of optional-lite over std::optional.

My program is functioning after this change.