ThePhD / sol2

Sol3 (sol2 v3.0) - a C++ <-> Lua API wrapper with advanced features and top notch performance - is here, and it's great! Documentation:
http://sol2.rtfd.io/
MIT License
4.06k stars 492 forks source link

Error in emplace method #1605

Open paulocoutinhox opened 1 month ago

paulocoutinhox commented 1 month ago

Hi,

Im getting this error when build:

[100%] Building CXX object engine/extensions/scripting/lua-bindings/CMakeFiles/axlua.dir/Users/paulo/Developer/workspaces/cpp/axmol/3rdparty/yasio/yasio/bindings/lyasio.cpp.o
In file included from /Users/paulo/Developer/workspaces/cpp/axmol/3rdparty/yasio/yasio/bindings/lyasio.cpp:83:
In file included from /Users/paulo/Developer/workspaces/cpp/axmol/3rdparty/yasio/yasio/bindings/yasio_sol.hpp:29:
/Users/paulo/Developer/workspaces/cpp/axmol/3rdparty/lua/sol/sol.hpp:6755:10: error: no member named 'construct' in 'optional<type-parameter-0-0 &>'
 6755 |                         this->construct(std::forward<Args>(args)...);
      |                         ~~~~  ^
/Users/paulo/Developer/workspaces/cpp/axmol/3rdparty/lua/sol/sol.hpp:14541:32: warning: unknown warning group '-Wmaybe-uninitialized', ignored [-Wunknown-warning-option]
 14541 | #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
       |                                ^
/Users/paulo/Developer/workspaces/cpp/axmol/3rdparty/lua/sol/sol.hpp:17294:32: warning: unknown warning group '-Wmaybe-uninitialized', ignored [-Wunknown-warning-option]
 17294 | #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
       |                                ^
2 warnings and 1 error generated.

My solution:

/// Constructs the value in-place, destroying the current one if there is
/// one.
///
/// \group emplace
template <class... Args>
T& emplace(Args&&... args) noexcept {
    static_assert(std::is_constructible<T, Args&&...>::value, "T must be constructible with Args");

    *this = nullopt;
    new (static_cast<void*>(this)) optional(std::in_place, std::forward<Args>(args)...);
    return **this;
}