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

**URL:** <https://forum.heroiclabs.com/t/c-optional-lite-library-conflicts-with-std-optional-breaks-nakama-functions-with-optional-parameters/2004>\
**Category:** Client Libraries\
**Created:** [October 3, 2021, 5:32am UTC](https://forum.heroiclabs.com/t/c-optional-lite-library-conflicts-with-std-optional-breaks-nakama-functions-with-optional-parameters/2004 "2021-10-03T05:32:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mehoo462](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@Mehoo462](https://forum.heroiclabs.com/u/Mehoo462)\
**Post date:** [October 3, 2021, 5:32am UTC](https://forum.heroiclabs.com/t/c-optional-lite-library-conflicts-with-std-optional-breaks-nakama-functions-with-optional-parameters/2004/1 "2021-10-03T05:32:35Z")

</div>

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.](https://github.com/martinmoene/optional-lite#in-a-nutshell)”

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.

---

<div class="post-metadata">

**Author:** ![Mehoo462](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@Mehoo462](https://forum.heroiclabs.com/u/Mehoo462)\
**Post date:** [October 3, 2021, 7:28pm UTC](https://forum.heroiclabs.com/t/c-optional-lite-library-conflicts-with-std-optional-breaks-nakama-functions-with-optional-parameters/2004/2 "2021-10-03T19:28:22Z")

</div>

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

before:

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

```

After:

```auto
#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.
