From 38d979209de9afd8d32f4df5e4c5a7c0e7616abc Mon Sep 17 00:00:00 2001 From: ThePhD Date: Sun, 1 Dec 2019 19:27:49 -0500 Subject: [PATCH] Rework variant checks and other things to prevent hard failures. --- include/sol/stack_core.hpp | 2 +- include/sol/traits.hpp | 84 +++++++++++++-------------- include/sol/types.hpp | 11 +--- single/include/sol/forward.hpp | 4 +- single/include/sol/sol.hpp | 102 ++++++++++++++------------------- 5 files changed, 88 insertions(+), 115 deletions(-) diff --git a/include/sol/stack_core.hpp b/include/sol/stack_core.hpp index 3b37210e..79b559e2 100644 --- a/include/sol/stack_core.hpp +++ b/include/sol/stack_core.hpp @@ -1365,7 +1365,7 @@ namespace sol { template int default_to_string(lua_State* L) { - return oss_default_to_string(meta::supports_ostream_op(), L); + return oss_default_to_string(meta::supports_op_ostream(), L); } template diff --git a/include/sol/traits.hpp b/include/sol/traits.hpp index ca2b8ff2..e609c7f1 100644 --- a/include/sol/traits.hpp +++ b/include/sol/traits.hpp @@ -37,6 +37,9 @@ #include #include #include +#if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT != 0 +#include +#endif // variant is weird on XCode, thanks XCode namespace sol { namespace meta { @@ -459,39 +462,30 @@ namespace sol { namespace meta { static constexpr bool value = std::is_same_v(0)), sfinae_yes_t>; }; -#if defined(_MSC_VER) && _MSC_VER <= 1910 - template () < std::declval())> - std::true_type supports_op_less_test(std::reference_wrapper, std::reference_wrapper); - std::false_type supports_op_less_test(...); - template () == std::declval())> - std::true_type supports_op_equal_test(std::reference_wrapper, std::reference_wrapper); - std::false_type supports_op_equal_test(...); - template () <= std::declval())> - std::true_type supports_op_less_equal_test(std::reference_wrapper, std::reference_wrapper); - std::false_type supports_op_less_equal_test(...); - template () << std::declval())> - std::true_type supports_ostream_op(std::reference_wrapper, std::reference_wrapper); - std::false_type supports_ostream_op(...); - template ()))> - std::true_type supports_adl_to_string(std::reference_wrapper); - std::false_type supports_adl_to_string(...); -#else - template () < std::declval())> - std::true_type supports_op_less_test(const T&, const U&); - std::false_type supports_op_less_test(...); - template () == std::declval())> - std::true_type supports_op_equal_test(const T&, const U&); - std::false_type supports_op_equal_test(...); - template () <= std::declval())> - std::true_type supports_op_less_equal_test(const T&, const U&); - std::false_type supports_op_less_equal_test(...); - template () << std::declval())> - std::true_type supports_ostream_op(const T&, const OS&); - std::false_type supports_ostream_op(...); - template ()))> - std::true_type supports_adl_to_string(const T&); - std::false_type supports_adl_to_string(...); -#endif + template + class supports_op_less_test : public std::false_type {}; + template + class supports_op_less_test() < std::declval())>> : public std::integral_constant, std::variant> && !is_specialization_of_v, std::variant>> {}; + + template + class supports_op_equal_test : public std::false_type {}; + template + class supports_op_equal_test() == std::declval())>> : public std::integral_constant, std::variant> && !is_specialization_of_v, std::variant>> {}; + + template + class supports_op_less_equal_test : public std::false_type {}; + template + class supports_op_less_equal_test() <= std::declval())>> : public std::integral_constant, std::variant> && !is_specialization_of_v, std::variant>> {}; + + template + class supports_op_ostream_test : public std::false_type {}; + template + class supports_op_ostream_test() << std::declval())>> : public std::integral_constant, std::variant> && !is_specialization_of_v, std::variant>> {}; + + template + class supports_adl_to_string_test : public std::false_type {}; + template + class supports_adl_to_string_test()))>> : public std::true_type {}; template struct is_matched_lookup_impl : std::false_type {}; @@ -503,22 +497,22 @@ namespace sol { namespace meta { } // namespace meta_detail template - using supports_op_less - = decltype(meta_detail::supports_op_less_test(std::declval&>(), std::declval&>())); + class supports_op_less : public meta_detail::supports_op_less_test {}; + template - using supports_op_equal - = decltype(meta_detail::supports_op_equal_test(std::declval&>(), std::declval&>())); + class supports_op_equal : public meta_detail::supports_op_equal_test {}; + template - using supports_op_less_equal - = decltype(meta_detail::supports_op_less_equal_test(std::declval&>(), std::declval&>())); - template - using supports_ostream_op - = decltype(meta_detail::supports_ostream_op(std::declval&>(), std::declval&>())); - template - using supports_adl_to_string = decltype(meta_detail::supports_adl_to_string(std::declval&>())); + class supports_op_less_equal : public meta_detail::supports_op_less_equal_test {}; + template + class supports_op_ostream : public meta_detail::supports_op_ostream_test {}; + template - using supports_to_string_member = meta::boolean>::value>; + class supports_adl_to_string : public meta_detail::supports_adl_to_string_test {}; + + template + class supports_to_string_member : public meta::boolean>::value> {}; template using is_callable = boolean::value>; diff --git a/include/sol/types.hpp b/include/sol/types.hpp index 7607e531..43bf9ec4 100644 --- a/include/sol/types.hpp +++ b/include/sol/types.hpp @@ -908,7 +908,7 @@ namespace sol { template struct is_to_stringable : meta::any>, meta::supports_adl_to_string>, - meta::supports_ostream_op>> {}; + meta::supports_op_ostream>> {}; namespace detail { template @@ -1307,14 +1307,7 @@ namespace sol { template struct is_automagical - : std::integral_constant, std::variant> && -#endif // std::variant borked in places -#endif // C++17 Features - std::is_array_v< - meta::unqualified_t> || (!std::is_same_v, state> && !std::is_same_v, state_view>)> { + : std::integral_constant> || (!std::is_same_v, state> && !std::is_same_v, state_view>)> { }; template diff --git a/single/include/sol/forward.hpp b/single/include/sol/forward.hpp index 140acb94..af4e6500 100644 --- a/single/include/sol/forward.hpp +++ b/single/include/sol/forward.hpp @@ -20,8 +20,8 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // This file was generated with a script. -// Generated 2019-12-01 22:39:33.269777 UTC -// This header was generated with sol v3.2.0 (revision e26475e) +// Generated 2019-12-02 00:27:36.626106 UTC +// This header was generated with sol v3.2.0 (revision b0c7420) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP diff --git a/single/include/sol/sol.hpp b/single/include/sol/sol.hpp index d68bfd25..cda15c32 100644 --- a/single/include/sol/sol.hpp +++ b/single/include/sol/sol.hpp @@ -20,8 +20,8 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // This file was generated with a script. -// Generated 2019-12-01 22:39:31.432773 UTC -// This header was generated with sol v3.2.0 (revision e26475e) +// Generated 2019-12-02 00:27:35.949915 UTC +// This header was generated with sol v3.2.0 (revision b0c7420) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -1412,6 +1412,9 @@ namespace sol { #include #include #include +#if defined(SOL_STD_VARIANT) && SOL_STD_VARIANT != 0 +#include +#endif // variant is weird on XCode, thanks XCode namespace sol { namespace meta { template @@ -1833,39 +1836,30 @@ namespace sol { namespace meta { static constexpr bool value = std::is_same_v(0)), sfinae_yes_t>; }; -#if defined(_MSC_VER) && _MSC_VER <= 1910 - template () < std::declval())> - std::true_type supports_op_less_test(std::reference_wrapper, std::reference_wrapper); - std::false_type supports_op_less_test(...); - template () == std::declval())> - std::true_type supports_op_equal_test(std::reference_wrapper, std::reference_wrapper); - std::false_type supports_op_equal_test(...); - template () <= std::declval())> - std::true_type supports_op_less_equal_test(std::reference_wrapper, std::reference_wrapper); - std::false_type supports_op_less_equal_test(...); - template () << std::declval())> - std::true_type supports_ostream_op(std::reference_wrapper, std::reference_wrapper); - std::false_type supports_ostream_op(...); - template ()))> - std::true_type supports_adl_to_string(std::reference_wrapper); - std::false_type supports_adl_to_string(...); -#else - template () < std::declval())> - std::true_type supports_op_less_test(const T&, const U&); - std::false_type supports_op_less_test(...); - template () == std::declval())> - std::true_type supports_op_equal_test(const T&, const U&); - std::false_type supports_op_equal_test(...); - template () <= std::declval())> - std::true_type supports_op_less_equal_test(const T&, const U&); - std::false_type supports_op_less_equal_test(...); - template () << std::declval())> - std::true_type supports_ostream_op(const T&, const OS&); - std::false_type supports_ostream_op(...); - template ()))> - std::true_type supports_adl_to_string(const T&); - std::false_type supports_adl_to_string(...); -#endif + template + class supports_op_less_test : public std::false_type {}; + template + class supports_op_less_test() < std::declval())>> : public std::integral_constant, std::variant> && !is_specialization_of_v, std::variant>> {}; + + template + class supports_op_equal_test : public std::false_type {}; + template + class supports_op_equal_test() == std::declval())>> : public std::integral_constant, std::variant> && !is_specialization_of_v, std::variant>> {}; + + template + class supports_op_less_equal_test : public std::false_type {}; + template + class supports_op_less_equal_test() <= std::declval())>> : public std::integral_constant, std::variant> && !is_specialization_of_v, std::variant>> {}; + + template + class supports_op_ostream_test : public std::false_type {}; + template + class supports_op_ostream_test() << std::declval())>> : public std::integral_constant, std::variant> && !is_specialization_of_v, std::variant>> {}; + + template + class supports_adl_to_string_test : public std::false_type {}; + template + class supports_adl_to_string_test()))>> : public std::true_type {}; template struct is_matched_lookup_impl : std::false_type {}; @@ -1877,22 +1871,22 @@ namespace sol { namespace meta { } // namespace meta_detail template - using supports_op_less - = decltype(meta_detail::supports_op_less_test(std::declval&>(), std::declval&>())); + class supports_op_less : public meta_detail::supports_op_less_test {}; + template - using supports_op_equal - = decltype(meta_detail::supports_op_equal_test(std::declval&>(), std::declval&>())); + class supports_op_equal : public meta_detail::supports_op_equal_test {}; + template - using supports_op_less_equal - = decltype(meta_detail::supports_op_less_equal_test(std::declval&>(), std::declval&>())); - template - using supports_ostream_op - = decltype(meta_detail::supports_ostream_op(std::declval&>(), std::declval&>())); - template - using supports_adl_to_string = decltype(meta_detail::supports_adl_to_string(std::declval&>())); + class supports_op_less_equal : public meta_detail::supports_op_less_equal_test {}; + template + class supports_op_ostream : public meta_detail::supports_op_ostream_test {}; + template - using supports_to_string_member = meta::boolean>::value>; + class supports_adl_to_string : public meta_detail::supports_adl_to_string_test {}; + + template + class supports_to_string_member : public meta::boolean>::value> {}; template using is_callable = boolean::value>; @@ -6297,7 +6291,6 @@ namespace sol { namespace detail { #include #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES #ifdef SOL_STD_VARIANT -#include #endif #endif // C++17 #ifdef SOL_USE_BOOST @@ -7163,7 +7156,7 @@ namespace sol { template struct is_to_stringable : meta::any>, meta::supports_adl_to_string>, - meta::supports_ostream_op>> {}; + meta::supports_op_ostream>> {}; namespace detail { template @@ -7561,14 +7554,7 @@ namespace sol { template struct is_automagical - : std::integral_constant, std::variant> && -#endif // std::variant borked in places -#endif // C++17 Features - std::is_array_v< - meta::unqualified_t> || (!std::is_same_v, state> && !std::is_same_v, state_view>)> { + : std::integral_constant> || (!std::is_same_v, state> && !std::is_same_v, state_view>)> { }; template @@ -10814,7 +10800,7 @@ namespace sol { template int default_to_string(lua_State* L) { - return oss_default_to_string(meta::supports_ostream_op(), L); + return oss_default_to_string(meta::supports_op_ostream(), L); } template