move typeinfo_pointer_cast to a cross-platform header

This commit is contained in:
HJfod 2024-08-20 12:50:20 +03:00
parent f061dd4bf2
commit 28cc6fdbd3
2 changed files with 10 additions and 7 deletions

View file

@ -242,3 +242,13 @@ namespace std {
#elif defined(GEODE_IS_ANDROID64) #elif defined(GEODE_IS_ANDROID64)
#define GEODE_PLATFORM_TARGET PlatformID::Android64 #define GEODE_PLATFORM_TARGET PlatformID::Android64
#endif #endif
// this is cross-platform so not duplicating it across the typeinfo_cast definitions
namespace geode::cast {
template<class T, class U>
std::shared_ptr<T> typeinfo_pointer_cast(std::shared_ptr<U> const& r) noexcept {
// https://en.cppreference.com/w/cpp/memory/shared_ptr/pointer_cast
auto p = typeinfo_cast<typename std::shared_ptr<T>::element_type*>(r.get());
return std::shared_ptr<T>(r, p);
}
}

View file

@ -130,11 +130,4 @@ namespace geode::cast {
return nullptr; return nullptr;
} }
template<class T, class U>
std::shared_ptr<T> typeinfo_pointer_cast(std::shared_ptr<U> const& r) noexcept {
// https://en.cppreference.com/w/cpp/memory/shared_ptr/pointer_cast
auto p = typeinfo_cast<typename std::shared_ptr<T>::element_type*>(r.get());
return std::shared_ptr<T>(r, p);
}
} }