Remove const/volatile from Type

This commit is contained in:
ThePhD 2021-02-01 23:32:52 -05:00
parent 27c352149d
commit 22ecd349ab
No known key found for this signature in database
GPG Key ID: 1509DB1C0F702BFA
5 changed files with 56 additions and 38 deletions

View File

@ -51,11 +51,11 @@ namespace sol {
template <typename X> template <typename X>
using rebind_actual_type = std::shared_ptr<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; 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(); return p.get();
} }
}; };
@ -168,41 +168,43 @@ namespace sol {
namespace detail { namespace detail {
template <typename T> template <typename T>
constexpr bool unique_is_null_noexcept() noexcept { constexpr bool unique_is_null_noexcept() noexcept {
if constexpr (meta::meta_detail::unique_usertype_is_null_with_state_v<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<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 { 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> template <typename T>
bool unique_is_null(lua_State* L_, T& value_) noexcept(unique_is_null_noexcept<T>()) { bool unique_is_null(lua_State* L_, T& value_) noexcept(unique_is_null_noexcept<std::remove_cv_t<T>>()) {
if constexpr (meta::meta_detail::unique_usertype_is_null_with_state_v<T>) { using Tu = std::remove_cv_t<T>;
return unique_usertype_traits<T>::is_null(L_, value_); if constexpr (meta::meta_detail::unique_usertype_is_null_with_state_v<Tu>) {
return unique_usertype_traits<Tu>::is_null(L_, value_);
} }
else { else {
return unique_usertype_traits<T>::is_null(value_); return unique_usertype_traits<Tu>::is_null(value_);
} }
} }
template <typename T> template <typename T>
constexpr bool unique_get_noexcept() noexcept { constexpr bool unique_get_noexcept() noexcept {
if constexpr (meta::meta_detail::unique_usertype_get_with_state_v<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<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 { 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> template <typename T>
auto unique_get(lua_State* L_, T& value_) noexcept(unique_get_noexcept<T>()) { auto unique_get(lua_State* L_, T& value_) noexcept(unique_get_noexcept<std::remove_cv_t<T>>()) {
if constexpr (meta::meta_detail::unique_usertype_get_with_state_v<T>) { using Tu = std::remove_cv_t<T>;
return unique_usertype_traits<T>::get(L_, value_); if constexpr (meta::meta_detail::unique_usertype_get_with_state_v<Tu>) {
return unique_usertype_traits<Tu>::get(L_, value_);
} }
else { else {
return unique_usertype_traits<T>::get(value_); return unique_usertype_traits<Tu>::get(value_);
} }
} }
} // namespace detail } // namespace detail

View File

@ -20,8 +20,8 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// This file was generated with a script. // This file was generated with a script.
// Generated 2021-01-25 02:52:07.886776 UTC // Generated 2021-02-02 04:28:44.753067 UTC
// This header was generated with sol v3.2.3 (revision e1950b9a) // This header was generated with sol v3.2.3 (revision 27c35214)
// https://github.com/ThePhD/sol2 // https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_CONFIG_HPP #ifndef SOL_SINGLE_CONFIG_HPP

View File

@ -20,8 +20,8 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// This file was generated with a script. // This file was generated with a script.
// Generated 2021-01-25 02:52:07.863772 UTC // Generated 2021-02-02 04:28:44.742065 UTC
// This header was generated with sol v3.2.3 (revision e1950b9a) // This header was generated with sol v3.2.3 (revision 27c35214)
// https://github.com/ThePhD/sol2 // https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP #ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP

View File

@ -20,8 +20,8 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// This file was generated with a script. // This file was generated with a script.
// Generated 2021-01-25 02:52:07.000664 UTC // Generated 2021-02-02 04:28:44.395065 UTC
// This header was generated with sol v3.2.3 (revision e1950b9a) // This header was generated with sol v3.2.3 (revision 27c35214)
// https://github.com/ThePhD/sol2 // https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_INCLUDE_HPP #ifndef SOL_SINGLE_INCLUDE_HPP
@ -8604,11 +8604,11 @@ namespace sol {
template <typename X> template <typename X>
using rebind_actual_type = std::shared_ptr<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; 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(); return p.get();
} }
}; };
@ -8721,41 +8721,43 @@ namespace sol {
namespace detail { namespace detail {
template <typename T> template <typename T>
constexpr bool unique_is_null_noexcept() noexcept { constexpr bool unique_is_null_noexcept() noexcept {
if constexpr (meta::meta_detail::unique_usertype_is_null_with_state_v<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<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 { 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> template <typename T>
bool unique_is_null(lua_State* L_, T& value_) noexcept(unique_is_null_noexcept<T>()) { bool unique_is_null(lua_State* L_, T& value_) noexcept(unique_is_null_noexcept<std::remove_cv_t<T>>()) {
if constexpr (meta::meta_detail::unique_usertype_is_null_with_state_v<T>) { using Tu = std::remove_cv_t<T>;
return unique_usertype_traits<T>::is_null(L_, value_); if constexpr (meta::meta_detail::unique_usertype_is_null_with_state_v<Tu>) {
return unique_usertype_traits<Tu>::is_null(L_, value_);
} }
else { else {
return unique_usertype_traits<T>::is_null(value_); return unique_usertype_traits<Tu>::is_null(value_);
} }
} }
template <typename T> template <typename T>
constexpr bool unique_get_noexcept() noexcept { constexpr bool unique_get_noexcept() noexcept {
if constexpr (meta::meta_detail::unique_usertype_get_with_state_v<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<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 { 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> template <typename T>
auto unique_get(lua_State* L_, T& value_) noexcept(unique_get_noexcept<T>()) { auto unique_get(lua_State* L_, T& value_) noexcept(unique_get_noexcept<std::remove_cv_t<T>>()) {
if constexpr (meta::meta_detail::unique_usertype_get_with_state_v<T>) { using Tu = std::remove_cv_t<T>;
return unique_usertype_traits<T>::get(L_, value_); if constexpr (meta::meta_detail::unique_usertype_get_with_state_v<Tu>) {
return unique_usertype_traits<Tu>::get(L_, value_);
} }
else { else {
return unique_usertype_traits<T>::get(value_); return unique_usertype_traits<Tu>::get(value_);
} }
} }
} // namespace detail } // namespace detail

View File

@ -111,6 +111,10 @@ inline namespace sol2_test_usertype_unique {
int factory_test::num_saved = 0; int factory_test::num_saved = 0;
int factory_test::num_killed = 0; int factory_test::num_killed = 0;
const int factory_test::true_a = 156; 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 sol2_test_usertype_unique
namespace sol { 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); sol::optional<sol::error> should_error = lua.safe_script("f(c)", sol::script_pass_on_error);
REQUIRE(should_error.has_value()); 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);
}