mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Remove const/volatile from Type
This commit is contained in:
parent
27c352149d
commit
22ecd349ab
|
@ -51,11 +51,11 @@ namespace sol {
|
|||
template <typename X>
|
||||
using rebind_actual_type = std::shared_ptr<X>;
|
||||
|
||||
static bool is_null(const std::shared_ptr<T>& p) noexcept {
|
||||
static bool is_null(lua_State*, const std::shared_ptr<T>& p) noexcept {
|
||||
return p == nullptr;
|
||||
}
|
||||
|
||||
static pointer get(const std::shared_ptr<T>& p) noexcept {
|
||||
static pointer get(lua_State*, const std::shared_ptr<T>& p) noexcept {
|
||||
return p.get();
|
||||
}
|
||||
};
|
||||
|
@ -168,41 +168,43 @@ namespace sol {
|
|||
namespace detail {
|
||||
template <typename T>
|
||||
constexpr bool unique_is_null_noexcept() noexcept {
|
||||
if constexpr (meta::meta_detail::unique_usertype_is_null_with_state_v<T>) {
|
||||
return noexcept(unique_usertype_traits<T>::is_null(static_cast<lua_State*>(nullptr), std::declval<unique_usertype_actual_t<T>>()));
|
||||
if constexpr (meta::meta_detail::unique_usertype_is_null_with_state_v<std::remove_cv_t<T>>) {
|
||||
return noexcept(unique_usertype_traits<T>::is_null(static_cast<lua_State*>(nullptr), std::declval<unique_usertype_actual_t<std::remove_cv_t<T>>>()));
|
||||
}
|
||||
else {
|
||||
return noexcept(unique_usertype_traits<T>::is_null(std::declval<unique_usertype_actual_t<T>>()));
|
||||
return noexcept(unique_usertype_traits<T>::is_null(std::declval<unique_usertype_actual_t<std::remove_cv_t<T>>>()));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool unique_is_null(lua_State* L_, T& value_) noexcept(unique_is_null_noexcept<T>()) {
|
||||
if constexpr (meta::meta_detail::unique_usertype_is_null_with_state_v<T>) {
|
||||
return unique_usertype_traits<T>::is_null(L_, value_);
|
||||
bool unique_is_null(lua_State* L_, T& value_) noexcept(unique_is_null_noexcept<std::remove_cv_t<T>>()) {
|
||||
using Tu = std::remove_cv_t<T>;
|
||||
if constexpr (meta::meta_detail::unique_usertype_is_null_with_state_v<Tu>) {
|
||||
return unique_usertype_traits<Tu>::is_null(L_, value_);
|
||||
}
|
||||
else {
|
||||
return unique_usertype_traits<T>::is_null(value_);
|
||||
return unique_usertype_traits<Tu>::is_null(value_);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
constexpr bool unique_get_noexcept() noexcept {
|
||||
if constexpr (meta::meta_detail::unique_usertype_get_with_state_v<T>) {
|
||||
return noexcept(unique_usertype_traits<T>::get(static_cast<lua_State*>(nullptr), std::declval<unique_usertype_actual_t<T>>()));
|
||||
if constexpr (meta::meta_detail::unique_usertype_get_with_state_v<std::remove_cv_t<T>>) {
|
||||
return noexcept(unique_usertype_traits<T>::get(static_cast<lua_State*>(nullptr), std::declval<unique_usertype_actual_t<std::remove_cv_t<T>>>()));
|
||||
}
|
||||
else {
|
||||
return noexcept(unique_usertype_traits<T>::get(std::declval<unique_usertype_actual_t<T>>()));
|
||||
return noexcept(unique_usertype_traits<T>::get(std::declval<unique_usertype_actual_t<std::remove_cv_t<T>>>()));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
auto unique_get(lua_State* L_, T& value_) noexcept(unique_get_noexcept<T>()) {
|
||||
if constexpr (meta::meta_detail::unique_usertype_get_with_state_v<T>) {
|
||||
return unique_usertype_traits<T>::get(L_, value_);
|
||||
auto unique_get(lua_State* L_, T& value_) noexcept(unique_get_noexcept<std::remove_cv_t<T>>()) {
|
||||
using Tu = std::remove_cv_t<T>;
|
||||
if constexpr (meta::meta_detail::unique_usertype_get_with_state_v<Tu>) {
|
||||
return unique_usertype_traits<Tu>::get(L_, value_);
|
||||
}
|
||||
else {
|
||||
return unique_usertype_traits<T>::get(value_);
|
||||
return unique_usertype_traits<Tu>::get(value_);
|
||||
}
|
||||
}
|
||||
} // namespace detail
|
||||
|
|
|
@ -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 2021-01-25 02:52:07.886776 UTC
|
||||
// This header was generated with sol v3.2.3 (revision e1950b9a)
|
||||
// Generated 2021-02-02 04:28:44.753067 UTC
|
||||
// This header was generated with sol v3.2.3 (revision 27c35214)
|
||||
// https://github.com/ThePhD/sol2
|
||||
|
||||
#ifndef SOL_SINGLE_CONFIG_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 2021-01-25 02:52:07.863772 UTC
|
||||
// This header was generated with sol v3.2.3 (revision e1950b9a)
|
||||
// Generated 2021-02-02 04:28:44.742065 UTC
|
||||
// This header was generated with sol v3.2.3 (revision 27c35214)
|
||||
// https://github.com/ThePhD/sol2
|
||||
|
||||
#ifndef SOL_SINGLE_INCLUDE_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 2021-01-25 02:52:07.000664 UTC
|
||||
// This header was generated with sol v3.2.3 (revision e1950b9a)
|
||||
// Generated 2021-02-02 04:28:44.395065 UTC
|
||||
// This header was generated with sol v3.2.3 (revision 27c35214)
|
||||
// https://github.com/ThePhD/sol2
|
||||
|
||||
#ifndef SOL_SINGLE_INCLUDE_HPP
|
||||
|
@ -8604,11 +8604,11 @@ namespace sol {
|
|||
template <typename X>
|
||||
using rebind_actual_type = std::shared_ptr<X>;
|
||||
|
||||
static bool is_null(const std::shared_ptr<T>& p) noexcept {
|
||||
static bool is_null(lua_State*, const std::shared_ptr<T>& p) noexcept {
|
||||
return p == nullptr;
|
||||
}
|
||||
|
||||
static pointer get(const std::shared_ptr<T>& p) noexcept {
|
||||
static pointer get(lua_State*, const std::shared_ptr<T>& p) noexcept {
|
||||
return p.get();
|
||||
}
|
||||
};
|
||||
|
@ -8721,41 +8721,43 @@ namespace sol {
|
|||
namespace detail {
|
||||
template <typename T>
|
||||
constexpr bool unique_is_null_noexcept() noexcept {
|
||||
if constexpr (meta::meta_detail::unique_usertype_is_null_with_state_v<T>) {
|
||||
return noexcept(unique_usertype_traits<T>::is_null(static_cast<lua_State*>(nullptr), std::declval<unique_usertype_actual_t<T>>()));
|
||||
if constexpr (meta::meta_detail::unique_usertype_is_null_with_state_v<std::remove_cv_t<T>>) {
|
||||
return noexcept(unique_usertype_traits<T>::is_null(static_cast<lua_State*>(nullptr), std::declval<unique_usertype_actual_t<std::remove_cv_t<T>>>()));
|
||||
}
|
||||
else {
|
||||
return noexcept(unique_usertype_traits<T>::is_null(std::declval<unique_usertype_actual_t<T>>()));
|
||||
return noexcept(unique_usertype_traits<T>::is_null(std::declval<unique_usertype_actual_t<std::remove_cv_t<T>>>()));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool unique_is_null(lua_State* L_, T& value_) noexcept(unique_is_null_noexcept<T>()) {
|
||||
if constexpr (meta::meta_detail::unique_usertype_is_null_with_state_v<T>) {
|
||||
return unique_usertype_traits<T>::is_null(L_, value_);
|
||||
bool unique_is_null(lua_State* L_, T& value_) noexcept(unique_is_null_noexcept<std::remove_cv_t<T>>()) {
|
||||
using Tu = std::remove_cv_t<T>;
|
||||
if constexpr (meta::meta_detail::unique_usertype_is_null_with_state_v<Tu>) {
|
||||
return unique_usertype_traits<Tu>::is_null(L_, value_);
|
||||
}
|
||||
else {
|
||||
return unique_usertype_traits<T>::is_null(value_);
|
||||
return unique_usertype_traits<Tu>::is_null(value_);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
constexpr bool unique_get_noexcept() noexcept {
|
||||
if constexpr (meta::meta_detail::unique_usertype_get_with_state_v<T>) {
|
||||
return noexcept(unique_usertype_traits<T>::get(static_cast<lua_State*>(nullptr), std::declval<unique_usertype_actual_t<T>>()));
|
||||
if constexpr (meta::meta_detail::unique_usertype_get_with_state_v<std::remove_cv_t<T>>) {
|
||||
return noexcept(unique_usertype_traits<T>::get(static_cast<lua_State*>(nullptr), std::declval<unique_usertype_actual_t<std::remove_cv_t<T>>>()));
|
||||
}
|
||||
else {
|
||||
return noexcept(unique_usertype_traits<T>::get(std::declval<unique_usertype_actual_t<T>>()));
|
||||
return noexcept(unique_usertype_traits<T>::get(std::declval<unique_usertype_actual_t<std::remove_cv_t<T>>>()));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
auto unique_get(lua_State* L_, T& value_) noexcept(unique_get_noexcept<T>()) {
|
||||
if constexpr (meta::meta_detail::unique_usertype_get_with_state_v<T>) {
|
||||
return unique_usertype_traits<T>::get(L_, value_);
|
||||
auto unique_get(lua_State* L_, T& value_) noexcept(unique_get_noexcept<std::remove_cv_t<T>>()) {
|
||||
using Tu = std::remove_cv_t<T>;
|
||||
if constexpr (meta::meta_detail::unique_usertype_get_with_state_v<Tu>) {
|
||||
return unique_usertype_traits<Tu>::get(L_, value_);
|
||||
}
|
||||
else {
|
||||
return unique_usertype_traits<T>::get(value_);
|
||||
return unique_usertype_traits<Tu>::get(value_);
|
||||
}
|
||||
}
|
||||
} // namespace detail
|
||||
|
|
|
@ -111,6 +111,10 @@ inline namespace sol2_test_usertype_unique {
|
|||
int factory_test::num_saved = 0;
|
||||
int factory_test::num_killed = 0;
|
||||
const int factory_test::true_a = 156;
|
||||
|
||||
void const_ptr_test(const std::shared_ptr<int> ptr) {
|
||||
REQUIRE(*ptr.get() == 1);
|
||||
}
|
||||
} // namespace sol2_test_usertype_unique
|
||||
|
||||
namespace sol {
|
||||
|
@ -269,3 +273,13 @@ TEST_CASE("usertype/unique_usertype checks", "Ensure that access to usertypes ca
|
|||
sol::optional<sol::error> should_error = lua.safe_script("f(c)", sol::script_pass_on_error);
|
||||
REQUIRE(should_error.has_value());
|
||||
}
|
||||
|
||||
TEST_CASE("usertype/unique_usertype const", "make sure const-qualified values don't trip the wrong template specializations") {
|
||||
sol::state lua;
|
||||
|
||||
lua.set_function("f", &const_ptr_test);
|
||||
|
||||
sol::protected_function lua_f = lua["f"];
|
||||
const std::shared_ptr<int> ptr = std::make_shared<int>(1);
|
||||
lua_f(ptr);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user