heroiclabs / nakama-cpp

Generic C/C++ client for Nakama server.
https://heroiclabs.com/docs/cpp-client-guide
Apache License 2.0
69 stars 25 forks source link

Nakama::opt::optional performs unexpected conversions when compiling with different C++ language standards #31

Closed Daspien27 closed 4 years ago

Daspien27 commented 4 years ago

With further investigation, I can confirm it is due to misaligned language standards. By changing my project from C++latest to C++14 Nakama::opt::make_optional aligns with the nonstd::optional_lite::optional class.

This is unfortunate that the nakama-cpp headers changes types depending on the language version. I think a potential fix would be to provide the two optional class interfaces in parallel (introducing a std::optional when available) or to just commit to a more hardened Nakama::NOptional type that could potentially allow conversions with nonstd::optional_lite::optional or std::optional.

Originally posted by @Daspien27 in https://github.com/heroiclabs/nakama-cpp/issues/24#issuecomment-633558997

Dimon4eg commented 4 years ago

Thanks for report of the error. We will try to resolve it. By now I propose two solutions:

  1. build nakama-cpp with same C++ standard. Open nakama-cpp\src\CMakeLists.txt, line 63 and set C++20:
    target_compile_features(nakama-cpp PUBLIC cxx_std_20)
  2. use nakama-cpp as shared library https://github.com/heroiclabs/nakama-cpp#use-as-dynamic-library
Daspien27 commented 4 years ago
  1. build nakama-cpp with same C++ standard. Open nakama-cpp\src\CMakeLists.txt, line 63 and set C++20:
target_compile_features(nakama-cpp PUBLIC cxx_std_20)

Opting to modify CMakeLists is more in line with my goals, and I can verify the incorrect behavior resolves.

Thanks for looking into resolving this error!

Dimon4eg commented 4 years ago

Great! I think we will release static libs for C++17 and C++20 standard.