diff --git a/CMakeLists.txt b/CMakeLists.txt index a7b0ac9f..018afd28 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,11 @@ endif() set (CMAKE_CXX_STANDARD_REQUIRED ON) set (CMAKE_CXX_EXTENSIONS OFF) +if (MSVC AND CMAKE_CXX_STANDARD GREATER_EQUAL 23) + set (CMAKE_CXX23_STANDARD_COMPILE_OPTION "/std:c++latest") + set (CMAKE_CXX23_EXTENSION_COMPILE_OPTION "/std:c++latest") +endif() + find_program (FIND_EXECUTABLE find) find_program (LCOV_EXECUTABLE lcov) find_program (GENHTML_EXECUTABLE genhtml) diff --git a/Manual.md b/Manual.md index cb665ed3..b46a4709 100644 --- a/Manual.md +++ b/Manual.md @@ -93,8 +93,9 @@ Contents * [6.8 - LUABRIDGE_HAS_CXX20_SPAN / LUABRIDGE_DISABLE_CXX20_SPAN](#68---luabridge-has-cxx20-span--luabridge-disable-cxx20-span) * [6.9 - LUABRIDGE_HAS_CXX20_RANGES / LUABRIDGE_DISABLE_CXX20_RANGES](#69---luabridge-has-cxx20-ranges--luabridge-disable-cxx20-ranges) * [6.10 - LUABRIDGE_HAS_CXX23_EXPECTED / LUABRIDGE_DISABLE_CXX23_EXPECTED](#610---luabridge-has-cxx23-expected--luabridge-disable-cxx23-expected) - * [6.11 - LUABRIDGE_HAS_CXX23_FLAT_CONTAINERS / LUABRIDGE_DISABLE_CXX23_FLAT_CONTAINERS](#611---luabridge-has-cxx23-flat-containers--luabridge-disable-cxx23-flat-containers) - * [6.12 - LUABRIDGE_HAS_CXX23_MOVE_ONLY_FUNCTION / LUABRIDGE_DISABLE_CXX23_MOVE_ONLY_FUNCTION](#612---luabridge-has-cxx23-move-only-function--luabridge-disable-cxx23-move-only-function) + * [6.11 - LUABRIDGE_HAS_CXX23_FLAT_MAP / LUABRIDGE_DISABLE_CXX23_FLAT_MAP](#611---luabridge-has-cxx23-flat-map--luabridge-disable-cxx23-flat-map) + * [6.12 - LUABRIDGE_HAS_CXX23_FLAT_SET / LUABRIDGE_DISABLE_CXX23_FLAT_SET](#612---luabridge-has-cxx23-flat-set--luabridge-disable-cxx23-flat-set) + * [6.13 - LUABRIDGE_HAS_CXX23_MOVE_ONLY_FUNCTION / LUABRIDGE_DISABLE_CXX23_MOVE_ONLY_FUNCTION](#612---luabridge-has-cxx23-move-only-function--luabridge-disable-cxx23-move-only-function) * [Appendix - API Reference](#appendix---api-reference) @@ -1463,8 +1464,8 @@ The table below lists every optional header and its requirements: | `LuaBridge/Any.h` | `std::any` | C++17 (`LUABRIDGE_HAS_CXX17_ANY`) | Push-only; types must be pre-registered with `luabridge::registerAnyPush(L)` | | `LuaBridge/Span.h` | `std::span` | C++20 (`LUABRIDGE_HAS_CXX20_SPAN`) | Push-only; use `std::vector` to retrieve sequences from Lua | | `LuaBridge/StdExpected.h` | `std::expected` | C++23 (`LUABRIDGE_HAS_CXX23_EXPECTED`) | Pushes the value on success, nil on error | -| `LuaBridge/FlatMap.h` | `std::flat_map` | C++23 (`LUABRIDGE_HAS_CXX23_FLAT_CONTAINERS`) | Ordered key-value table backed by contiguous storage | -| `LuaBridge/FlatSet.h` | `std::flat_set` | C++23 (`LUABRIDGE_HAS_CXX23_FLAT_CONTAINERS`) | Ordered set backed by contiguous storage | +| `LuaBridge/FlatMap.h` | `std::flat_map` | C++23 (`LUABRIDGE_HAS_CXX23_FLAT_MAP`) | Ordered key-value table backed by contiguous storage | +| `LuaBridge/FlatSet.h` | `std::flat_set` | C++23 (`LUABRIDGE_HAS_CXX23_FLAT_SET`) | Ordered set backed by contiguous storage | `std::filesystem::path` is also supported as a built-in type when C++17 filesystem is available (`LUABRIDGE_HAS_CXX17_FILESYSTEM`). It is converted to and from a Lua string automatically; no additional header is required beyond `LuaBridge/LuaBridge.h`. @@ -2530,21 +2531,35 @@ To force the feature off: #include ``` -6.11 - LUABRIDGE_HAS_CXX23_FLAT_CONTAINERS / LUABRIDGE_DISABLE_CXX23_FLAT_CONTAINERS +6.11 - LUABRIDGE_HAS_CXX23_FLAT_MAP / LUABRIDGE_DISABLE_CXX23_FLAT_MAP ------------------------------------------------------------------------------------- -**`LUABRIDGE_HAS_CXX23_FLAT_CONTAINERS` - auto-detected when C++23 is enabled, override allowed** +**`LUABRIDGE_HAS_CXX23_FLAT_MAP` - auto-detected when C++23 is enabled, override allowed** -When a C++23 compiler and `` are available, LuaBridge enables conversion support for `std::flat_map` and `std::flat_set` via `LuaBridge/FlatMap.h` and `LuaBridge/FlatSet.h` respectively. These are contiguous-storage analogues of `std::map` and `std::set` with identical Lua table semantics. +When a C++23 compiler and `` are available, LuaBridge enables conversion support for `std::flat_map` via `LuaBridge/FlatMap.h`. This is a contiguous-storage analogue of `std::map` with identical Lua table semantics. To force the feature off: ```cpp -#define LUABRIDGE_DISABLE_CXX23_FLAT_CONTAINERS +#define LUABRIDGE_DISABLE_CXX23_FLAT_MAP #include ``` -6.12 - LUABRIDGE_HAS_CXX23_MOVE_ONLY_FUNCTION / LUABRIDGE_DISABLE_CXX23_MOVE_ONLY_FUNCTION +6.12 - LUABRIDGE_HAS_CXX23_FLAT_SET / LUABRIDGE_DISABLE_CXX23_FLAT_SET +------------------------------------------------------------------------------------- + +**`LUABRIDGE_HAS_CXX23_FLAT_SET` - auto-detected when C++23 is enabled, override allowed** + +When a C++23 compiler and `` are available, LuaBridge enables conversion support for `std::flat_set` via `LuaBridge/FlatSet.h`. This is a contiguous-storage analogue of `std::set` with identical Lua table semantics. + +To force the feature off: + +```cpp +#define LUABRIDGE_DISABLE_CXX23_FLAT_SET +#include +``` + +6.13 - LUABRIDGE_HAS_CXX23_MOVE_ONLY_FUNCTION / LUABRIDGE_DISABLE_CXX23_MOVE_ONLY_FUNCTION ------------------------------------------------------------------------------------------- **`LUABRIDGE_HAS_CXX23_MOVE_ONLY_FUNCTION` - auto-detected when C++23 is enabled, override allowed** diff --git a/README.md b/README.md index 796cec51..cc0e5ed8 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,8 @@ LuaBridge3 auto-detects available C++ standard library features and activates th | `LUABRIDGE_HAS_CXX20_RANGES` | `Iterator`/`Range` satisfy `std::ranges` concepts | C++20 | | `LUABRIDGE_HAS_CXX20_COROUTINES` | `CppCoroutine` / `LuaCoroutine` | C++20 | | `LUABRIDGE_HAS_CXX23_EXPECTED` | `std::expected` conversion | C++23 | -| `LUABRIDGE_HAS_CXX23_FLAT_CONTAINERS` | `std::flat_map` / `std::flat_set` | C++23 | +| `LUABRIDGE_HAS_CXX23_FLAT_MAP` | `std::flat_map` | C++23 | +| `LUABRIDGE_HAS_CXX23_FLAT_SET` | `std::flat_set` | C++23 | | `LUABRIDGE_HAS_CXX23_MOVE_ONLY_FUNCTION` | `std::move_only_function` as callable | C++23 | ## Documentation diff --git a/Source/LuaBridge/FlatMap.h b/Source/LuaBridge/FlatMap.h index 2a34d851..6c8d507a 100644 --- a/Source/LuaBridge/FlatMap.h +++ b/Source/LuaBridge/FlatMap.h @@ -6,7 +6,7 @@ #include "detail/Stack.h" -#if LUABRIDGE_HAS_CXX23_FLAT_CONTAINERS +#if LUABRIDGE_HAS_CXX23_FLAT_MAP #include @@ -86,4 +86,4 @@ struct Stack> } // namespace luabridge -#endif // LUABRIDGE_HAS_CXX23_FLAT_CONTAINERS +#endif // LUABRIDGE_HAS_CXX23_FLAT_MAP diff --git a/Source/LuaBridge/FlatSet.h b/Source/LuaBridge/FlatSet.h index 56309c6c..44db824e 100644 --- a/Source/LuaBridge/FlatSet.h +++ b/Source/LuaBridge/FlatSet.h @@ -6,7 +6,7 @@ #include "detail/Stack.h" -#if LUABRIDGE_HAS_CXX23_FLAT_CONTAINERS +#if LUABRIDGE_HAS_CXX23_FLAT_SET #include @@ -81,4 +81,4 @@ struct Stack> } // namespace luabridge -#endif // LUABRIDGE_HAS_CXX23_FLAT_CONTAINERS +#endif // LUABRIDGE_HAS_CXX23_FLAT_SET diff --git a/Source/LuaBridge/detail/Config.h b/Source/LuaBridge/detail/Config.h index f4f1706f..e5e75920 100644 --- a/Source/LuaBridge/detail/Config.h +++ b/Source/LuaBridge/detail/Config.h @@ -230,16 +230,30 @@ #endif /** - * @brief Enable C++23 flat containers library support. + * @brief Enable C++23 flat map library support. * * Requires C++23 and the flat_map header to be available. - * Define LUABRIDGE_DISABLE_CXX23_FLAT_CONTAINERS to force-disable even when available. + * Define LUABRIDGE_DISABLE_CXX23_FLAT_MAP to force-disable even when available. */ -#if !defined(LUABRIDGE_HAS_CXX23_FLAT_CONTAINERS) -#if !defined(LUABRIDGE_DISABLE_CXX23_FLAT_CONTAINERS) && LUABRIDGE_CXX23_OR_GREATER && __has_include() && __has_include() && defined(__cpp_lib_flat_map) -#define LUABRIDGE_HAS_CXX23_FLAT_CONTAINERS 1 +#if !defined(LUABRIDGE_HAS_CXX23_FLAT_MAP) +#if !defined(LUABRIDGE_DISABLE_CXX23_FLAT_MAP) && LUABRIDGE_CXX23_OR_GREATER && __has_include() && defined(__cpp_lib_flat_map) +#define LUABRIDGE_HAS_CXX23_FLAT_MAP 1 #else -#define LUABRIDGE_HAS_CXX23_FLAT_CONTAINERS 0 +#define LUABRIDGE_HAS_CXX23_FLAT_MAP 0 +#endif +#endif + +/** + * @brief Enable C++23 flat set library support. + * + * Requires C++23 and the flat_set header to be available. + * Define LUABRIDGE_DISABLE_CXX23_FLAT_SET to force-disable even when available. + */ +#if !defined(LUABRIDGE_HAS_CXX23_FLAT_SET) +#if !defined(LUABRIDGE_DISABLE_CXX23_FLAT_SET) && LUABRIDGE_CXX23_OR_GREATER && __has_include() && defined(__cpp_lib_flat_set) +#define LUABRIDGE_HAS_CXX23_FLAT_SET 1 +#else +#define LUABRIDGE_HAS_CXX23_FLAT_SET 0 #endif #endif diff --git a/Source/LuaBridge/detail/FuncTraits.h b/Source/LuaBridge/detail/FuncTraits.h index c2b194ca..a8ea4371 100644 --- a/Source/LuaBridge/detail/FuncTraits.h +++ b/Source/LuaBridge/detail/FuncTraits.h @@ -227,7 +227,7 @@ struct functor_traits_impl }; template -struct functor_traits_impl>> : function_traits_impl +struct functor_traits_impl && !is_move_only_function_v>> : function_traits_impl { }; diff --git a/Tests/Source/FlatMapTests.cpp b/Tests/Source/FlatMapTests.cpp index 22dda4f5..a3dc6b24 100644 --- a/Tests/Source/FlatMapTests.cpp +++ b/Tests/Source/FlatMapTests.cpp @@ -6,7 +6,7 @@ #include "LuaBridge/FlatMap.h" -#if LUABRIDGE_HAS_CXX23_FLAT_CONTAINERS +#if LUABRIDGE_HAS_CXX23_FLAT_MAP #include #include @@ -168,21 +168,21 @@ TEST_F(FlatMapTests, PassToFunction) "end"); auto foo = luabridge::getGlobal(L, "foo"); - using Int2Bool = std::flat_map; + using Int2String = std::flat_map; resetResult(); - Int2Bool lvalue{{10, false}, {20, true}, {30, true}}; + Int2String lvalue{{10, "1"}, {20, "2"}, {30, "3"}}; ASSERT_TRUE(foo.call(lvalue)); ASSERT_TRUE(result().isTable()); - ASSERT_EQ(lvalue, result()); + ASSERT_EQ(lvalue, result()); resetResult(); - const Int2Bool constLvalue = lvalue; + const Int2String constLvalue = lvalue; ASSERT_TRUE(foo.call(constLvalue)); ASSERT_TRUE(result().isTable()); - ASSERT_EQ(constLvalue, result()); + ASSERT_EQ(constLvalue, result()); } TEST_F(FlatMapTests, PassFromLua) @@ -295,4 +295,4 @@ TEST_F(FlatMapTests, PushUnregisteredWithNoExceptionsShouldFailButRestoreStack) } #endif -#endif // LUABRIDGE_HAS_CXX23_FLAT_CONTAINERS +#endif // LUABRIDGE_HAS_CXX23_FLAT_MAP diff --git a/Tests/Source/FlatSetTests.cpp b/Tests/Source/FlatSetTests.cpp index 4349b9ed..1f8ad277 100644 --- a/Tests/Source/FlatSetTests.cpp +++ b/Tests/Source/FlatSetTests.cpp @@ -6,7 +6,7 @@ #include "LuaBridge/FlatSet.h" -#if LUABRIDGE_HAS_CXX23_FLAT_CONTAINERS +#if LUABRIDGE_HAS_CXX23_FLAT_SET #include #include @@ -257,4 +257,4 @@ TEST_F(FlatSetTests, PushUnregisteredWithNoExceptionsShouldFailButRestoreStack) } #endif -#endif // LUABRIDGE_HAS_CXX23_FLAT_CONTAINERS +#endif // LUABRIDGE_HAS_CXX23_FLAT_SET